コード例 #1
0
            // Use this for initialization
            //[MenuItem("Puppet3D/export collada")]
            static public void ExportCollad()
            {
                SkinnedMeshRenderer smr    = Selection.activeGameObject.GetComponent <SkinnedMeshRenderer>();
                ColladaExporter     export = new ColladaExporter(("Assets/" + Selection.activeGameObject.name + ".dae"), true);

                export.AddGeometry(Selection.activeGameObject.name, smr.sharedMesh, smr);
                export.AddGeometryToScene(Selection.activeGameObject.name, Selection.activeGameObject.name);

                export.AddControllerToScene(smr.bones);


                export.Save();
                return;

                /*
                 * COLLADA collada = new COLLADA();
                 * material mat = new material();
                 * mat.ID = "lambert1";
                 * mat.Name = "lambert1";
                 *
                 * geometry geo = new geometry();
                 * geo.ID = "cube";
                 * geo.Name = "cube";
                 * geometry.source pos = new geometry.source();
                 * pos.float_array.FloatString = "0 0 0\n0 0 0";
                 * pos.float_array.ID = "cube-Position-array";
                 * pos.float_array.count = 2;
                 * geometry.source normal = new geometry.source();
                 * geometry.source uv0 = new geometry.source();
                 *
                 * geo.mesh.Add(pos);
                 * geo.mesh.Add(normal);
                 * geo.mesh.Add(uv0);
                 *
                 * collada.library_materials.Add(mat);
                 * collada.library_geometries.Add(geo);
                 *
                 * string path = Path.Combine(Application.persistentDataPath, "monsters.xml");
                 * Debug.Log(path);
                 * collada.Save(path);*/
            }
コード例 #2
0
        static public void ExportCollad()
        {
            if (Selection.activeGameObject == null)
            {
                return;
            }
            SkinnedMeshRenderer smr = Selection.activeGameObject.GetComponent <SkinnedMeshRenderer>();

            if (smr == null)
            {
                Debug.LogWarning("Please selct an object with a skinnedMeshRenderer");
                return;
            }

            string path = AssetDatabase.GetAssetPath(smr.sharedMesh);

            path = path.Remove(path.Length - 6, 6);
            string newPath = AssetDatabase.GenerateUniqueAssetPath(path + ".dae");

            //ColladaExporter export = new ColladaExporter(("Assets/" + Selection.activeGameObject.name + ".dae"), true);
            Debug.Log(newPath);
            ColladaExporter export = new ColladaExporter(newPath, true);

            List <Transform> bones = new List <Transform>();

            GameObject[] objects = Selection.gameObjects;
            foreach (GameObject obj in objects)
            {
                smr = obj.GetComponent <SkinnedMeshRenderer>();
                if (smr == null)
                {
                    Debug.LogWarning("Please selct an object with a skinnedMeshRenderer");
                    break;
                }

                Mesh mesh = smr.sharedMesh;

                if (mesh.subMeshCount > 1)
                {
                    Mesh newMesh = new Mesh();
                    for (int index = 0; index < mesh.subMeshCount; index++)
                    {
                        newMesh              = new Mesh();
                        newMesh.vertices     = mesh.vertices;
                        newMesh.colors       = mesh.colors;
                        newMesh.normals      = mesh.normals;
                        newMesh.uv           = mesh.uv;
                        newMesh.bindposes    = mesh.bindposes;
                        newMesh.boneWeights  = mesh.boneWeights;
                        newMesh.tangents     = mesh.tangents;
                        newMesh.subMeshCount = 1;

                        newMesh.SetTriangles(mesh.GetTriangles(index), 0);
                        export.AddGeometry(obj.name + index, newMesh, smr);
                        export.AddGeometryToScene(obj.name + index, obj.name + index);
                    }
                }
                else
                {
                    export.AddGeometry(obj.name, mesh, smr);
                    export.AddGeometryToScene(obj.name, obj.name);
                }



                foreach (Transform bone in smr.bones)
                {
                    if (!bones.Contains(bone))
                    {
                        bones.Add(bone);
                    }
                }
            }
            export.AddControllerToScene(bones.ToArray());

            export.Save();
            return;
        }