コード例 #1
0
        protected override void DoUpdate()
        {
            VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.triggerButton,
                                () =>
            {
                group = new CommandGroup("Gun");
            },
                                () =>
            {
                group.Submit();
                group = null;
            }
                                );

            bool triggered = VRInput.GetValue(VRInput.primaryController, CommonUsages.triggerButton);

            if (triggered && prefabs.Count > 0)
            {
                if (Time.time - prevTime > 1f / fireRate)
                {
                    int           prefabIndex = UnityEngine.Random.Range(0, prefabs.Count);
                    GameObject    spawned     = Instantiate(prefabs[prefabIndex]);
                    ThrowedObject throwed     = spawned.AddComponent <ThrowedObject>();
                    throwed.AddForce(transform.forward * power);
                    throwed.SetScale(objectScale);
                    new CommandAddGameObject(spawned).Submit();
                    Matrix4x4 matrix = SceneManager.RightHanded.worldToLocalMatrix * mouthpiece.localToWorldMatrix;
                    Maths.DecomposeMatrix(matrix, out Vector3 t, out _, out _);
                    Vector3 scale = Vector3.one;
                    SceneManager.SetObjectMatrix(spawned, Matrix4x4.TRS(t, Quaternion.identity, scale));
                    prevTime = Time.time;
                }
            }
        }
コード例 #2
0
        public void SetDestination(Transform mouthpiece)
        {
            Matrix4x4 transformation = mouthpiece.localToWorldMatrix * initialMouthMatrix;

            if (poseMode == AnimationTool.PoseEditMode.AC)
            {
                float currentAngle = Vector3.SignedAngle(initForward, mouthpiece.position - oTransform.position, acAxis);

                float angleOffset = Mathf.DeltaAngle(previousAngle, currentAngle);
                oTransform.Rotate(acAxis, angleOffset, Space.World);
                endRotations[0] = oTransform.localRotation;
                previousAngle   = currentAngle;
                return;
            }
            if (poseMode == AnimationTool.PoseEditMode.FK || fullHierarchy.Count == 1)
            {
                Matrix4x4 transformed = InitialParentMatrixWorldToLocal *
                                        transformation * InitialParentMatrix *
                                        InitialTRS;
                Maths.DecomposeMatrix(transformed, out Vector3 position, out Quaternion rotation, out Vector3 scale);
                targetPosition = position;
                targetRotation = rotation;
            }
            else
            {
                Matrix4x4 target = transformation * initialTransformMatrix;
                Maths.DecomposeMatrix(target, out Vector3 position, out Quaternion rotation, out Vector3 scale);
                targetPosition = position;
                targetRotation = rotation * Quaternion.Euler(-180, 0, 0);
            }
        }
コード例 #3
0
        private void AddObject(GameObject gobject)
        {
            if (!items.TryGetValue(selectedItem, out AssetBankItem item))
            {
                Debug.LogWarning($"Item {gobject.name} not found in Asset Bank (id: {selectedItem})");
                return;
            }

            // Get the position of the mouthpiece into matrix
            Matrix4x4 matrix = SceneManager.RightHanded.worldToLocalMatrix * mouthpiece.localToWorldMatrix;

            Maths.DecomposeMatrix(matrix, out Vector3 t, out _, out _);
            Vector3 scale = Vector3.one;

            CommandGroup group = new CommandGroup("Instantiate Bank Object");

            try
            {
                // Add the object to scene
                ClearSelection();
                CommandAddGameObject command = new CommandAddGameObject(gobject);
                command.Submit();
                GameObject newObject = command.newObject;
                if (item.imported)
                {
                    ParametersController controller = newObject.GetComponent <ParametersController>();
                    if (null == controller)
                    {
                        controller            = newObject.AddComponent <ParametersController>();
                        controller.isImported = true;
                        controller.importPath = item.assetName;
                    }
                }

                // Set the object size to 20cm in the user space
                Bounds bounds = new Bounds();
                foreach (var subMeshFilter in newObject.GetComponentsInChildren <MeshFilter>())
                {
                    if (!useDefaultInstantiationScale)
                    {
                        bounds.Encapsulate(subMeshFilter.mesh.bounds);
                    }
                }
                if (bounds.size.magnitude > 0)
                {
                    scale *= (0.2f / bounds.size.magnitude) / GlobalState.WorldScale;  // 0.2: 20cm
                }
                AddToSelection(newObject);
                SceneManager.SetObjectMatrix(newObject, Matrix4x4.TRS(t, Quaternion.identity, scale));
                Selection.HoveredObject = newObject;
            }
            finally
            {
                group.Submit();
            }
        }
コード例 #4
0
        public void Import(string filename)
        {
            Scene scene = Scene.Open(filename);

            CommandGroup group = new CommandGroup();

            var cameras = scene.ReadAll <CameraControllerSample>();

            foreach (var camera in cameras)
            {
                CameraControllerSample sample = camera.sample;

                GameObject cameraPrefab = ResourceManager.GetPrefab(PrefabID.Camera);
                GameObject instance     = SceneManager.InstantiateUnityPrefab(cameraPrefab);
                GameObject newObject    = SceneManager.AddObject(instance);

                newObject.name = camera.path.GetName();
                sample.CopyToCamera(newObject.GetComponent <CameraController>());
                Maths.DecomposeMatrix(sample.transform, out Vector3 position, out Quaternion rotation, out Vector3 scale);
                newObject.transform.localPosition = position;
                newObject.transform.localRotation = rotation;
                newObject.transform.localScale    = scale;
            }

            foreach (var m in scene.ReadAll <MeshSample>())
            {
                MeshSample sample = m.sample;

                GameObject gobject = new GameObject();
                gobject.name = m.path.GetName();
                Maths.DecomposeMatrix(sample.transform, out Vector3 position, out Quaternion rotation, out Vector3 scale);
                gobject.transform.localPosition = position;
                gobject.transform.localRotation = rotation;
                gobject.transform.localScale    = scale;

                Mesh mesh = new Mesh();
                mesh.SetVertices(sample.points);
                mesh.SetNormals(sample.normals);
                mesh.SetUVs(0, sample.st as Vector2[]);
                mesh.SetTriangles(sample.faceVertexIndices, 0);

                MeshFilter meshFilter = gobject.AddComponent <MeshFilter>();
                meshFilter.sharedMesh = mesh;
                MeshRenderer mr = gobject.AddComponent <MeshRenderer>();
                mr.sharedMaterial = ResourceManager.GetMaterial(MaterialID.ObjectOpaque);
                gobject.AddComponent <MeshCollider>();

                SceneManager.AddObject(gobject);
            }

            group.Submit();

            scene.Close();
        }
コード例 #5
0
        private State GetCurrentState(int currentFrame)
        {
            Matrix4x4 currentMatrix = FrameMatrix(currentFrame, animationList);

            Maths.DecomposeMatrix(currentMatrix, out Vector3 pos, out Quaternion rot, out Vector3 scale);
            return(new State()
            {
                position = pos,
                rotation = rot,
                time = currentFrame
            });
        }
コード例 #6
0
ファイル: GoalGizmo.cs プロジェクト: AnthonyMir/vrtist
        public void ResetPosition(GameObject gObject)
        {
            if (Controller == null)
            {
                return;
            }
            Matrix4x4 targetMatrix = Controller.transform.localToWorldMatrix;

            Maths.DecomposeMatrix(targetMatrix, out Vector3 pos, out Quaternion rot, out Vector3 scale);
            transform.position   = pos;
            transform.rotation   = rot;
            transform.localScale = scale;
        }
コード例 #7
0
        public void DragObject(Transform mouthpiece)
        {
            Matrix4x4 transformation = mouthpiece.localToWorldMatrix * initMouthPieceWorldToLocal;

            movedObjects.ForEach(x =>
            {
                Matrix4x4 transformed = initialParentMatrixWtL[x] * transformation * initialParentMatrixLtW[x] * Matrix4x4.TRS(initialPositions[x], initialRotation[x], initialScale[x]);
                Maths.DecomposeMatrix(transformed, out Vector3 pos, out Quaternion rot, out Vector3 scale);
                x.transform.localPosition = pos;
                x.transform.localRotation = rot;
                x.transform.localScale    = scale;
            });
        }
コード例 #8
0
        private void CreateSolver(Matrix4x4 transformation)
        {
            Matrix4x4 target = transformation * humanData.InitFrameMatrix;

            target = humanData.Controller.RootController.transform.worldToLocalMatrix * target;
            Maths.DecomposeMatrix(target, out Vector3 targetPos, out Quaternion targetRot, out Vector3 targetScale);

            TangentRigSolver solver = new TangentRigSolver(targetPos, targetRot, humanData.Controller.Animation, humanData.Controller.AnimToRoot, Frame, startFrame, endFrame, continuity);

            humanData.Solver = solver;

            solver.NextStep();
            GlobalState.Animation.onChangeCurve.Invoke(humanData.Controller.RootController.gameObject, AnimatableProperty.PositionX);
        }
コード例 #9
0
ファイル: AssimpIO.cs プロジェクト: ubisoft/vrtist
        private IEnumerator ImportHierarchy(Assimp.Node node, Transform parent, GameObject go)
        {
            if (parent != null && parent != go.transform)
            {
                go.transform.parent = parent;
            }

            // Do not use Assimp Decompose function, it does not work properly
            // use unity decomposition instead
            Matrix4x4 mat = new Matrix4x4(
                new Vector4(node.Transform.A1, node.Transform.B1, node.Transform.C1, node.Transform.D1),
                new Vector4(node.Transform.A2, node.Transform.B2, node.Transform.C2, node.Transform.D2),
                new Vector4(node.Transform.A3, node.Transform.B3, node.Transform.C3, node.Transform.D3),
                new Vector4(node.Transform.A4, node.Transform.B4, node.Transform.C4, node.Transform.D4)
                );

            Vector3    position, scale;
            Quaternion rotation;

            Maths.DecomposeMatrix(mat, out position, out rotation, out scale);

            AssignMeshes(node, go);

            if (node.Parent != null)
            {
                go.transform.localPosition = position;
                go.transform.localRotation = rotation;
                go.transform.localScale    = scale;
                go.name = Utils.CreateUniqueName(node.Name);
            }

            foreach (Assimp.Node assimpChild in node.Children)
            {
                GameObject child = new GameObject();
                child.tag = "PhysicObject";
                if (blocking)
                {
                    ImportHierarchy(assimpChild, go.transform, child).MoveNext();
                }
                else
                {
                    yield return(StartCoroutine(ImportHierarchy(assimpChild, go.transform, child)));
                }
            }
        }
コード例 #10
0
ファイル: GoalGizmo.cs プロジェクト: AnthonyMir/vrtist
        public void Init(RigGoalController controller)
        {
            Controller = controller;

            Matrix4x4 targetMatrix = controller.transform.localToWorldMatrix;

            Maths.DecomposeMatrix(targetMatrix, out Vector3 pos, out Quaternion rot, out Vector3 scale);
            transform.position   = pos;
            transform.rotation   = rot;
            transform.localScale = scale;

            if (!isListening)
            {
                GlobalState.ObjectMovingEvent.AddListener(ResetPosition);
                GlobalState.Animation.onFrameEvent.AddListener(ResetPosition);
                isListening = true;
            }
        }
コード例 #11
0
        private void DragObject(Matrix4x4 transformation, float scaleIndice)
        {
            Matrix4x4 transformed = objectData.InitialParentMatrixWorldToLocal *
                                    transformation * objectData.InitialParentMatrix *
                                    objectData.InitialTRS;

            Maths.DecomposeMatrix(transformed, out objectData.lastPosition, out objectData.lastQRotation, out objectData.lastScale);
            objectData.lastRotation = objectData.lastQRotation.eulerAngles;
            objectData.lastScale   *= scaleIndice;

            Interpolation interpolation = GlobalState.Settings.interpolation;
            AnimationKey  posX          = new AnimationKey(Frame, objectData.lastPosition.x, interpolation);
            AnimationKey  posY          = new AnimationKey(Frame, objectData.lastPosition.y, interpolation);
            AnimationKey  posZ          = new AnimationKey(Frame, objectData.lastPosition.z, interpolation);
            AnimationKey  rotX          = new AnimationKey(Frame, objectData.lastRotation.x, interpolation);
            AnimationKey  rotY          = new AnimationKey(Frame, objectData.lastRotation.y, interpolation);
            AnimationKey  rotZ          = new AnimationKey(Frame, objectData.lastRotation.z, interpolation);
            AnimationKey  scalex        = new AnimationKey(Frame, objectData.lastScale.z, interpolation);
            AnimationKey  scaley        = new AnimationKey(Frame, objectData.lastScale.z, interpolation);
            AnimationKey  scalez        = new AnimationKey(Frame, objectData.lastScale.z, interpolation);

            switch (manipulationMode)
            {
            case AnimationTool.CurveEditMode.AddKeyframe:
                AddFilteredKeyframe(Target, posX, posY, posZ, rotX, rotY, rotZ, scalex, scaley, scalez);
                break;

            case AnimationTool.CurveEditMode.Zone:
                AddFilteredKeyframeZone(Target, posX, posY, posZ, rotX, rotY, rotZ, scalex, scaley, scalez);
                break;

            case AnimationTool.CurveEditMode.Segment:
                objectData.Solver = new TangentSimpleSolver(objectData.lastPosition, objectData.lastQRotation, GlobalState.Animation.GetObjectAnimation(Target), Frame, startFrame, endFrame, continuity);
                objectData.Solver.TrySolver();
                GlobalState.Animation.onChangeCurve.Invoke(Target, AnimatableProperty.PositionX);
                break;

            case AnimationTool.CurveEditMode.Tangents:
                objectData.Solver = new TangentSimpleSolver(objectData.lastPosition, objectData.lastQRotation, GlobalState.Animation.GetObjectAnimation(Target), Frame, startFrame, endFrame, continuity);
                objectData.Solver.TrySolver();
                GlobalState.Animation.onChangeCurve.Invoke(Target, AnimatableProperty.PositionX);
                break;
            }
        }
コード例 #12
0
            public Node(GameObject targetObject, int frame, Transform parentNode, Matrix4x4 parentMatrix, float scale = 1f)
            {
                Target          = targetObject;
                Frame           = frame;
                ObjectAnimation = GlobalState.Animation.GetObjectAnimation(Target);
                Childrens       = new List <Node>();
                if (null == ObjectAnimation)
                {
                    return;
                }
                Matrix4x4 objectMatrix = parentMatrix * ObjectAnimation.GetTRSMatrix(frame);

                Maths.DecomposeMatrix(objectMatrix, out worldPosition, out Quaternion objectRotation, out Vector3 objectScale);

                if (Target.TryGetComponent <RigGoalController>(out RigGoalController controller) && controller.IsGoal)
                {
                    Sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    controller.CheckAnimations();
                }
コード例 #13
0
        public Vector3 FramePosition(int frame)
        {
            if (null == Animation)
            {
                Animation = GlobalState.Animation.GetObjectAnimation(this.gameObject);
            }
            if (null == Animation)
            {
                return(Vector3.zero);
            }

            AnimationSet rootAnimation = GlobalState.Animation.GetObjectAnimation(RootController.gameObject);
            Matrix4x4    trsMatrix     = RootController.transform.parent.localToWorldMatrix;

            if (null != rootAnimation)
            {
                trsMatrix = trsMatrix * rootAnimation.GetTRSMatrix(frame);
            }
            else
            {
                trsMatrix = trsMatrix * Matrix4x4.TRS(RootController.transform.localPosition, RootController.transform.localRotation, RootController.transform.localScale);
            }

            if (PathToRoot.Count > 1)
            {
                for (int i = 0; i < PathToRoot.Count; i++)
                {
                    if (null != AnimToRoot[i])
                    {
                        trsMatrix = trsMatrix * AnimToRoot[i].GetTRSMatrix(frame);
                    }
                }
            }
            trsMatrix = trsMatrix * Animation.GetTRSMatrix(frame);

            Maths.DecomposeMatrix(trsMatrix, out Vector3 parentPosition, out Quaternion quaternion, out Vector3 scale);
            return(parentPosition);
        }
コード例 #14
0
        private IEnumerator ImportHierarchy(Assimp.Node node, Transform parent, GameObject go, Matrix4x4 cumulMatrix, Quaternion preRotation)
        {
            if (parent != null && parent != go.transform)
            {
                go.transform.parent = parent;
            }

            GlobalState.Instance.messageBox.ShowMessage("Importing Hierarchy : " + importCount);
            // Do not use Assimp Decompose function, it does not work properly
            // use unity decomposition instead
            Matrix4x4 nodeMatrix = new Matrix4x4(
                new Vector4(node.Transform.A1, node.Transform.B1, node.Transform.C1, node.Transform.D1),
                new Vector4(node.Transform.A2, node.Transform.B2, node.Transform.C2, node.Transform.D2),
                new Vector4(node.Transform.A3, node.Transform.B3, node.Transform.C3, node.Transform.D3),
                new Vector4(node.Transform.A4, node.Transform.B4, node.Transform.C4, node.Transform.D4)
                );

            Maths.DecomposeMatrix(nodeMatrix, out Vector3 nodePosition, out Quaternion nodeRotation, out Vector3 nodeScale);
            Maths.DecomposeMatrix(cumulMatrix, out Vector3 cumulPosition, out Quaternion cumulRotation, out Vector3 cumulScale);

            if (node.Name.Contains("$AssimpFbx$") && node.HasChildren)
            {
                if (node.Name.Contains("Translation"))
                {
                    nodePosition = cumulRotation * nodePosition;
                }
                else
                {
                    nodePosition += cumulPosition;
                }
                if (node.Name.Contains("PreRotation"))
                {
                    preRotation  = nodeRotation;
                    nodeRotation = cumulRotation * nodeRotation;
                }
                else
                {
                    nodeRotation = cumulRotation;
                }
                cumulMatrix = Matrix4x4.TRS(nodePosition, nodeRotation, nodeScale);
                if (blocking)
                {
                    ImportHierarchy(node.Children[0], parent, go, cumulMatrix, preRotation).MoveNext();
                }
                else
                {
                    yield return(StartCoroutine(ImportHierarchy(node.Children[0], parent, go, cumulMatrix, preRotation)));
                }
            }
            else
            {
                nodePosition = (cumulRotation * nodePosition) + cumulPosition;
                node.Transform.Decompose(out Assimp.Vector3D scale1, out Assimp.Quaternion rot, out Assimp.Vector3D trans);
                AssignMeshes(node, go);

                if (node.Parent != null)
                {
                    go.transform.localPosition = nodePosition;
                    go.transform.localRotation = nodeRotation;
                    go.transform.localScale    = nodeScale;
                    go.name = isHuman ? node.Name : Utils.CreateUniqueName(node.Name);
                    if (isHuman)
                    {
                        if (bones.ContainsKey(node.Name))
                        {
                            bones[node.Name] = go.transform;
                        }
                        if (node.Name.Contains("Hips"))
                        {
                            rootBone = go.transform;
                        }
                    }
                }


                if (scene.HasAnimations)
                {
                    ImportAnimation(node, go, cumulRotation);
                }

                nodeMatrix = Matrix4x4.TRS(Vector3.zero, cumulRotation * nodeRotation, nodeScale);
                importCount++;
                foreach (Assimp.Node assimpChild in node.Children)
                {
                    GameObject child = new GameObject();
                    if (blocking)
                    {
                        ImportHierarchy(assimpChild, go.transform, child, nodeMatrix, Quaternion.identity).MoveNext();
                    }
                    else
                    {
                        yield return(StartCoroutine(ImportHierarchy(assimpChild, go.transform, child, nodeMatrix, Quaternion.identity)));
                    }
                }
            }
        }
コード例 #15
0
        public void Execute(int index)
        {
            int objectIndex    = index / 24;
            int executionIndex = index % 24;


            Matrix4x4 prevMatrix = GetFrameMatrix();

            Maths.DecomposeMatrix(prevMatrix, out Vector3 currentPosition, out Quaternion currentRotation, out Vector3 prevScale);
            KeyFrame prevFrame = prevFrames[0];
            KeyFrame nextFrame = postFrames[0];

            if (objectIndex < prevFrames.Length)
            {
                prevFrame = prevFrames[objectIndex];
                nextFrame = postFrames[objectIndex];
                switch (executionIndex)
                {
                case 0: prevFrame.rotX.inTanX += dtheta; break;

                case 1: prevFrame.rotX.inTanY += dtheta; break;

                case 2: prevFrame.rotX.outTanX += dtheta; break;

                case 3: prevFrame.rotX.outTanY += dtheta; break;

                case 4: nextFrame.rotX.inTanX += dtheta; break;

                case 5: nextFrame.rotX.inTanY += dtheta; break;

                case 6: nextFrame.rotX.outTanX += dtheta; break;

                case 7: nextFrame.rotX.outTanY += dtheta; break;

                case 8: prevFrame.rotY.inTanX += dtheta; break;

                case 9: prevFrame.rotY.inTanY += dtheta; break;

                case 10: prevFrame.rotY.outTanX += dtheta; break;

                case 11: prevFrame.rotY.outTanY += dtheta; break;

                case 12: nextFrame.rotY.inTanX += dtheta; break;

                case 13: nextFrame.rotY.inTanY += dtheta; break;

                case 14: nextFrame.rotY.outTanX += dtheta; break;

                case 15: nextFrame.rotY.outTanY += dtheta; break;

                case 16: prevFrame.rotZ.inTanX += dtheta; break;

                case 17: prevFrame.rotZ.inTanY += dtheta; break;

                case 18: prevFrame.rotZ.outTanX += dtheta; break;

                case 19: prevFrame.rotZ.outTanY += dtheta; break;

                case 20: nextFrame.rotZ.inTanX += dtheta; break;

                case 21: nextFrame.rotZ.inTanY += dtheta; break;

                case 22: nextFrame.rotZ.outTanX += dtheta; break;

                case 23: nextFrame.rotZ.outTanY += dtheta; break;
                }
            }
            else
            {
                switch (executionIndex)
                {
                case 0: prevFrame.posX.inTanX += dtheta; break;

                case 1: prevFrame.posX.inTanY += dtheta; break;

                case 2: prevFrame.posX.outTanX += dtheta; break;

                case 3: prevFrame.posX.outTanY += dtheta; break;

                case 4: nextFrame.posX.inTanX += dtheta; break;

                case 5: nextFrame.posX.inTanY += dtheta; break;

                case 6: nextFrame.posX.outTanX += dtheta; break;

                case 7: nextFrame.posX.outTanY += dtheta; break;

                case 8: prevFrame.posY.inTanX += dtheta; break;

                case 9: prevFrame.posY.inTanY += dtheta; break;

                case 10: prevFrame.posY.outTanX += dtheta; break;

                case 11: prevFrame.posY.outTanY += dtheta; break;

                case 12: nextFrame.posY.inTanX += dtheta; break;

                case 13: nextFrame.posY.inTanY += dtheta; break;

                case 14: nextFrame.posY.outTanX += dtheta; break;

                case 15: nextFrame.posY.outTanY += dtheta; break;

                case 16: prevFrame.posZ.inTanX += dtheta; break;

                case 17: prevFrame.posZ.inTanY += dtheta; break;

                case 18: prevFrame.posZ.outTanX += dtheta; break;

                case 19: prevFrame.posZ.outTanY += dtheta; break;

                case 20: nextFrame.posZ.inTanX += dtheta; break;

                case 21: nextFrame.posZ.inTanY += dtheta; break;

                case 22: nextFrame.posZ.outTanX += dtheta; break;

                case 23: nextFrame.posZ.outTanY += dtheta; break;
                }
            }

            Matrix4x4 matrix = GetFrameMatrix(objectIndex, prevFrame, nextFrame);

            Maths.DecomposeMatrix(matrix, out Vector3 plusPosition, out Quaternion plusRotation, out Vector3 plusScale);
            Js0[index] = (double)(plusPosition.x - currentPosition.x) * dtheta;
            Js1[index] = (double)(plusPosition.y - currentPosition.y) * dtheta;
            Js2[index] = (double)(plusPosition.z - currentPosition.z) * dtheta;
            Js3[index] = (double)(plusRotation.x - currentRotation.x) * dtheta;
            Js4[index] = (double)(plusRotation.y - currentRotation.y) * dtheta;
            Js5[index] = (double)(plusRotation.z - currentRotation.z) * dtheta;
            Js6[index] = (double)(plusRotation.w - currentRotation.w) * dtheta;
        }
コード例 #16
0
        private IEnumerator ImportHierarchy(Assimp.Node node, Transform parent, GameObject go)
        {
            if (parent != null && parent != go.transform)
            {
                go.transform.parent = parent;
            }

            GlobalState.Instance.messageBox.ShowMessage("Importing Hierarchy : " + importCount);
            // Do not use Assimp Decompose function, it does not work properly
            // use unity decomposition instead
            Matrix4x4 mat = new Matrix4x4(
                new Vector4(node.Transform.A1, node.Transform.B1, node.Transform.C1, node.Transform.D1),
                new Vector4(node.Transform.A2, node.Transform.B2, node.Transform.C2, node.Transform.D2),
                new Vector4(node.Transform.A3, node.Transform.B3, node.Transform.C3, node.Transform.D3),
                new Vector4(node.Transform.A4, node.Transform.B4, node.Transform.C4, node.Transform.D4)
                );
            Vector3    position, scale;
            Quaternion rotation;

            Maths.DecomposeMatrix(mat, out position, out rotation, out scale);

            node.Transform.Decompose(out Assimp.Vector3D scale1, out Assimp.Quaternion rot, out Assimp.Vector3D trans);

            AssignMeshes(node, go);

            if (node.Parent != null)
            {
                go.transform.localPosition = position;
                go.transform.localRotation = rotation;
                go.transform.localScale    = scale;
                go.name = isHuman ? node.Name : Utils.CreateUniqueName(node.Name);
                if (isHuman)
                {
                    if (bones.ContainsKey(node.Name))
                    {
                        bones[node.Name] = go.transform;
                    }
                    if (node.Name.Contains("Hips"))
                    {
                        rootBone = go.transform;
                    }
                }
            }


            if (scene.HasAnimations)
            {
                ImportAnimation(node, go, Quaternion.identity);
            }

            importCount++;
            foreach (Assimp.Node assimpChild in node.Children)
            {
                GameObject child = new GameObject();
                if (blocking)
                {
                    ImportHierarchy(assimpChild, go.transform, child).MoveNext();
                }
                else
                {
                    yield return(StartCoroutine(ImportHierarchy(assimpChild, go.transform, child)));
                }
            }
        }
コード例 #17
0
 public void SetObjectMatrix(GameObject gobject, Matrix4x4 matrix)
 {
     Maths.DecomposeMatrix(matrix, out Vector3 position, out Quaternion rotation, out Vector3 scale);
     SetObjectTransform(gobject, position, rotation, scale);
 }