예제 #1
0
        SkeletonBone AddNodeToSkeletonRecursive(
            FbxNode node,
            SkeletonBone parentBone,
            Dictionary <ulong, bool> skeletonNodeTree,
            FbxSkin[] skins)
        {
            if (BoneIndexDictionary.ContainsKey(node.GetUniqueID()))
            {
                return(null);
            }

            SkeletonBone pBone = new SkeletonBone(node, parentBone, skins, Scene);

            //pBone.CalculateAnimations(animationTracks);
            BoneIndexDictionary[node.GetUniqueID()] = Bones.Count;
            Bones.Add(pBone);

            for (int i = 0; i < node.GetChildCount(); i++)
            {
                FbxNode pChild = node.GetChild(i);
                if (skeletonNodeTree[pChild.GetUniqueID()])
                {
                    var childBone = AddNodeToSkeletonRecursive(pChild, pBone, skeletonNodeTree, skins);
                    if (childBone != null)
                    {
                        pBone.Children.Add(childBone);
                    }
                }
            }
            return(pBone);
        }
예제 #2
0
        void ReadMeshGeometriesRecursive(FbxManager manager, FbxNode node, ImportOptions options, Matrix4 additionalTransform /*nodeTransform*/)
        {
            FbxExtensions.GetNodeMesh(node, out FbxMesh fbxMesh);
            if (fbxMesh != null)
            {
                var res = ProcessMesh.ProcMesh(manager, node, fbxMesh, options, additionalTransform);
                if (res != null)
                {
                    foreach (var geom in res)
                    {
                        geom.Name = ImportGeneral.GetFixedName(geom.Node.GetName());
                        if (Skeleton != null)
                        {
                            FillBoneAssignments(geom, Skeleton);
                        }
                        Geometries.Add(geom);
                    }
                }
            }

            for (int i = 0; i < node.GetChildCount(); i++)
            {
                var childNode = node.GetChild(i);
                ReadMeshGeometriesRecursive(manager, childNode, options, additionalTransform);
            }
        }
예제 #3
0
        protected void CheckSkeleton(FbxNode origRootNode, FbxNode importRootNode)
        {
            FbxNode origLimb1Node   = origRootNode.GetChild(0);
            FbxNode importLimb1Node = importRootNode.GetChild(0);

            FbxNode origLimb2Node   = origLimb1Node.GetChild(0);
            FbxNode importLimb2Node = importLimb1Node.GetChild(0);

            foreach (var skelNodePair in new SkelNodePair[] { new SkelNodePair(origRootNode, importRootNode, true),
                                                              new SkelNodePair(origLimb1Node, importLimb1Node), new SkelNodePair(origLimb2Node, importLimb2Node) })
            {
                FbxSkeleton origSkel   = skelNodePair.origNode.GetSkeleton();
                FbxSkeleton importSkel = skelNodePair.importNode.GetSkeleton();

                Assert.IsNotNull(origSkel);
                Assert.IsNotNull(importSkel);

                Assert.AreEqual(origSkel.GetName(), importSkel.GetName());
                Assert.AreEqual(origSkel.GetSkeletonType(), importSkel.GetSkeletonType());
                Assert.AreEqual(skelNodePair.origNode.LclTranslation.Get(), skelNodePair.importNode.LclTranslation.Get());

                if (!skelNodePair.isRoot)
                {
                    Assert.AreEqual(origSkel.Size.Get(), importSkel.Size.Get());
                }
            }
        }
예제 #4
0
        protected override FbxScene CreateScene(FbxManager manager)
        {
            FbxScene scene = base.CreateScene(manager);

            // mesh shared by all instances
            FbxMesh            sharedMesh     = FbxMesh.Create(scene, m_meshName);
            FbxSurfaceMaterial sharedMaterial = FbxSurfacePhong.Create(scene, m_materialName);

            // add mesh to all nodes
            Queue <FbxNode> nodes = new Queue <FbxNode>();

            for (int i = 0; i < scene.GetRootNode().GetChildCount(); i++)
            {
                nodes.Enqueue(scene.GetRootNode().GetChild(i));
            }

            while (nodes.Count > 0)
            {
                FbxNode node = nodes.Dequeue();
                node.SetNodeAttribute(sharedMesh);
                node.AddMaterial(sharedMaterial);
                for (int i = 0; i < node.GetChildCount(); i++)
                {
                    nodes.Enqueue(node.GetChild(i));
                }
            }

            return(scene);
        }
        // Test for bug where exporting FbxShapes with empty names would fail to import all
        // blendshapes except the first in Maya (fixed by UT-3216)
        private void TestFbxShapeNamesNotEmpty(FbxNode node)
        {
            var mesh = node.GetMesh();

            if (mesh != null)
            {
                for (int i = 0; i < mesh.GetDeformerCount(); i++)
                {
                    var blendshape = mesh.GetBlendShapeDeformer(i);
                    if (blendshape == null)
                    {
                        continue;
                    }

                    for (int j = 0; j < blendshape.GetBlendShapeChannelCount(); j++)
                    {
                        var blendShapeChannel = blendshape.GetBlendShapeChannel(j);
                        for (int k = 0; k < blendShapeChannel.GetTargetShapeCount(); k++)
                        {
                            var shape = blendShapeChannel.GetTargetShape(k);
                            Assert.That(string.IsNullOrEmpty(shape.GetName()), Is.False, string.Format("FbxShape missing name on blendshape {0}", blendshape.GetName()));
                        }
                    }
                }
            }

            for (int i = 0; i < node.GetChildCount(); i++)
            {
                TestFbxShapeNamesNotEmpty(node.GetChild(i));
            }
        }
예제 #6
0
        protected void LinkMeshToSkeleton(FbxScene scene, FbxNode meshNode, FbxNode skelRootNode)
        {
            FbxNode limb1 = skelRootNode.GetChild(0);
            FbxNode limb2 = limb1.GetChild(0);

            FbxCluster rootCluster = FbxCluster.Create(scene, "RootCluster");

            rootCluster.SetLink(skelRootNode);
            rootCluster.SetLinkMode(FbxCluster.ELinkMode.eTotalOne);
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    rootCluster.AddControlPointIndex(4 * i + j, 1.0 - 0.25 * i);
                }
            }

            FbxCluster limb1Cluster = FbxCluster.Create(scene, "Limb1Cluster");

            limb1Cluster.SetLink(limb1);
            limb1Cluster.SetLinkMode(FbxCluster.ELinkMode.eTotalOne);
            for (int i = 1; i < 6; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    limb1Cluster.AddControlPointIndex(4 * i + j, (i == 1 || i == 5 ? 0.25 : 0.5));
                }
            }

            FbxCluster limb2Cluster = FbxCluster.Create(scene, "Limb2Cluster");

            limb2Cluster.SetLink(limb2);
            limb2Cluster.SetLinkMode(FbxCluster.ELinkMode.eTotalOne);
            for (int i = 3; i < 7; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    limb2Cluster.AddControlPointIndex(4 * i + j, 0.25 * (i - 2));
                }
            }

            FbxAMatrix globalTransform = meshNode.EvaluateGlobalTransform();

            rootCluster.SetTransformMatrix(globalTransform);
            limb1Cluster.SetTransformMatrix(globalTransform);
            limb2Cluster.SetTransformMatrix(globalTransform);

            rootCluster.SetTransformLinkMatrix(skelRootNode.EvaluateGlobalTransform());
            limb1Cluster.SetTransformLinkMatrix(limb1.EvaluateGlobalTransform());
            limb2Cluster.SetTransformLinkMatrix(limb2.EvaluateGlobalTransform());

            FbxSkin skin = FbxSkin.Create(scene, "Skin");

            skin.AddCluster(rootCluster);
            skin.AddCluster(limb1Cluster);
            skin.AddCluster(limb2Cluster);
            meshNode.GetMesh().AddDeformer(skin);
        }
예제 #7
0
        static void PrintFbxNode(FbxNode node, string prefix = "")
        {
            Console.WriteLine(prefix + node.GetName());

            for (int childIndex = 0; childIndex < node.GetChildCount(); ++childIndex)
            {
                PrintFbxNode(node.GetChild(childIndex), prefix + "--");
            }
        }
예제 #8
0
 void CreateChildren(Transform unityParent, FbxNode fbxParent, Dictionary <GameObject, FbxNode> nodes)
 {
     for (int i = 0, n = fbxParent.GetChildCount(); i < n; ++i)
     {
         var fbxChild   = fbxParent.GetChild(i);
         var unityChild = CreateNode(unityParent, fbxChild);
         nodes[unityChild.gameObject] = fbxChild;
         CreateChildren(unityChild, fbxChild, nodes);
     }
 }
예제 #9
0
    public FbxObjectTexture(FbxDocument fbxDocument, FbxNode node)
    {
        FbxDocument = fbxDocument;
        Id          = new FbxObjectId {
            Id = (long)node.Properties[0]
        };
        Name             = (string)node.Properties[1];
        RelativeFilename = (string)node.GetChild("RelativeFilename").Properties[0];

        FbxDocument.ObjectCache.Add(this, Id);
    }
예제 #10
0
            /// <summary>
            /// Convert scene's system units but leave scaling unchanged
            /// </summary>
            public void ConvertScene(FbxScene fbxScene, FbxSystemUnit toUnits)
            {
                // Get scale factor.
                float scaleFactor = 1.0f;

                scaleFactor = (float)fbxScene.GetGlobalSettings().GetSystemUnit().GetConversionFactorTo(toUnits);

                if (scaleFactor.Equals(1.0f))
                {
                    return;
                }

                // Get root node.
                FbxNode fbxRootNode = fbxScene.GetRootNode();

                // For all the nodes to convert the translations
                Queue <FbxNode> fbxNodes = new Queue <FbxNode> ();

                fbxNodes.Enqueue(fbxRootNode);

                while (fbxNodes.Count > 0)
                {
                    FbxNode fbxNode = fbxNodes.Dequeue();

                    // Convert node's translation.
                    FbxDouble3 lclTrs = fbxNode.LclTranslation.Get();

#if UNI_18844
                    lclTrs *= scaleFactor;
                    lclTrs *= scaleFactor;
                    lclTrs *= scaleFactor;
#endif
                    fbxNode.LclTranslation.Set(lclTrs);

                    FbxMesh fbxMesh = fbxNode.GetMesh();

                    if (fbxMesh != null)
                    {
                        for (int i = 0; i < fbxMesh.GetControlPointsCount(); ++i)
                        {
                            FbxVector4 fbxVector4 = fbxMesh.GetControlPointAt(i);
#if UNI_18844
                            fbxVector4 *= scaleFactor;
#endif
                            fbxMesh.SetControlPointAt(fbxVector4, i);
                        }
                    }

                    for (int i = 0; i < fbxNode.GetChildCount(); ++i)
                    {
                        fbxNodes.Enqueue(fbxNode.GetChild(i));
                    }
                }
            }
예제 #11
0
    MappingInformationType GetMappingInfomationType(FbxNode node)
    {
        var typeStr = node.GetChild("MappingInformationType").GetProperty <string>(0);

        switch (typeStr)
        {
        case "ByPolygonVertex":
            return(MappingInformationType.ByPolygonVertex);

        case "ByPolygon":
            return(MappingInformationType.ByPolygon);

        default:
            throw new Exception();
        }
    }
예제 #12
0
    ReferenceInformationType GetReferenceInformationType(FbxNode node)
    {
        var typeStr = node.GetChild("ReferenceInformationType").GetProperty <string>(0);

        switch (typeStr)
        {
        case "Direct":
            return(ReferenceInformationType.Direct);

        case "IndexToDirect":
            return(ReferenceInformationType.IndexToDirect);

        default:
            throw new Exception();
        }
    }
        private void AddCustomProperties(FbxNode fbxNode, string propName, int propValue)
        {
            var fbxProperty = FbxProperty.Create(fbxNode, Globals.FbxIntDT, propName);

            Assert.IsTrue(fbxProperty.IsValid());
            fbxProperty.Set(propValue);

            // Must be marked user-defined or it won't be shown in most DCCs
            fbxProperty.ModifyFlag(FbxPropertyFlags.EFlags.eUserDefined, true);
            fbxProperty.ModifyFlag(FbxPropertyFlags.EFlags.eAnimatable, true);

            for (int i = 0; i < fbxNode.GetChildCount(); i++)
            {
                AddCustomProperties(fbxNode.GetChild(i), propName, propValue + 1);
            }
        }
예제 #14
0
        bool HasSceneSkeleton(FbxNode pNode)
        {
            if (Skeleton.IsNodeSkeleton(pNode))
            {
                return(true);
            }

            for (int i = 0; i < pNode.GetChildCount(); i++)
            {
                if (HasSceneSkeleton(pNode.GetChild(i)))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #15
0
        private GameObject ImportNodes(
            FbxNode node, float fbxUnitToTiltUnit,
            ref long completedVerts, long totalVerts)
        {
            FbxNodeAttribute a = node.GetNodeAttribute();
            int nChildren      = node.GetChildCount();

            GameObject go = null;

            if (a != null)
            {
                var attrType = a.GetAttributeType();
                if (attrType == FbxNodeAttribute.EType.eMesh)
                {
                    go = ImportMesh(
                        node, fbxUnitToTiltUnit,
                        ref completedVerts, totalVerts);
                }
                else if (attrType == FbxNodeAttribute.EType.eNurbs ||
                         attrType == FbxNodeAttribute.EType.eSubDiv ||
                         attrType == FbxNodeAttribute.EType.eNurbsSurface)
                {
                    warnings.Add("Ignoring non-mesh geometry");
                }
            }

            for (int i = 0; i < nChildren; i++)
            {
                GameObject child = ImportNodes(
                    node.GetChild(i), fbxUnitToTiltUnit,
                    ref completedVerts, totalVerts);
                if (child != null)
                {
                    if (go == null)
                    {
                        go = new GameObject("Node");
                    }
                    child.transform.parent = go.transform;
                }
            }

            if (go != null)
            {
                ApplyTransform(node, go.transform, fbxUnitToTiltUnit);
            }
            return(go);
        }
예제 #16
0
        static bool CheckIsNodeContainsSkeletonRecursive(FbxNode node, Dictionary <ulong, bool> skeletonNodeTree)
        {
            bool isSkeletonNode = IsNodeSkeleton(node);

            for (int i = 0; i < node.GetChildCount(); i++)
            {
                FbxNode pChild = node.GetChild(i);
                if (CheckIsNodeContainsSkeletonRecursive(pChild, skeletonNodeTree))
                {
                    isSkeletonNode = true;
                }
            }

            skeletonNodeTree[node.GetUniqueID()] = isSkeletonNode;

            return(isSkeletonNode);
        }
        // compare the hierarchy of two nodes
        private void CheckSceneHelper(FbxNode node1, FbxNode node2)
        {
            if (node1 == null && node2 == null)
            {
                return;
            }

            Assert.IsNotNull(node1);
            Assert.IsNotNull(node2);

            Assert.AreEqual(node1.GetChildCount(), node2.GetChildCount());
            Assert.AreEqual(node1.GetName(), node2.GetName());

            for (int i = 0; i < node1.GetChildCount(); i++)
            {
                // recurse through the hierarchy
                CheckSceneHelper(node1.GetChild(i), node2.GetChild(i));
            }
        }
        // compare the hierarchy and transform of two nodes
        private void CheckSceneHelper(FbxNode node1, FbxNode node2)
        {
            if (node1 == null && node2 == null)
            {
                return;
            }

            Assert.IsNotNull(node1);
            Assert.IsNotNull(node2);

            Assert.AreEqual(node1.GetChildCount(), node2.GetChildCount());

            // compare the transforms
            Assert.AreEqual(node1.LclTranslation.Get(), node2.LclTranslation.Get());
            Assert.AreEqual(node1.LclRotation.Get(), node2.LclRotation.Get());
            Assert.AreEqual(node1.LclScaling.Get(), node2.LclScaling.Get());

            Assert.AreEqual(node1.GetPreRotation(FbxNode.EPivotSet.eSourcePivot),
                            node2.GetPreRotation(FbxNode.EPivotSet.eSourcePivot));

            Assert.AreEqual(node1.GetPostRotation(FbxNode.EPivotSet.eSourcePivot),
                            node2.GetPostRotation(FbxNode.EPivotSet.eSourcePivot));

            Assert.AreEqual(node1.GetRotationPivot(FbxNode.EPivotSet.eSourcePivot),
                            node2.GetRotationPivot(FbxNode.EPivotSet.eSourcePivot));

            Assert.AreEqual(node1.GetScalingPivot(FbxNode.EPivotSet.eSourcePivot),
                            node2.GetScalingPivot(FbxNode.EPivotSet.eSourcePivot));

            Assert.AreEqual(node1.GetRotationOffset(FbxNode.EPivotSet.eSourcePivot),
                            node2.GetRotationOffset(FbxNode.EPivotSet.eSourcePivot));

            Assert.AreEqual(node1.GetScalingOffset(FbxNode.EPivotSet.eSourcePivot),
                            node2.GetScalingOffset(FbxNode.EPivotSet.eSourcePivot));

            Assert.AreEqual(node1.GetName(), node2.GetName());

            for (int i = 0; i < node1.GetChildCount(); i++)
            {
                // recurse through the hierarchy
                CheckSceneHelper(node1.GetChild(i), node2.GetChild(i));
            }
        }
예제 #19
0
        public void Node_AddChild_AddsChild()
        {
            // given:
            var node1 = new FbxNode("Node1");
            var node2 = new FbxNode("Node2");

            // require:
            Assert.AreEqual(0, node1.GetSrcObjectCount());
            Assert.AreEqual(0, node1.GetDstObjectCount());
            Assert.AreEqual(0, node1.GetSrcPropertyCount());
            Assert.AreEqual(0, node1.GetDstPropertyCount());
            Assert.AreEqual(0, node1.GetChildCount());
            Assert.AreEqual(null, node1.GetParent());

            Assert.AreEqual(0, node2.GetSrcObjectCount());
            Assert.AreEqual(0, node2.GetDstObjectCount());
            Assert.AreEqual(0, node2.GetSrcPropertyCount());
            Assert.AreEqual(0, node2.GetDstPropertyCount());
            Assert.AreEqual(0, node2.GetChildCount());
            Assert.AreEqual(null, node1.GetParent());

            // when:
            node1.AddChild(node2);

            // then:
            Assert.AreEqual(1, node1.GetSrcObjectCount());
            Assert.AreEqual(node2, node1.GetSrcObject(0));
            Assert.AreEqual(0, node1.GetDstObjectCount());
            Assert.AreEqual(0, node1.GetSrcPropertyCount());
            Assert.AreEqual(0, node1.GetDstPropertyCount());
            Assert.AreEqual(1, node1.GetChildCount());
            Assert.AreEqual(node2, node1.GetChild(0));
            Assert.AreEqual(null, node1.GetParent());

            Assert.AreEqual(0, node2.GetSrcObjectCount());
            Assert.AreEqual(1, node2.GetDstObjectCount());
            Assert.AreEqual(node1, node2.GetDstObject(0));
            Assert.AreEqual(0, node2.GetSrcPropertyCount());
            Assert.AreEqual(0, node2.GetDstPropertyCount());
            Assert.AreEqual(0, node2.GetChildCount());
            Assert.AreEqual(node1, node2.GetParent());
        }
        private void CheckCustomProperties(FbxNode origNode, FbxNode importNode, string propName)
        {
            var origProperty   = origNode.FindProperty(propName);
            var importProperty = importNode.FindProperty(propName);

            Assert.IsNotNull(origProperty);
            Assert.IsNotNull(importProperty);
            Assert.IsTrue(origProperty.IsValid());
            Assert.IsTrue(importProperty.IsValid());

            Assert.AreEqual(origProperty.GetInt(), importProperty.GetInt());
            Assert.AreEqual(origProperty.GetFlag(FbxPropertyFlags.EFlags.eUserDefined), importProperty.GetFlag(FbxPropertyFlags.EFlags.eUserDefined));
            Assert.AreEqual(origProperty.GetFlag(FbxPropertyFlags.EFlags.eAnimatable), importProperty.GetFlag(FbxPropertyFlags.EFlags.eAnimatable));

            Assert.AreEqual(origNode.GetChildCount(), importNode.GetChildCount());
            for (int i = 0; i < origNode.GetChildCount(); i++)
            {
                CheckCustomProperties(origNode.GetChild(i), importNode.GetChild(i), propName);
            }
        }
예제 #21
0
        private void CheckSceneHelper(FbxNode node, FbxMesh mesh, FbxSurfaceMaterial material)
        {
            if (node == null)
            {
                return;
            }

            Assert.AreEqual(mesh, node.GetMesh());

            int matIndex = node.GetMaterialIndex(m_materialName);

            Assert.GreaterOrEqual(matIndex, 0);
            Assert.AreEqual(material, node.GetMaterial(matIndex));

            for (int i = 0; i < node.GetChildCount(); i++)
            {
                // recurse through the hierarchy
                CheckSceneHelper(node.GetChild(i), mesh, material);
            }
        }
예제 #22
0
        static void LoadSkinsFromNodeRecursive(FbxNode pNode, List <FbxSkin> skinsResult)
        {
            FbxNodeAttribute pNodeAttribute = pNode.GetNodeAttribute();

            if (pNodeAttribute?.GetAttributeType() == FbxNodeAttribute.EType.eMesh)
            {
                FbxMesh pMesh     = pNode.GetMesh();
                int     skinCount = pMesh.GetDeformerCount(FbxDeformer.EDeformerType.eSkin);
                for (int i = 0; i < skinCount; i++)
                {
                    FbxSkin pSkin = FbxSkin.Cast(pMesh.GetDeformer(i, FbxDeformer.EDeformerType.eSkin));
                    skinsResult.Add(pSkin);
                }
            }

            for (int i = 0; i < pNode.GetChildCount(); i++)
            {
                LoadSkinsFromNodeRecursive(pNode.GetChild(i), skinsResult);
            }
        }
예제 #23
0
            /// <summary>
            /// Process fbxNode, configure the transform and construct mesh
            /// </summary>
            public void ProcessNode(FbxNode fbxNode, GameObject unityParentObj = null)
            {
                string name = fbxNode.GetName();

                GameObject unityGo = new GameObject(name);

                NumNodes++;

                if (unityParentObj != null)
                {
                    unityGo.transform.parent = unityParentObj.transform;
                }

                ProcessTransform(fbxNode, unityGo);
                ProcessMesh(fbxNode, unityGo);

                for (int i = 0; i < fbxNode.GetChildCount(); ++i)
                {
                    ProcessNode(fbxNode.GetChild(i), unityGo);
                }
            }
예제 #24
0
        private static long GetTotalVerts(FbxNode node)
        {
            FbxNodeAttribute a = node.GetNodeAttribute();
            int  nChildren     = node.GetChildCount();
            long vertCount     = 0;

            if (a != null)
            {
                var attrType = a.GetAttributeType();
                if (attrType == FbxNodeAttribute.EType.eMesh)
                {
                    FbxMesh fbxMesh = node.GetMesh();
                    fbxMesh.SplitPoints();
                    vertCount = fbxMesh.GetControlPointsCount();
                }
            }
            for (int i = 0; i < nChildren; i++)
            {
                vertCount += GetTotalVerts(node.GetChild(i));
            }
            return(vertCount);
        }
예제 #25
0
        protected override FbxScene CreateScene(FbxManager manager)
        {
            // Add a skeleton to the cube that we created in StaticMeshExportTest
            FbxScene scene = base.CreateScene(manager);

            FbxNode meshNode         = scene.GetRootNode().GetChild(0);
            FbxNode skeletonRootNode = CreateSkeleton(scene);

            FbxNode rootNode = scene.GetRootNode();

            rootNode.AddChild(skeletonRootNode);

            LinkMeshToSkeleton(scene, meshNode, skeletonRootNode);

            FbxNode limb1 = skeletonRootNode.GetChild(0);
            FbxNode limb2 = limb1.GetChild(0);

            ExportBindPose(meshNode, scene, new List <FbxNode> ()
            {
                skeletonRootNode, limb1, limb2
            });

            return(scene);
        }
예제 #26
0
 public FbxObjectGeometryLayerElementUv(FbxNode node) : base(node, 2)
 {
     Array = node.GetChild("UV").GetProperty <double[]>(0);
     Index = node.GetChild("UVIndex").GetProperty <int[]>(0);
 }
예제 #27
0
 public FbxObjectGeometryLayerElementMaterial(FbxNode node) : base(node, 1)
 {
     Array = node.GetChild("Materials").GetProperty <int[]>(0);
 }
예제 #28
0
        public void RootNode_AddChild_AddsNodeSubtree()
        {
            // given:
            var scene = new FbxScene("TheScene");
            var root  = scene.GetRootNode();
            var node2 = new FbxNode("ChildNode");
            var node3 = new FbxNode("ChildNode");

            node2.AddChild(node3);

            // require:
            Assert.AreEqual(3, scene.GetSrcObjectCount());
            Assert.AreEqual(root, scene.GetSrcObject(0));
            Assert.AreEqual(scene.GetGlobalSettings(), scene.GetSrcObject(1));
            Assert.AreEqual(scene.GetAnimationEvaluator(), scene.GetSrcObject(2));
            Assert.AreEqual(0, scene.GetDstObjectCount());
            Assert.AreEqual(1, scene.GetNodeCount());
            Assert.AreEqual(root, scene.GetNode(0));

            Assert.AreEqual(0, root.GetSrcObjectCount());
            Assert.AreEqual(1, root.GetDstObjectCount());
            Assert.AreEqual(scene, root.GetDstObject(0));
            Assert.AreEqual(0, root.GetChildCount());
            Assert.AreEqual(scene, root.GetScene());

            Assert.AreEqual(1, node2.GetSrcObjectCount());
            Assert.AreEqual(node3, node2.GetSrcObject(0));
            Assert.AreEqual(0, node2.GetDstObjectCount());
            Assert.AreEqual(1, node2.GetChildCount());
            Assert.AreEqual(node3, node2.GetChild(0));
            Assert.AreEqual(null, node2.GetParent());
            Assert.AreEqual(null, node2.GetScene());

            Assert.AreEqual(0, node3.GetSrcObjectCount());
            Assert.AreEqual(1, node3.GetDstObjectCount());
            Assert.AreEqual(node2, node3.GetDstObject(0));
            Assert.AreEqual(0, node3.GetChildCount());
            Assert.AreEqual(node2, node3.GetParent());
            Assert.AreEqual(null, node3.GetScene());

            // when:
            root.AddChild(node2);

            // then:
            Assert.AreEqual(5, scene.GetSrcObjectCount());
            Assert.AreEqual(root, scene.GetSrcObject(0));
            Assert.AreEqual(scene.GetGlobalSettings(), scene.GetSrcObject(1));
            Assert.AreEqual(scene.GetAnimationEvaluator(), scene.GetSrcObject(2));
            Assert.AreEqual(node2, scene.GetSrcObject(3));
            Assert.AreEqual(node3, scene.GetSrcObject(4));
            Assert.AreEqual(0, scene.GetDstObjectCount());
            Assert.AreEqual(3, scene.GetNodeCount());
            Assert.AreEqual(root, scene.GetNode(0));
            Assert.AreEqual(node2, scene.GetNode(1));
            Assert.AreEqual(node3, scene.GetNode(2));

            Assert.AreEqual(1, root.GetSrcObjectCount());
            Assert.AreEqual(node2, root.GetSrcObject(0));
            Assert.AreEqual(1, root.GetDstObjectCount());
            Assert.AreEqual(scene, root.GetDstObject(0));
            Assert.AreEqual(1, root.GetChildCount());
            Assert.AreEqual(node2, root.GetChild(0));
            Assert.AreEqual(scene, root.GetScene());

            Assert.AreEqual(1, node2.GetSrcObjectCount());
            Assert.AreEqual(node3, node2.GetSrcObject(0));
            Assert.AreEqual(2, node2.GetDstObjectCount());
            Assert.AreEqual(root, node2.GetDstObject(0));
            Assert.AreEqual(scene, node2.GetDstObject(1));
            Assert.AreEqual(1, node2.GetChildCount());
            Assert.AreEqual(node3, node2.GetChild(0));
            Assert.AreEqual(root, node2.GetParent());
            Assert.AreEqual(scene, node2.GetScene());

            Assert.AreEqual(0, node3.GetSrcObjectCount());
            Assert.AreEqual(2, node3.GetDstObjectCount());
            Assert.AreEqual(node2, node3.GetDstObject(0));
            Assert.AreEqual(scene, node3.GetDstObject(1));
            Assert.AreEqual(0, node3.GetChildCount());
            Assert.AreEqual(node2, node3.GetParent());
            Assert.AreEqual(scene, node3.GetScene());
        }
예제 #29
0
            /// <summary>
            /// Process fbx scene by doing nothing
            /// </summary>
            public void ProcessNode(FbxNode fbxNode, GameObject unityParentObj = null, bool constructTransform = false)
            {
                string name = fbxNode.GetName();

                GameObject unityGo = new GameObject(name);

                NumNodes++;

                if (unityParentObj != null)
                {
                    unityGo.transform.parent = unityParentObj.transform;
                }

                FbxAMatrix fbxTransform = null;

                if (constructTransform)
                {
#if UNI_18844
                    // Construct rotation matrices
                    FbxVector4 fbxRotation  = new FbxVector4(fbxNode.LclRotation.Get());
                    FbxAMatrix fbxRotationM = new FbxAMatrix();
                    fbxRotationM.SetR(fbxRotation);

                    FbxVector4 fbxPreRotation  = new FbxVector4(fbxNode.PreRotation.Get());
                    FbxAMatrix fbxPreRotationM = new FbxAMatrix();
                    fbxPreRotationM.SetR(fbxPreRotation);

                    FbxVector4 fbxPostRotation  = new FbxVector4(fbxNode.PostRotation.Get());
                    FbxAMatrix fbxPostRotationM = new FbxAMatrix();
                    fbxPostRotationM.SetR(fbxPostRotation);

                    // Construct translation matrix
                    FbxAMatrix fbxTranslationM = new FbxAMatrix();
                    FbxVector4 fbxTranslation  = new FbxVector4(fbxNode.LclTranslation.Get());
                    fbxTranslationM.SetT(fbxTranslation);

                    // Construct scaling matrix
                    FbxAMatrix fbxScalingM = new FbxAMatrix();
                    FbxVector4 fbxScaling  = new FbxVector4(fbxNode.LclScaling.Get());
                    fbxScalingM.SetS(fbxScaling);

                    // Construct offset and pivot matrices
                    FbxAMatrix fbxRotationOffsetM = new FbxAMatrix();
                    FbxVector4 fbxRotationOffset  = fbxNode.RotationOffset.Get();
                    fbxRotationOffsetM.SetT(fbxRotationOffset);

                    FbxAMatrix fbxRotationPivotM = new FbxAMatrix();
                    FbxVector4 fbxRotationPivot  = fbxNode.RotationPivot.Get();
                    fbxRotationPivotM.SetT(fbxRotationPivot);

                    FbxAMatrix fbxScalingOffsetM = new FbxAMatrix();
                    FbxVector4 fbxScalingOffset  = fbxNode.ScalingOffset.Get();
                    fbxScalingOffsetM.SetT(fbxScalingOffset);

                    FbxAMatrix fbxScalingPivotM = new FbxAMatrix();
                    FbxVector4 fbxScalingPivot  = fbxNode.ScalingPivot.Get();
                    fbxScalingPivotM.SetT(fbxScalingPivot);

                    fbxTransform =
                        fbxTranslationM *
                        fbxRotationOffsetM *
                        fbxRotationPivotM *
                        fbxPreRotationM *
                        fbxRotationM *
                        fbxPostRotationM *
                        fbxRotationPivotM.Inverse() *
                        fbxScalingOffsetM *
                        fbxScalingPivotM *
                        fbxScalingM *
                        fbxScalingPivotM.Inverse();

                    lclTrs = fbxTransform.GetT();
                    lclRot = fbxTransform.GetQ();
                    lclScl = fbxTransform.GetS();
#endif
                }
                else
                {
                    fbxTransform = fbxNode.EvaluateLocalTransform();
                }

                if (fbxTransform == null)
                {
                    Debug.LogError(string.Format("failed to retrieve transform for node : {0}", fbxNode.GetName()));
                    return;
                }

                FbxVector4    lclTrs = fbxTransform.GetT();
                FbxQuaternion lclRot = fbxTransform.GetQ();
                FbxVector4    lclScl = fbxTransform.GetS();

                Debug.Log(string.Format("processing {3} Lcl : T({0}) R({1}) S({2})",
                                        lclTrs.ToString(),
                                        lclRot.ToString(),
                                        lclScl.ToString(),
                                        fbxNode.GetName()));

                // check we can handle translation value
                Debug.Assert(lclTrs.X <= float.MaxValue && lclTrs.X >= float.MinValue);
                Debug.Assert(lclTrs.Y <= float.MaxValue && lclTrs.Y >= float.MinValue);
                Debug.Assert(lclTrs.Z <= float.MaxValue && lclTrs.Z >= float.MinValue);

                unityGo.transform.localPosition = new Vector3((float)lclTrs.X, (float)lclTrs.Y, (float)lclTrs.Z);
                unityGo.transform.localRotation = new Quaternion((float)lclRot[0], (float)lclRot[1], (float)lclRot[2], (float)lclRot[3]);
                unityGo.transform.localScale    = new Vector3((float)lclScl.X, (float)lclScl.Y, (float)lclScl.Z);

                for (int i = 0; i < fbxNode.GetChildCount(); ++i)
                {
                    ProcessNode(fbxNode.GetChild(i), unityGo);
                }
            }
예제 #30
0
 public FbxObjectGeometryLayerElementNormal(FbxNode node, FbxObjectGeometryPolygonMap map) : base(node, 3)
 {
     Array = node.GetChild("Normals").GetProperty <double[]>(0);
 }