@@ -10,6 +10,7 @@ const project = useProjectStore()
1010const props = defineProps <{
1111 ModeData: viz .ModeData
1212 showNodePaths: boolean
13+ showNodeOrientation: boolean
1314}>()
1415
1516watch (
@@ -19,13 +20,16 @@ watch(
1920)
2021
2122watch (() => props .showNodePaths , (snp ) => (nodePaths .visible = snp ))
23+ watch (() => props .showNodeOrientation , (sno ) => {
24+ for (const ofr of orientationFrames ) {
25+ ofr .visible = sno && lineFrames .indexOf (ofr ) === frameNum
26+ }
27+ })
2228
23- const showNodePaths = ref (true )
24-
25- let frames = new Array < THREE .Group > ;
29+ let lineFrames = new Array < THREE .Group > ;
30+ let orientationFrames = new Array < THREE .Group > ;
2631let nodePaths = new THREE .Group ;
2732let frameNum = 0 ;
28- let capturing = false ;
2933let frameCenter = new THREE .Vector3 ;
3034let frameSize = new THREE .Vector3 ;
3135let clock = new THREE .Clock ();
@@ -35,30 +39,75 @@ const FOV = 10
3539function createFrames(modeData : viz .ModeData ) {
3640 if (modeData .Frames == null ) return
3741 scene .clear ()
38- frames = [] as THREE . Group [];
42+
3943 const geometry = new THREE .BufferGeometry ();
4044 geometry .setAttribute (' position' , new THREE .Float32BufferAttribute ([0 , 0 , 0 ], 3 ));
4145 const material = new THREE .PointsMaterial ({ color: 0x888888 });
4246 const origin = new THREE .Points (geometry , material );
4347 origin .visible = false
48+
49+ // Clear existing frames
50+ lineFrames = [] as THREE .Group [];
51+ orientationFrames = [] as THREE .Group [];
52+
4453 const allFramesGroup = new THREE .Group ()
4554 allFramesGroup .add (origin )
55+
56+ const xMaterial = new THREE .LineBasicMaterial ({ color: 0xff0000 , linewidth: 2 });
57+ const yMaterial = new THREE .LineBasicMaterial ({ color: 0x00ff00 , linewidth: 2 });
58+ const zMaterial = new THREE .LineBasicMaterial ({ color: 0x0000ff , linewidth: 2 });
59+
60+ // Loop through frames
4661 for (const f of modeData .Frames ) {
47- const frameGroup = new THREE .Group ()
62+
63+ // Lines
64+ const lineFrameGroup = new THREE .Group ()
4865 for (const c of Object .values (f .Components )) {
4966 const curve = new THREE .CatmullRomCurve3 (
5067 c .Line .map ((p ) => new THREE .Vector3 (p .XYZ [0 ], p .XYZ [1 ], p .XYZ [2 ])))
5168 const points = curve .getPoints (50 );
5269 const geometry = new THREE .BufferGeometry ().setFromPoints (points );
5370 const material = new THREE .LineBasicMaterial ({ color: 0xffffff , linewidth: 1 });
5471 const curveObject = new THREE .Line (geometry , material );
55- frameGroup .add (curveObject )
72+ lineFrameGroup .add (curveObject )
5673 allFramesGroup .add (curveObject .clone ()) // Add clone of object to be used for view sizing
5774 }
58- frameGroup .visible = false // Initialize each group to not visible for animation
59- frames .push (frameGroup )
60- scene .add (frameGroup )
75+ lineFrameGroup .visible = false // Initialize each group to not visible for animation
76+ lineFrames .push (lineFrameGroup )
77+
78+ // Orientations
79+ const orientationFrameGroup = new THREE .Group ()
80+ for (const c of Object .values (f .Components )) {
81+ const indices = new Uint16Array (c .Line .map ((_ , i ) => i * 2 ).flatMap (i => [i , i + 1 ]));
82+
83+ const pointsX = new Float32Array (c .Line .flatMap (p => [p .XYZ [0 ], p .XYZ [1 ], p .XYZ [2 ], p .XYZ [0 ] + p .OrientationX [0 ] * 4 , p .XYZ [1 ] + p .OrientationX [1 ] * 4 , p .XYZ [2 ] + p .OrientationX [2 ] * 4 ]));
84+ const geometryX = new THREE .BufferGeometry ();
85+ geometryX .setAttribute (' position' , new THREE .BufferAttribute (pointsX , 3 ));
86+ geometryX .setIndex (new THREE .BufferAttribute (indices , 1 ));
87+ const lineX = new THREE .LineSegments (geometryX , xMaterial );
88+ orientationFrameGroup .add (lineX );
89+
90+ const pointsY = new Float32Array (c .Line .flatMap (p => [p .XYZ [0 ], p .XYZ [1 ], p .XYZ [2 ], p .XYZ [0 ] + p .OrientationY [0 ] * 4 , p .XYZ [1 ] + p .OrientationY [1 ] * 4 , p .XYZ [2 ] + p .OrientationY [2 ] * 4 ]));
91+ const geometryY = new THREE .BufferGeometry ();
92+ geometryY .setAttribute (' position' , new THREE .BufferAttribute (pointsY , 3 ));
93+ geometryY .setIndex (new THREE .BufferAttribute (indices , 1 ));
94+ const lineY = new THREE .LineSegments (geometryY , yMaterial );
95+ orientationFrameGroup .add (lineY );
96+
97+ // const pointsZ = new Float32Array(c.Line.flatMap(p => [p.XYZ[0], p.XYZ[1], p.XYZ[2], p.XYZ[0] + p.OrientationZ[0] * 4, p.XYZ[1] + p.OrientationZ[1] * 4, p.XYZ[2] + p.OrientationZ[2] * 4]));
98+ // const geometryZ = new THREE.BufferGeometry();
99+ // geometryZ.setAttribute('position', new THREE.BufferAttribute(pointsZ, 3));
100+ // geometryZ.setIndex(new THREE.BufferAttribute(indices, 1));
101+ // const lineZ = new THREE.LineSegments(geometryZ, zMaterial);
102+ // orientationFrameGroup.add(lineZ);
103+ }
104+ orientationFrameGroup .visible = false // Initialize each group to not visible for animation
105+ orientationFrames .push (orientationFrameGroup )
106+
107+ scene .add (lineFrameGroup )
108+ scene .add (orientationFrameGroup )
61109 }
110+
62111 // Node paths
63112 const componentNames = Object .keys (modeData .Frames [0 ].Components )
64113 const curves = new Array < THREE .CatmullRomCurve3 >
@@ -172,12 +221,23 @@ const views = [
172221function animate() {
173222 requestAnimationFrame (animate );
174223 delta += clock .getDelta ()
175- if (delta > 1.5 / frames .length ) {
224+ if (delta > 1.5 / lineFrames .length ) {
176225 delta = 0
177- frames [frameNum ].visible = false ;
226+
227+ // Hide current frame
228+ lineFrames [frameNum ].visible = false ;
229+ orientationFrames [frameNum ].visible = false ;
230+
231+ // Increment frame number
178232 frameNum ++
179- if (frameNum >= frames .length ) frameNum = 0
180- frames [frameNum ].visible = true ;
233+ if (frameNum >= lineFrames .length ) frameNum = 0
234+
235+ // Show next frame
236+ lineFrames [frameNum ].visible = true ;
237+ if (props .showNodeOrientation ) {
238+ orientationFrames [frameNum ].visible = true ;
239+ }
240+
181241 render ();
182242 }
183243}
0 commit comments