fix up code model connection a little

This commit is contained in:
Kurt Hutten IrevDev
2022-11-29 19:03:50 +11:00
parent 95f9c4c2b4
commit faf37d1b03
2 changed files with 37 additions and 34 deletions

View File

@ -104,7 +104,7 @@ function App() {
const geos: ViewerArtifact[] = const geos: ViewerArtifact[] =
programMemory?.return?.flatMap( programMemory?.return?.flatMap(
({ name }: { name: string }) => ({ name }: { name: string }) =>
processShownObjects(programMemory)(programMemory?.root?.[name]) || processShownObjects(programMemory, programMemory?.root?.[name]) ||
[] []
) || [] ) || []
setGeoArray(geos) setGeoArray(geos)
@ -263,7 +263,7 @@ function RenderViewerArtifacts({
<Line <Line
geo={geo} geo={geo}
sourceRange={sourceRange} sourceRange={sourceRange}
forceHighlight={forceHighlight} forceHighlight={forceHighlight || editorCursor}
/> />
) )
} }
@ -273,7 +273,7 @@ function RenderViewerArtifacts({
<RenderViewerArtifacts <RenderViewerArtifacts
artifact={artifact} artifact={artifact}
key={index} key={index}
forceHighlight={editorCursor} forceHighlight={forceHighlight || editorCursor}
/> />
))} ))}
</> </>

View File

@ -198,45 +198,48 @@ export type ViewerArtifact =
children: ViewerArtifact[] children: ViewerArtifact[]
} }
type PreviousTransforms = {
rotation: [number, number, number]
transform: [number, number, number]
}[]
export const processShownObjects = export const processShownObjects =
(programMemory: ProgramMemory) => (
(geoMeta: Path[] | Transform): ViewerArtifact[] => { programMemory: ProgramMemory,
geoMeta: Path[] | Transform,
previousTransforms: PreviousTransforms = []
): ViewerArtifact[] => {
if (Array.isArray(geoMeta)) { if (Array.isArray(geoMeta)) {
return geoMeta.map(({ geo, sourceRange }) => ({ return geoMeta.map(({ geo, sourceRange }) => {
type: 'geo',
geo,
sourceRange,
}))
} else if (geoMeta.type === 'transform') {
console.log('transform', geoMeta, programMemory)
const geos = processShownObjects(programMemory)(
programMemory.root[geoMeta.id]
).map((arg): ViewerArtifact => {
if (arg.type !== 'geo')
throw new Error('transform must be applied to geo')
const { geo, sourceRange } = arg
const newGeo = geo.clone() const newGeo = geo.clone()
newGeo.rotateX(geoMeta.rotation[0]) previousTransforms.forEach(({ rotation, transform }) => {
newGeo.rotateY(geoMeta.rotation[1]) newGeo.rotateX(rotation[0])
newGeo.rotateZ(geoMeta.rotation[2]) newGeo.rotateY(rotation[1])
newGeo.translate( newGeo.rotateZ(rotation[2])
geoMeta.transform[0], newGeo.translate(transform[0], transform[1], transform[2])
geoMeta.transform[1], })
geoMeta.transform[2]
)
return { return {
type: 'geo', type: 'geo',
sourceRange,
geo: newGeo, geo: newGeo,
sourceRange,
} }
}) })
return [ } else if (geoMeta.type === 'transform') {
{ const referencedVar = programMemory.root[geoMeta.id]
type: 'parent', const parentArtifact: ViewerArtifact = {
sourceRange: geoMeta.sourceRange, type: 'parent',
children: geos, sourceRange: geoMeta.sourceRange,
}, children: processShownObjects(programMemory, referencedVar, [
] ...previousTransforms,
{
rotation: geoMeta.rotation,
transform: geoMeta.transform,
},
]),
}
return [parentArtifact]
} }
throw new Error('Unknown geoMeta type') throw new Error('Unknown geoMeta type')
} }