Exemplo n.º 1
0
        public override JSONComponent ToJSON()
        {
            var json = new JSONTransform();

            json.type          = "Transform";
            json.localPosition = unityTransform.localPosition;
            json.localRotation = unityTransform.localEulerAngles.z;
            json.localScale    = unityTransform.localScale;
            return(json);
        }
Exemplo n.º 2
0
        public new JSONMesh ToJSON()
        {
            var json = new JSONMesh();

            json.name = name;

            // submeshes
            json.subMeshCount = unityMesh.subMeshCount;
            json.triangles    = new int[unityMesh.subMeshCount][];
            for (int i = 0; i < unityMesh.subMeshCount; i++)
            {
                json.triangles[i] = unityMesh.GetTriangles(i);
            }

            // Vertices
            json.vertexCount     = unityMesh.vertexCount;
            json.vertexPositions = unityMesh.vertices;
            json.vertexUV        = unityMesh.uv;
            json.vertexUV2       = unityMesh.uv2;
            json.vertexColors    = unityMesh.colors;
            json.vertexNormals   = unityMesh.normals;
            json.vertexTangents  = unityMesh.tangents;
            json.bindPoses       = unityMesh.bindposes;
            json.boneWeights     = new JSONBoneWeight[unityMesh.boneWeights.Length];

            json.rootBone = rootBone;

            for (int i = 0; i < unityMesh.boneWeights.Length; i++)
            {
                var bw  = unityMesh.boneWeights[i];
                var jbw = new JSONBoneWeight();
                jbw.indexes[0]      = bw.boneIndex0;
                jbw.indexes[1]      = bw.boneIndex1;
                jbw.indexes[2]      = bw.boneIndex2;
                jbw.indexes[3]      = bw.boneIndex3;
                jbw.weights[0]      = bw.weight0;
                jbw.weights[1]      = bw.weight1;
                jbw.weights[2]      = bw.weight2;
                jbw.weights[3]      = bw.weight3;
                json.boneWeights[i] = jbw;
            }

            if (bones != null)
            {
                JSONTransform[] jbones = new JSONTransform[bones.Length];
                for (int i = 0; i < bones.Length; i++)
                {
                    JSONTransform jt = new JSONTransform();
                    jt.localPosition = bones[i].localPosition;
                    jt.localRotation = bones[i].localRotation;
                    jt.localScale    = bones[i].localScale;
                    jt.name          = bones[i].gameObject.name;
                    jt.parentName    = bones[i].parent == null ? "" : bones[i].parent.gameObject.name;
                    jt.type          = "Bone";
                    jbones[i]        = jt;
                }
                json.bones = jbones;
            }

            return(json);
        }