@@ -65,10 +65,6 @@ let ShldAngl = 180,
6565 ElbwAngl = 90 ,
6666 WrstAngl = 90 ;
6767
68- let trans_matrix = new THREE . Matrix4 ( ) ;
69- trans_matrix . set ( 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ) ;
70-
71- let spanEditModal = document . getElementsByClassName ( "close" ) [ 0 ] ;
7268let scene ,
7369 PI = 3.141592653589793 ,
7470 camera ,
@@ -441,7 +437,6 @@ let prev_y = 0;
441437let prev_z = 0 ;
442438
443439function movePoint ( e ) {
444- // alert("hello");
445440 var target = e . target || e . srcElement ;
446441
447442 // Get target values directly from input
@@ -455,46 +450,13 @@ function movePoint(e) {
455450 let curr_y = ty * translationScale - prev_y ;
456451 let curr_z = tz * translationScale - prev_z ;
457452
458- // Create translation matrix
453+ // Update previous values
459454 prev_x += curr_x ;
460455 prev_y += curr_y ;
461456 prev_z += curr_z ;
462- let translate_M = new THREE . Matrix4 ( ) . makeTranslation ( curr_x , curr_y , curr_z ) ;
463-
464- // Update dot
465- // dotList[0].geometry.applyMatrix4(translate_M);
466- // if (dotList[0].geometry.isBufferGeometry) {
467- // dotList[0].geometry.attributes.position.needsUpdate = true;
468- // }
469-
470- trans_matrix . multiply ( translate_M ) ;
471-
472- // Reset transformation matrix if needed
473- if ( target . value <= 0 ) {
474- trans_matrix . set ( 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ) ;
475- }
476457
458+ // Move the arm
477459 moveArm ( hand_comp , new THREE . Vector3 ( curr_x , curr_y , curr_z ) ) ;
478-
479- document . getElementById ( "matrix-00" ) . value = trans_matrix . elements [ 0 ] ;
480- document . getElementById ( "matrix-01" ) . value = trans_matrix . elements [ 1 ] ;
481- document . getElementById ( "matrix-02" ) . value = trans_matrix . elements [ 2 ] ;
482- document . getElementById ( "matrix-03" ) . value = trans_matrix . elements [ 12 ] ;
483-
484- document . getElementById ( "matrix-10" ) . value = trans_matrix . elements [ 4 ] ;
485- document . getElementById ( "matrix-11" ) . value = trans_matrix . elements [ 5 ] ;
486- document . getElementById ( "matrix-12" ) . value = trans_matrix . elements [ 6 ] ;
487- document . getElementById ( "matrix-13" ) . value = trans_matrix . elements [ 13 ] ;
488-
489- document . getElementById ( "matrix-20" ) . value = trans_matrix . elements [ 8 ] ;
490- document . getElementById ( "matrix-21" ) . value = trans_matrix . elements [ 9 ] ;
491- document . getElementById ( "matrix-22" ) . value = trans_matrix . elements [ 10 ] ;
492- document . getElementById ( "matrix-23" ) . value = trans_matrix . elements [ 14 ] ;
493-
494- document . getElementById ( "matrix-30" ) . value = trans_matrix . elements [ 3 ] ;
495- document . getElementById ( "matrix-31" ) . value = trans_matrix . elements [ 7 ] ;
496- document . getElementById ( "matrix-32" ) . value = trans_matrix . elements [ 11 ] ;
497- document . getElementById ( "matrix-33" ) . value = trans_matrix . elements [ 15 ] ;
498460}
499461
500462function createLabel ( text , direction , length ) {
@@ -589,7 +551,6 @@ camera.updateProjectionMatrix();
589551let init = function ( ) {
590552 camera . position . set ( 5 , 17 , 20 ) ; // Set camera position behind and above the origin
591553
592- // camera.lookAt(20, 10, 5);
593554 const light = new THREE . DirectionalLight ( 0xffffff , 3 ) ;
594555 light . position . set ( 1 , 1 , 1 ) . normalize ( ) ;
595556 scene . add ( light ) ;
@@ -624,12 +585,24 @@ let init = function () {
624585
625586 // Create the arrow helper for the current direction and color
626587 arrowHelper [ i ] = new THREE . ArrowHelper ( dir [ i ] , origin , length , color ) ;
588+ // Add polygon offset to prevent z-fighting
589+ if ( arrowHelper [ i ] . material ) {
590+ arrowHelper [ i ] . material . polygonOffset = true ;
591+ arrowHelper [ i ] . material . polygonOffsetFactor = 1 ;
592+ arrowHelper [ i ] . material . polygonOffsetUnits = 1 ;
593+ }
627594 scene . add ( arrowHelper [ i ] ) ;
628595
629596 // Create label for each axis and position it at the tip of the arrow
630597 const label = createLabel ( labels [ i ] , dir [ i ] , length ) ;
631- scene . add ( label ) ;
598+ if ( label && label . material ) {
599+ label . material . polygonOffset = true ;
600+ label . material . polygonOffsetFactor = 1 ;
601+ label . material . polygonOffsetUnits = 1 ;
602+ scene . add ( label ) ;
603+ }
632604 }
605+
633606 let PointGeometry = createArm (
634607 scene ,
635608 hand_comp ,
@@ -640,10 +613,31 @@ let init = function () {
640613 palm_dim ,
641614 palm_pos
642615 ) ;
643- renderer = new THREE . WebGLRenderer ( ) ;
616+
617+ // Add polygon offset to all arm components
618+ hand_comp . forEach ( component => {
619+ if ( component && component . material ) {
620+ component . material . polygonOffset = true ;
621+ component . material . polygonOffsetFactor = 1 ;
622+ component . material . polygonOffsetUnits = 1 ;
623+ }
624+ // Also check children for materials
625+ if ( component && component . children ) {
626+ component . children . forEach ( child => {
627+ if ( child && child . material ) {
628+ child . material . polygonOffset = true ;
629+ child . material . polygonOffsetFactor = 1 ;
630+ child . material . polygonOffsetUnits = 1 ;
631+ }
632+ } ) ;
633+ }
634+ } ) ;
635+
636+ renderer = new THREE . WebGLRenderer ( { antialias : true } ) ;
644637 let w = container . offsetWidth ;
645638 let h = container . offsetHeight ;
646639 renderer . setSize ( w , 0.83 * h ) ;
640+ renderer . setPixelRatio ( window . devicePixelRatio ) ;
647641 container . appendChild ( renderer . domElement ) ;
648642 orbit = new OrbitControls ( camera , renderer . domElement ) ;
649643 orbit . mouseButtons = {
0 commit comments