@@ -732,6 +732,165 @@ export default QUnit.module( 'Core', () => {
732732
733733 } ) ;
734734
735+ QUnit . test ( "updateWorldMatrix" , ( assert ) => {
736+
737+ const object = new Object3D ( ) ;
738+ const parent = new Object3D ( ) ;
739+ const child = new Object3D ( ) ;
740+
741+ const m = new Matrix4 ( ) ;
742+ const v = new Vector3 ( ) ;
743+
744+ parent . add ( object ) ;
745+ object . add ( child ) ;
746+
747+ parent . position . set ( 1 , 2 , 3 ) ;
748+ object . position . set ( 4 , 5 , 6 ) ;
749+ child . position . set ( 7 , 8 , 9 ) ;
750+
751+ // Update the world matrix of an object
752+
753+ object . updateWorldMatrix ( ) ;
754+
755+ assert . deepEqual ( parent . matrix . elements ,
756+ m . elements ,
757+ "No effect to parents' local matrices" ) ;
758+
759+ assert . deepEqual ( parent . matrixWorld . elements ,
760+ m . elements ,
761+ "No effect to parents' world matrices" ) ;
762+
763+ assert . deepEqual ( object . matrix . elements ,
764+ m . setPosition ( object . position ) . elements ,
765+ "Object's local matrix is updated" ) ;
766+
767+ assert . deepEqual ( object . matrixWorld . elements ,
768+ m . setPosition ( object . position ) . elements ,
769+ "Object's world matrix is updated" ) ;
770+
771+ assert . deepEqual ( child . matrix . elements ,
772+ m . identity ( ) . elements ,
773+ "No effect to children's local matrices" ) ;
774+
775+ assert . deepEqual ( child . matrixWorld . elements ,
776+ m . elements ,
777+ "No effect to children's world matrices" ) ;
778+
779+ // Update the world matrices of an object and its parents
780+
781+ object . matrix . identity ( ) ;
782+ object . matrixWorld . identity ( ) ;
783+
784+ object . updateWorldMatrix ( true , false ) ;
785+
786+ assert . deepEqual ( parent . matrix . elements ,
787+ m . setPosition ( parent . position ) . elements ,
788+ "Parents' local matrices are updated" ) ;
789+
790+ assert . deepEqual ( parent . matrixWorld . elements ,
791+ m . setPosition ( parent . position ) . elements ,
792+ "Parents' world matrices are updated" ) ;
793+
794+ assert . deepEqual ( object . matrix . elements ,
795+ m . setPosition ( object . position ) . elements ,
796+ "Object's local matrix is updated" ) ;
797+
798+ assert . deepEqual ( object . matrixWorld . elements ,
799+ m . setPosition ( v . copy ( parent . position ) . add ( object . position ) ) . elements ,
800+ "Object's world matrix is updated" ) ;
801+
802+ assert . deepEqual ( child . matrix . elements ,
803+ m . identity ( ) . elements ,
804+ "No effect to children's local matrices" ) ;
805+
806+ assert . deepEqual ( child . matrixWorld . elements ,
807+ m . identity ( ) . elements ,
808+ "No effect to children's world matrices" ) ;
809+
810+ // Update the world matrices of an object and its children
811+
812+ parent . matrix . identity ( ) ;
813+ parent . matrixWorld . identity ( ) ;
814+ object . matrix . identity ( ) ;
815+ object . matrixWorld . identity ( ) ;
816+
817+ object . updateWorldMatrix ( false , true ) ;
818+
819+ assert . deepEqual ( parent . matrix . elements ,
820+ m . elements ,
821+ "No effect to parents' local matrices" ) ;
822+
823+ assert . deepEqual ( parent . matrixWorld . elements ,
824+ m . elements ,
825+ "No effect to parents' world matrices" ) ;
826+
827+ assert . deepEqual ( object . matrix . elements ,
828+ m . setPosition ( object . position ) . elements ,
829+ "Object's local matrix is updated" ) ;
830+
831+ assert . deepEqual ( object . matrixWorld . elements ,
832+ m . setPosition ( object . position ) . elements ,
833+ "Object's world matrix is updated" ) ;
834+
835+ assert . deepEqual ( child . matrix . elements ,
836+ m . setPosition ( child . position ) . elements ,
837+ "Children's local matrices are updated" ) ;
838+
839+ assert . deepEqual ( child . matrixWorld . elements ,
840+ m . setPosition ( v . copy ( object . position ) . add ( child . position ) ) . elements ,
841+ "Children's world matrices are updated" ) ;
842+
843+ // Update the world matrices of an object and its parents and children
844+
845+ object . matrix . identity ( ) ;
846+ object . matrixWorld . identity ( ) ;
847+ child . matrix . identity ( ) ;
848+ child . matrixWorld . identity ( ) ;
849+
850+ object . updateWorldMatrix ( true , true ) ;
851+
852+ assert . deepEqual ( parent . matrix . elements ,
853+ m . setPosition ( parent . position ) . elements ,
854+ "Parents' local matrices are updated" ) ;
855+
856+ assert . deepEqual ( parent . matrixWorld . elements ,
857+ m . setPosition ( parent . position ) . elements ,
858+ "Parents' world matrices are updated" ) ;
859+
860+ assert . deepEqual ( object . matrix . elements ,
861+ m . setPosition ( object . position ) . elements ,
862+ "Object's local matrix is updated" ) ;
863+
864+ assert . deepEqual ( object . matrixWorld . elements ,
865+ m . setPosition ( v . copy ( parent . position ) . add ( object . position ) ) . elements ,
866+ "Object's world matrix is updated" ) ;
867+
868+ assert . deepEqual ( child . matrix . elements ,
869+ m . setPosition ( child . position ) . elements ,
870+ "Children's local matrices are updated" ) ;
871+
872+ assert . deepEqual ( child . matrixWorld . elements ,
873+ m . setPosition ( v . copy ( parent . position ) . add ( object . position ) . add ( child . position ) ) . elements ,
874+ "Children's world matrices are updated" ) ;
875+
876+ // object.matrixAutoUpdate = false test
877+
878+ object . matrix . identity ( ) ;
879+ object . matrixWorld . identity ( ) ;
880+
881+ object . matrixAutoUpdate = false ;
882+ object . updateWorldMatrix ( true , false ) ;
883+
884+ assert . deepEqual ( object . matrix . elements ,
885+ m . identity ( ) . elements ,
886+ "No effect to object's local matrix if matrixAutoUpdate is false" ) ;
887+
888+ assert . deepEqual ( object . matrixWorld . elements ,
889+ m . setPosition ( parent . position ) . elements ,
890+ "object's world matrix is updated even if matrixAutoUpdate is false" ) ;
891+
892+ } ) ;
893+
735894 QUnit . test ( "toJSON" , ( assert ) => {
736895
737896 var a = new Object3D ( ) ;
0 commit comments