Beispiel #1
0
            private void ConvertFrames(Transform trans, ImportedFrame parent)
            {
                ImportedFrame frame = new ImportedFrame();

                frame.Name = trans.m_GameObject.instance.m_Name;
                frame.InitChildren(trans.Count);
                Vector3 euler = FbxUtility.QuaternionToEuler(trans.m_LocalRotation);

                euler.Y *= -1;
                euler.Z *= -1;
                Quaternion mirroredRotation = FbxUtility.EulerToQuaternion(euler);

                frame.Matrix = Matrix.Scaling(trans.m_LocalScale) * Matrix.RotationQuaternion(mirroredRotation) * Matrix.Translation(-trans.m_LocalPosition.X, trans.m_LocalPosition.Y, trans.m_LocalPosition.Z);
                if (parent == null)
                {
                    FrameList = new List <ImportedFrame>();
                    FrameList.Add(frame);
                }
                else
                {
                    parent.AddChild(frame);
                }

                foreach (Transform child in trans)
                {
                    ConvertFrames(child, frame);
                }
            }
Beispiel #2
0
            private ImportedFrame ConvertFrames(remBone frame)
            {
                ImportedFrame iFrame = new ImportedFrame();

                iFrame.InitChildren(frame.Count);
                iFrame.Name   = frame.name;
                iFrame.Matrix = frame.matrix;

                FrameList.Add(iFrame);

                foreach (remBone child in frame)
                {
                    ImportedFrame iChild = ConvertFrames(child);
                    iFrame.AddChild(iChild);
                }

                return(iFrame);
            }
Beispiel #3
0
            private ImportedFrame ImportFrame(Section section)
            {
                ImportedFrame frame = new ImportedFrame();
                frame.InitChildren(0);

                if (section.name == null)
                {
                    frame.Name = "no_name" + noNameCount;
                    noNameCount++;
                }
                else
                {
                    frame.Name = section.name;
                }

                List<bool> hasBonesList = new List<bool>();
                SortedDictionary<string, byte> boneDic = new SortedDictionary<string, byte>();
                ImportedMesh meshList = new ImportedMesh();
                meshList.Name = frame.Name;
                meshList.BoneList = new List<ImportedBone>();
                meshList.SubmeshList = new List<ImportedSubmesh>();

                Matrix matrix = new Matrix();
                foreach (Section child in section.children)
                {
                    if (child.type == "FrameTransformMatrix")
                    {
                        LinkedListNode<object> node = child.data.First;
                        for (int i = 0; i < 4; i++)
                        {
                            for (int j = 0; j < 4; j++)
                            {
                                matrix[i, j] = ConvertFloat(node.Value);
                                node = node.Next;
                            }
                        }
                        frame.Matrix = RHToLHMatrix(matrix);
                    }
                    else if (child.type == "Mesh")
                    {
                        ImportMesh(child, meshList, boneDic, hasBonesList);
                    }
                    else if (child.type == "Frame")
                    {
                        ImportedFrame childFrame = ImportFrame(child);
                        if (childFrame != null)
                        {
                            frame.AddChild(childFrame);
                        }
                    }
                    else
                    {
                        Report.ReportLog("Warning: unexpected section " + child.type);
                    }
                }
                SetBones(meshList, hasBonesList);
                if (meshList.SubmeshList.Count > 0)
                {
                    MeshList.Add(meshList);
                }

                if (matrix == null)
                {
                    frame.Matrix = Matrix.Identity;
                }
                return frame;
            }
Beispiel #4
0
            private ImportedFrame ImportNode(Document.Node node)
            {
                ImportedFrame frame = new ImportedFrame();
                try
                {
                    frame.Name = DecodeName(node.id);
                    frame.Matrix = ProcessNodeMatrix(node);

                    ImportedMesh meshList = new ImportedMesh();
                    meshList.Name = frame.Name;
                    meshList.SubmeshList = new List<ImportedSubmesh>();

                    List<string> boneNames = new List<string>(255);
                    List<Matrix> boneMatrices = new List<Matrix>(255);
                    List<Document.InstanceGeometry> geometries = new List<Document.InstanceGeometry>();
                    List<Document.InstanceController> controllers = new List<Document.InstanceController>();
                    List<Document.InstanceNode> instanceNodes;
                    ProcessNodeInstances(node, geometries, controllers, out instanceNodes);

                    for (int i = 0; i < instanceNodes.Count; i++)
                    {
                        List<Document.InstanceNode> dummy;
                        Document.Node instanceNode = (Document.Node)colladaDoc.dic[instanceNodes[i].url.Fragment];
                        if (ProcessNodeInstances(instanceNode, geometries, controllers, out dummy))
                        {
                            ImportedFrame child = ImportNode(instanceNode);
                            if (child != null)
                            {
                                frame.AddChild(child);
                            }
                        }
                        for (int j = 0; j < dummy.Count; j++)
                        {
                            Report.ReportLog("Warning: instance node " + dummy[j].name + " wasn't processed");
                        }
                    }

                    if (node.children != null)
                    {
                        for (int i = 0; i < node.children.Count; i++)
                        {
                            List<Document.InstanceNode> dummy;
                            if (ProcessNodeInstances(node.children[i], geometries, controllers, out dummy))
                            {
                                ImportedFrame child = ImportNode(node.children[i]);
                                if (child != null)
                                {
                                    frame.AddChild(child);
                                }
                            }
                            for (int j = 0; j < dummy.Count; j++)
                            {
                                Report.ReportLog("Warning: instance node " + dummy[j].name + " wasn't processed");
                            }
                        }
                    }

                    int vertInfoIdx = 0;
                    for (int i = 0; i < controllers.Count; i++)
                    {
                        ImportedSubmesh submesh = ImportController((Document.Controller)colladaDoc.dic[controllers[i].url.Fragment], boneNames, boneMatrices, ref vertInfoIdx);
                        if (submesh != null)
                        {
                            SetMaterial(controllers[i], submesh);
                            submesh.Index = meshList.SubmeshList.Count;
                            meshList.SubmeshList.Add(submesh);
                        }
                    }
                    for (int i = 0; i < geometries.Count; i++)
                    {
                        ImportedSubmesh submesh = ImportGeometry((Document.Geometry)colladaDoc.dic[geometries[i].url.Fragment], ref vertInfoIdx);
                        if (submesh != null)
                        {
                            SetMaterial(geometries[i], submesh);
                            submesh.Index = meshList.SubmeshList.Count;
                            meshList.SubmeshList.Add(submesh);

                            foreach (ImportedVertex vert in submesh.VertexList)
                            {
                                if (boneNames.Count > 0)
                                {
                                    vert.BoneIndices = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF };
                                    vert.Weights = new float[] { 1, 0, 0, 0 };
                                }
                                else
                                {
                                    vert.BoneIndices = new byte[4];
                                    vert.Weights = new float[4];
                                }
                            }
                        }
                    }

                    if (meshList.SubmeshList.Count > 0)
                    {
                        meshList.BoneList = new List<ImportedBone>(boneNames.Count);
                        for (int i = 0; i < boneNames.Count; i++)
                        {
                            string name = boneNames[i];
                            ImportedBone bone = new ImportedBone();
                            bone.Name = DecodeName(name);
                            bone.Matrix = boneMatrices[i];
                            meshList.BoneList.Add(bone);
                        }
                        MeshList.Add(meshList);
                    }
                }
                catch (Exception e)
                {
                    Report.ReportLog("Error importing node " + node.id + ": " + e.Message);
                    frame = null;
                }
                return frame;
            }
Beispiel #5
0
            private ImportedFrame ConvertFrames(odfFrame frame)
            {
                ImportedFrame iFrame = new ImportedFrame();
                iFrame.InitChildren(frame.Count);
                iFrame.Name = frame.Name;
                iFrame.Matrix = frame.Matrix;

                FrameList.Add(iFrame);

                foreach (odfFrame child in frame)
                {
                    ImportedFrame iChild = ConvertFrames(child);
                    iFrame.AddChild(iChild);
                }

                return iFrame;
            }
Beispiel #6
0
            private void ConvertFrames(Transform trans, ImportedFrame parent)
            {
                ImportedFrame frame = new ImportedFrame();
                frame.Name = trans.m_GameObject.instance.m_Name;
                frame.InitChildren(trans.Count);
                Vector3 euler = FbxUtility.QuaternionToEuler(trans.m_LocalRotation);
                euler.Y *= -1;
                euler.Z *= -1;
                Quaternion mirroredRotation = FbxUtility.EulerToQuaternion(euler);
                frame.Matrix = Matrix.Scaling(trans.m_LocalScale) * Matrix.RotationQuaternion(mirroredRotation) * Matrix.Translation(-trans.m_LocalPosition.X, trans.m_LocalPosition.Y, trans.m_LocalPosition.Z);
                if (parent == null)
                {
                    FrameList = new List<ImportedFrame>();
                    FrameList.Add(frame);
                }
                else
                {
                    parent.AddChild(frame);
                }

                foreach (Transform child in trans)
                {
                    ConvertFrames(child, frame);
                }
            }