Beispiel #1
0
        public NullSkeletonPiece AppendSkeletonPiece()
        {
            NullSkeletonPiece piece = new NullSkeletonPiece(CurrentVersion);

            mBindingPieceNodeArray.Add(piece);
            return(piece);
        }
Beispiel #2
0
 private void ConvertSkeletonPiece(NullSkeletonPiece skeletonBinding, BoneWeight[] boneweights)
 {
     skeletonBinding.SetSkeletonBindingNodeCount(boneweights.Length);
     for (int i = 0; i < boneweights.Length; ++i)
     {
         skeletonBinding[i].AppendWeightNode(boneweights[i].boneIndex0, boneweights[i].weight0);
         skeletonBinding[i].AppendWeightNode(boneweights[i].boneIndex1, boneweights[i].weight1);
         skeletonBinding[i].AppendWeightNode(boneweights[i].boneIndex2, boneweights[i].weight2);
         skeletonBinding[i].AppendWeightNode(boneweights[i].boneIndex3, boneweights[i].weight3);
     }
 }
Beispiel #3
0
        public bool ExchangeSkeletonPiece(int first, int second)
        {
            if ((first >= GetSkeletonBindingCount()) || (second >= GetSkeletonBindingCount()))
            {
                return(false);
            }
            NullSkeletonPiece tmp = mBindingPieceNodeArray[first];

            mBindingPieceNodeArray[first]  = mBindingPieceNodeArray[second];
            mBindingPieceNodeArray[second] = tmp;
            return(true);
        }
Beispiel #4
0
        public bool BuildIndexedPrimitives()
        {
            bool res = false;

            if (mMeshObjectList != null)
            {
                List <NullMergeIndex> indexMapping = new List <NullMergeIndex>();
                for (int i = 0; i < mMeshObjectList.GetMeshObjectCount(); i++)
                {
                    NullMeshObject meshObject = mMeshObjectList[i];
                    res |= meshObject.BuildIndexedPrimitives(indexMapping);
                    if (meshObject.IsVertexAnimationMeshObject() && mVertexMorphAnimations != null)
                    {
                        for (int k = 0; k < mVertexMorphAnimations.GetAnimationCount(); k++)
                        {
                            NullVertexMorphAnimation animation = mVertexMorphAnimations[k];
                            for (int j = 0; j < animation.GetFrameCount(); j++)
                            {
                                NullVertexMorphAnimationFrame animationFrame = animation[j];
                                NullVertexMorphObject         morphObject    = animationFrame.FindMorphAnimationNodeByIndex(i);
                                Assert.IsTrue(morphObject != null, "");
                                res |= morphObject.BuildIndexedPrimitives(indexMapping);
                            }
                        }
                    }
                }
            }

            //try extract mesh-objects and skeleton-bindings
            if (mSkinObjectList != null)
            {
                for (int i = 0; i < mSkinObjectList.GetMeshObjectCount(); i++)
                {
                    List <NullMergeIndex> indexMapping = new List <NullMergeIndex>();
                    NullMeshObject        meshObject   = mSkinObjectList[i];
                    res |= meshObject.BuildIndexedPrimitives(indexMapping);
                    if (mSkeletonBinding != null && indexMapping.Count > 0)
                    {
                        NullSkeletonPiece skeletonPiece = mSkeletonBinding[i];
                        res |= skeletonPiece.BuildIndexedPrimitives(indexMapping);
                    }
                }
            }
            return(res);
        }
Beispiel #5
0
        private void CreateSkeletonMesh()
        {
            NullMeshFile meshFile = new NullMeshFile(NullWorkingFlag.WF_SKELETON_MESHPIECE);

            bool hadNormals  = mVertexNormals.Length > 0;
            bool hadTangents = mVertexTangents.Length > 0;
            bool hadColors   = mVertexColors.Length > 0;
            bool hadUv       = mVertexuvs.Length > 0;

            NullMeshObject meshObject  = meshFile.AppendSkinObject(NullPrimitiveType.MOT_INDEXED_PRIMITIVES, mVertexTriangles.Length, mVertexPoses.Length, true, true, true);
            NullUVGroup    uvGroup     = hadUv ? meshObject.GetOrCreateUVGroup(UVType.UVT_DEFAULT, mVertexPoses.Length) : null;
            int            vertexCount = mVertexPoses.Length;

            for (int i = 0; i < vertexCount; ++i)
            {
                meshObject.SetVertex(i, mVertexPoses[i]);
                if (hadColors)
                {
                    meshObject.SetVertexColor(i, Convert(mVertexColors[i]));
                }
                if (hadTangents)
                {
                    meshObject.SetTangent(i, mVertexTangents[i]);
                }
                if (hadNormals)
                {
                    meshObject.SetNormal(i, mVertexNormals[i]);
                }
                if (hadUv)
                {
                    uvGroup.SetUV(i, mVertexuvs[i]);
                }
            }

            for (int i = 0; i < mVertexTriangles.Length; i += 3)
            {
                int i1 = mVertexTriangles[i];
                int i2 = mVertexTriangles[i + 1];
                int i3 = mVertexTriangles[i + 2];
                meshObject.SetTriangleIndex(i, new Vector3Int(i1, i2, i3));
            }

            // 骨骼数
            NullNodeTree rootNode = meshFile.GetNodeTree();

            ConvertNodeTree(mRootBone, rootNode, mBindposes, mBones);

            // 权重绑定
            NullSkeletonBinding skeletonBinding = meshFile.GetSkeletonBinding();
            int pieceCount = 1; // 对应子模型,现在只限制一个子模型

            skeletonBinding.SetSkeletonName(mMesh.name);
            skeletonBinding.SetSkeletonBindingCount(pieceCount);
            for (int i = 0; i < pieceCount; ++i)
            {
                NullSkeletonPiece skeletonPiece = skeletonBinding[i];
                skeletonPiece.SetPieceHandle(i);
                ConvertSkeletonPiece(skeletonPiece, mBoneweights);
            }

            string fileName = OutPutDir + "/" + Target.name + ".hxs";

            using (NullMemoryStream stream = NullMemoryStream.WriteToFile(fileName))
            {
                meshFile.SaveToStream(stream);
            }
        }
Beispiel #6
0
        public bool ExtractToTriangles()
        {
            bool res = false;

            //try extract mesh-objects and vertex-morph animations
            if (mMeshObjectList != null)
            {
                for (int i = 0; i < mMeshObjectList.GetMeshObjectCount(); i++)
                {
                    List <Vector3Int> originalFaceIndices = new List <Vector3Int>();
                    NullMeshObject    meshObject          = mMeshObjectList[i];
                    res |= meshObject.ExtractToTriangles(originalFaceIndices);
                    if (meshObject.IsVertexAnimationMeshObject() && mVertexMorphAnimations != null)
                    {
                        for (int k = 0; k < mVertexMorphAnimations.GetAnimationCount(); k++)
                        {
                            NullVertexMorphAnimation animation = mVertexMorphAnimations[k];
                            for (int j = 0; j < animation.GetFrameCount(); j++)
                            {
                                NullVertexMorphAnimationFrame animationFrame = animation[j];
                                NullVertexMorphObject         morphObject    = animationFrame.FindMorphAnimationNodeByIndex(i);
                                Assert.IsTrue(morphObject != null, "");
                                switch (meshObject.GetMeshObjectType())
                                {
                                case NullPrimitiveType.MOT_INDEXED_PRIMITIVES:
                                    res |= morphObject.ExtractToTrianglesFromIndexedPrimitives(originalFaceIndices);
                                    break;
                                    //case NullPrimitiveType.MOT_TRIANGLE_STRIPS:
                                    //    res |= morphObject.ExtractToTrianglesFromStrips(meshObject.GetTriangleCount());
                                    //    break;
                                }
                            }
                        }
                    }
                    originalFaceIndices.Clear();
                }
            }

            //try extract mesh-objects and skeleton-bindings
            if (mSkinObjectList != null)
            {
                for (int i = 0; i < mSkinObjectList.GetMeshObjectCount(); i++)
                {
                    List <Vector3Int> originalFaceIndices = new List <Vector3Int>();
                    NullMeshObject    meshObject          = mSkinObjectList[i];
                    res |= meshObject.ExtractToTriangles(originalFaceIndices);
                    if (mSkeletonBinding != null && mSkeletonBinding.GetSkeletonBindingCount() > 0)
                    {
                        NullSkeletonPiece skeletonPiece = mSkeletonBinding[i];
                        switch (meshObject.GetMeshObjectType())
                        {
                        case NullPrimitiveType.MOT_INDEXED_PRIMITIVES:
                            res |= skeletonPiece.ExtractToTrianglesFromIndexedPrimitives(originalFaceIndices);
                            break;
                            //case HexMeshObject::MOT_TRIANGLE_STRIPS:
                            //    res |= skeletonPiece.ExtractToTrianglesFromStrips(meshObject.GetTriangleCount());
                            //    break;
                        }
                    }
                }
            }

            return(res);
        }