protected UnityVertexData parserSkeleton(SkinnedMeshRenderer renderer, UnityScene scene)
        {
            var bones = renderer.bones;
            var mesh  = renderer.sharedMesh;
            var poses = mesh.bindposes;

            nameIndex = 0;

            UnityVertexData data = new UnityVertexData();

            data.vertex          = Export.boneWeightToBytes(mesh.boneWeights);
            data.data32PerVertex = 8;

            var dict = skeletonRoot2Dict(scene.getAvatarData(scene).root);

            for (int i = 0; i < bones.Length; i++)
            {
                var bone = bones[i];
                if (dict.ContainsKey(bone.name))
                {
                    var node = dict[bone.name];
                    node.inv   = Export.Matrix4x4ToBytes(poses[i]);
                    node.index = i;
                }
            }

            // getUsedSkeleton(mesh.boneWeights);

            return(data);
        }
        public override object parser(GameObject _object, Component component, UnityScene unityScene)
        {
            UnityVertexData skeletonData = null;

            SkinnedMeshRenderer renderer = component as SkinnedMeshRenderer;

            skeletonData = parserSkeleton(renderer, unityScene);

            UnityMeshData meshData = base.parser(_object, component, unityScene) as UnityMeshData;

            meshData.skeleton = skeletonData;

            return(meshData);
        }
Exemple #3
0
        public override object parser(GameObject _object, Component component, UnityScene unityScene)
        {
            Renderer renderer = component as Renderer;
            Mesh     mesh     = getMesh(renderer);

            if (null == mesh)
            {
                return(null);
            }

            UnityMeshData   meshData   = new UnityMeshData();
            UnityVertexData vertexData = new UnityVertexData();

            meshData.vertex = vertexData;

            /*pos*/
            Vector3[] vectors = mesh.vertices;
            /*normal*/
            Vector3[] normals = mesh.normals;
            /*uv*/
            Vector2[] uvs      = mesh.uv;
            Vector4[] tangnets = null;//mesh.tangents;
            Color[]   colors   = mesh.colors;



            int numVertices = vectors.Length;

            meshData.numVertices = numVertices;

            int offset = 0;
            Dictionary <string, Variable> variables = new Dictionary <string, Variable>();

            if (null != vectors && numVertices == vectors.Length)
            {
                variables.Add("pos", new Variable(3, offset));
                offset += 3;
            }

            if (null != normals && numVertices == normals.Length)
            {
                variables.Add("normal", new Variable(3, offset));
                offset += 3;
            }

            if (null != tangnets && 0 != tangnets.Length)
            {
                variables.Add("tangnet", new Variable(4, offset));
                offset += 4;
            }

            if (null != uvs && numVertices == uvs.Length)
            {
                variables.Add("uv", new Variable(2, offset));
                offset += 2;
            }


            if (null != colors && numVertices == colors.Length)
            {
                variables.Add("color", new Variable(4, offset));
                offset += 4;
            }

            variables.Add("data32PerVertex", new Variable(offset, offset));


            vertexData.vertex = Export.vector3toByte(vectors, normals, uvs, tangnets, colors);

            vertexData.data32PerVertex = offset;
            vertexData.variables       = variables;



            meshData.index = Export.ToUnit16(mesh.triangles);

            meshData.numTriangles = mesh.triangles.Length / 3;

            meshData.bounds = Export.toUntiyBounds(mesh.bounds, new Matrix4x4());

            // meshData.skeleton = skeletonData;


            meshData.material = Export.ExportMaterial(renderer.material);

            meshData.node = renderer.gameObject.name;

            if ("" == meshData.node)
            {
                Debug.LogError("error node name");
            }



            return(meshData);
        }
Exemple #4
0
        protected UnityMeshData toMeshData(Renderer renderer, UnityScene unityScene)
        {
            Mesh            mesh         = null;
            UnityVertexData skeletonData = null;

            if (renderer is MeshRenderer)
            {
                mesh = renderer.GetComponent <MeshFilter>().mesh;
            }
            else if (renderer is SkinnedMeshRenderer)
            {
                mesh         = (renderer as SkinnedMeshRenderer).sharedMesh;
                skeletonData = parserSkeleton(renderer as SkinnedMeshRenderer, unityScene);
            }

            if (null == mesh)
            {
                return(null);
            }

            UnityMeshData   meshData   = new UnityMeshData();
            UnityVertexData vertexData = new UnityVertexData();

            meshData.vertex = vertexData;


            /*pos*/
            Vector3[] vectors = mesh.vertices;
            /*normal*/
            Vector3[] normals = mesh.normals;
            /*uv*/
            Vector2[] uvs      = mesh.uv;
            Vector4[] tangnets = null;//mesh.tangents;
            Color[]   colors   = mesh.colors;



            int numVertices = vectors.Length;

            meshData.numVertices = numVertices;

            int offset = 0;
            Dictionary <string, Variable> variables = new Dictionary <string, Variable>();

            if (null != vectors && numVertices == vectors.Length)
            {
                variables.Add("pos", new Variable(3, offset));
                offset += 3;
            }

            if (null != normals && numVertices == normals.Length)
            {
                variables.Add("normal", new Variable(3, offset));
                offset += 3;
            }

            if (null != tangnets && 0 != tangnets.Length)
            {
                variables.Add("tangnet", new Variable(4, offset));
                offset += 4;
            }

            if (null != uvs && numVertices == uvs.Length)
            {
                variables.Add("uv", new Variable(2, offset));
                offset += 2;
            }


            if (null != colors && numVertices == colors.Length)
            {
                variables.Add("color", new Variable(4, offset));
                offset += 4;
            }

            variables.Add("data32PerVertex", new Variable(offset, offset));


            vertexData.vertex = Export.vector3toByte(vectors, normals, uvs, tangnets, colors);

            vertexData.data32PerVertex = offset;
            vertexData.variables       = variables;



            meshData.index = Export.ToUnit16(mesh.triangles);

            meshData.numTriangles = mesh.triangles.Length / 3;

            meshData.bounds = Export.toUntiyBounds(mesh.bounds, Export.newMatrix4x4());

            meshData.skeleton = skeletonData;


            meshData.material = Export.ExportMaterial(renderer.material, unityScene);

            meshData.node = renderer.gameObject.name;

            if ("" == meshData.node)
            {
                Debug.LogError("error node name");
            }



            return(meshData);
        }