Exemplo n.º 1
0
        public RoseMapObjectData ImportObject(int objectIdx)
        {
            var objPath = Utils.CombinePath(targetPath, "Obj_" + objectIdx + ".asset");

            if (!File.Exists(objPath))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(objPath));

                var zscObj = zsc.Objects[objectIdx];
                var mdl    = ScriptableObject.CreateInstance <RoseMapObjectData>();

                for (int j = 0; j < zscObj.Models.Count; ++j)
                {
                    var part   = zscObj.Models[j];
                    var subObj = new RoseMapObjectData.SubObject();

                    subObj.mesh      = ImportMesh(part.ModelID);
                    subObj.material  = ImportMaterial(part.TextureID);
                    subObj.animation = null;
                    subObj.parent    = part.Parent;
                    subObj.position  = part.Position / 100;
                    subObj.rotation  = part.Rotation;
                    subObj.scale     = part.Scale;

                    /*
                     * if (part.CollisionLevel == ZSC.CollisionLevelType.None)
                     * {
                     *  subObj.colMode = 0;
                     * }
                     * else
                     * {
                     *  subObj.colMode = 1;
                     * }
                     *
                     * if (part.AnimationFilePath != "")
                     * {
                     *  var animPath = _basePath + "Anim_" + i.ToString() + "_" + j.ToString() + ".asset";
                     *  var clip = ImportNodeAnimation(animPath, part.AnimationFilePath);
                     *  subObj.animation = clip;
                     * }
                     */

                    mdl.subObjects.Add(subObj);
                }

                AssetDatabase.CreateAsset(mdl, objPath);
                EditorUtility.SetDirty(mdl);
                AssetDatabase.SaveAssets();
            }
            return(AssetDatabase.LoadAssetAtPath <RoseMapObjectData>(objPath));
        }
Exemplo n.º 2
0
        public void ImportModels()
        {
            _meshLookup = new Mesh[_f.ModelFiles.Count];
            for (int i = 0; i < _f.ModelFiles.Count; ++i)
            {
                var zmsPath = rootPath + _f.ModelFiles[i];
                if (!File.Exists(zmsPath))
                {
                    Debug.LogWarning("Failed to find referenced ZMS.");
                    continue;
                }

                var mesh = new Mesh();

                var zms = new Revise.Files.ZMS.ModelFile();
                zms.Load(zmsPath);

                var verts = new Vector3[zms.Vertices.Count];
                var uvs = new Vector2[zms.Vertices.Count];
                for (int k = 0; k < zms.Vertices.Count; ++k)
                {
                    var v = zms.Vertices[k];
                    v.TextureCoordinates[0].y = 1 - v.TextureCoordinates[0].y;

                    verts[k] =  rtuPosition(v.Position);
                    uvs[k] = v.TextureCoordinates[0];
                }
                mesh.vertices = verts;
                mesh.uv = uvs;

                int[] indices = new int[zms.Indices.Count * 3];
                for (int k = 0; k < zms.Indices.Count; ++k)
                {
                    indices[k * 3 + 0] = zms.Indices[k].X;
                    indices[k * 3 + 2] = zms.Indices[k].Y;
                    indices[k * 3 + 1] = zms.Indices[k].Z;
                }
                mesh.triangles = indices;

                mesh.RecalculateNormals();
                Unwrapping.GenerateSecondaryUVSet(mesh);

                var meshPath = _basePath + "Mesh_" + i.ToString() + ".asset";
                AssetDatabase.CreateAsset(mesh, meshPath);
                _meshLookup[i] = mesh;
            }

            _matLookup = new Material[_f.TextureFiles.Count];
            for (int i = 0; i < _f.TextureFiles.Count; ++i)
            {
                var tex = _f.TextureFiles[i];

                var texPath = _basePath + "Tex_" + texLookup[i].ToString() + ".DDS";
                if (!File.Exists(texPath))
                {
                    continue;
                }

                var tex2d = AssetDatabase.LoadAssetAtPath(texPath, typeof(Texture2D)) as Texture2D;

                Shader shader = null;
                if (tex.TwoSided) {
                    if (tex.AlphaTestEnabled)
                        shader = Shader.Find("Transparent/Cutout/DoubleSided");
                    else if (tex.AlphaEnabled)
                        shader = Shader.Find("Transparent/DoubleSided");
                    else {
                        Debug.LogWarning("Two-sided non-alpha material encountered.");
                    }
                } else if (tex.AlphaTestEnabled)
                    shader = Shader.Find("Transparent/Cutout/Diffuse");
                else if (tex.AlphaEnabled)
                    shader = Shader.Find("Transparent/Diffuse");
                else
                    shader = Shader.Find("Diffuse");

                if (!shader)
                {
                    Debug.LogWarning("Failed to find appropriate shader for material.");
                    continue;
                }

                var mat = new Material(shader);
                if (tex.AlphaTestEnabled)
                    mat.SetFloat("_Cutoff", (float)tex.AlphaReference / 256);
                mat.mainTexture = tex2d;

                var matPath = _basePath + "Mat_" + i.ToString() + ".mat";
                AssetDatabase.CreateAsset(mat, matPath);

                _matLookup[i] = mat;
            }

            for (int i = 0; i < _f.Objects.Count; ++i)
            {
                var obj = _f.Objects[i];
                var mdl = ScriptableObject.CreateInstance<RoseMapObjectData>();

                for (int j = 0; j < obj.Parts.Count; ++j)
                {
                    var part = obj.Parts[j];
                    var subObj = new RoseMapObjectData.SubObject();

                    subObj.mesh = _meshLookup[part.Model];
                    subObj.material = _matLookup[part.Texture];
                    subObj.animation = null;
                    subObj.parent = part.Parent;
                    subObj.position = rtuPosition(part.Position) / 100;
                    subObj.rotation = rtuRotation(part.Rotation);
                    subObj.scale = rtuScale(part.Scale);
                    if (part.Collision == Revise.Files.ZSC.CollisionType.None) {
                        subObj.colMode = 0;
                    } else {
                        subObj.colMode = 1;
                    }

                    if (part.AnimationFilePath != "") {
                        var animPath = _basePath + "Anim_" + i.ToString() + "_" + j.ToString() + ".asset";
                        var clip = ImportNodeAnimation(animPath, part.AnimationFilePath);
                        subObj.animation = clip;
                    }

                    mdl.subObjects.Add(subObj);
                }

                var mdlPath = _basePath + "Model_" + i.ToString() + ".asset";
                AssetDatabase.CreateAsset(mdl, mdlPath);
                EditorUtility.SetDirty(mdl);
            }
        }