Ejemplo n.º 1
0
        } //OnImportAsset

        public void ReadWithoutAssetImportContext(string filePath)
        {
            Fmdl fmdl = new Fmdl(Path.GetFileNameWithoutExtension(filePath));
            fmdl.Read(filePath);

            int boneCount = fmdl.fmdlBones != null ? fmdl.fmdlBones.Length : 0;
            int materialCount = fmdl.fmdlMaterialInstances.Length;
            int textureCount = fmdl.fmdlTextures != null ? fmdl.fmdlTextures.Length : 0;
            int meshCount = fmdl.fmdlMeshInfos.Length;
            int meshGroupCount = fmdl.fmdlMeshGroups.Length;

            GameObject mainObject = new GameObject(fmdl.name);
            FoxModel foxModel = mainObject.AddComponent<FoxModel>();
            foxModel.meshGroups = new FoxMeshGroup[meshGroupCount];
            foxModel.meshDefinitions = new FoxMeshDefinition[meshCount];
            Transform[] bones = new Transform[boneCount];
            Texture[] textures = new Texture[textureCount];
            Material[] materials = new Material[materialCount];
            Mesh[] meshes = new Mesh[meshCount];

            Transform rootBone = new GameObject().transform;
            rootBone.name = "[Root]";
            rootBone.parent = mainObject.transform;

            Read(fmdl, mainObject, foxModel, bones, textures, materials, meshes, rootBone);
        } //ReadWithoutAssetImportContext
Ejemplo n.º 2
0
    public override void OnImportAsset(AssetImportContext ctx)
    {
        FileStream stream = new FileStream(ctx.assetPath, FileMode.Open);

        Fmdl       fmdl  = new Fmdl(Path.GetFileNameWithoutExtension(ctx.assetPath));
        UnityModel model = new UnityModel();

        fmdl.Read(stream);
        GameObject fmdlGameObject = model.GetDataFromFmdl(fmdl);

        ctx.AddObjectToAsset(ctx.assetPath, fmdlGameObject);
        ctx.SetMainObject(fmdlGameObject);
        stream.Close();
    }
Ejemplo n.º 3
0
        } //LoadTextureDXT

        private void ReadWithAssetImportContext(AssetImportContext ctx, string filePath)
        {
            Fmdl fmdl = new Fmdl(Path.GetFileNameWithoutExtension(filePath));
            fmdl.Read(filePath);

            int boneCount = fmdl.fmdlBones != null ? fmdl.fmdlBones.Length : 0;
            int materialCount = fmdl.fmdlMaterialInstances.Length;
            int textureCount = fmdl.fmdlTextures != null ? fmdl.fmdlTextures.Length : 0;
            int meshCount = fmdl.fmdlMeshInfos.Length;
            int meshGroupCount = fmdl.fmdlMeshGroups.Length;

            GameObject mainObject = new GameObject(fmdl.name);
            FoxModel foxModel = mainObject.AddComponent<FoxModel>();
            foxModel.meshGroups = new FoxMeshGroup[meshGroupCount];
            foxModel.meshDefinitions = new FoxMeshDefinition[meshCount];
            Transform[] bones = new Transform[boneCount];
            Texture[] textures = new Texture[textureCount];
            Material[] materials = new Material[materialCount];
            Mesh[] meshes = new Mesh[meshCount];

            Transform rootBone = new GameObject().transform;
            rootBone.name = "[Root]";
            rootBone.parent = mainObject.transform;

            Read(fmdl, mainObject, foxModel, bones, textures, materials, meshes, rootBone);

            ctx.AddObjectToAsset("mainObject", mainObject);
            ctx.SetMainObject(mainObject);

            for (int i = 0; i < textureCount; i++)
                ctx.AddObjectToAsset($"Texture {i}", textures[i]);

            for (int i = 0; i < materialCount; i++)
                ctx.AddObjectToAsset($"Material {i}", materials[i]);

            for (int i = 0; i < meshCount; i++)
                ctx.AddObjectToAsset($"Mesh {i}", meshes[i]);
        } //ReadWithAssetImportContext
Ejemplo n.º 4
0
        public void Import(Stream input, string path)
        {
            var prefabPath = Path.GetDirectoryName(path) + "/" + Path.GetFileNameWithoutExtension(path) + ".prefab";

            if (File.Exists(prefabPath))
            {
                return;
            }

            try
            {
                var reader = new Fmdl();
                reader.Read(input);

                Directory.CreateDirectory(Path.GetDirectoryName(Directory.GetParent(assetPath) + "/" + path));
                var createMeshCommand = new CreateMesh(() => reader.CreateAndSaveMesh(path));
                unityThreadDispacher.DispatchCommand(createMeshCommand);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError(e);
                throw;
            }
        }