Esempio n. 1
0
    public override void OnImportAsset(AssetImportContext ctx)
    {
        /* if(amf!=null&&!shouldReimport)
         *  return; */
        Debug.Log("Attempting to import AMF:" + ctx.assetPath);

        EditorUtility.DisplayProgressBar("Parsing" + ctx.assetPath, "Parsing...", 0);
        this.amf = ParseAMF(ctx.assetPath);

        string workingDir = ctx.assetPath.Substring(0, ctx.assetPath.LastIndexOf("/") + 1);

        /*
         * Setup materials first
         */
        Dictionary <string, Material>      mats        = new Dictionary <string, Material>();
        Dictionary <string, AMFShaderInfo> matsHelpers = new Dictionary <string, AMFShaderInfo>();

        System.IO.Directory.CreateDirectory(workingDir + "Materials/");
        //System.IO.Directory.CreateDirectory(workingDir+"MaterialHelpers/");
        AMFShaderInfo asi;
        float         totalMats    = amf.shaderInfos.Count;
        float         matsComplete = 0;

        foreach (AdjutantSharp.ShaderInfo si in amf.shaderInfos)
        {
            EditorUtility.DisplayProgressBar("Setting up Materials...", si.sName, (matsComplete / totalMats));
            asi      = (AMFShaderInfo)AMFShaderInfo.CreateInstance(typeof(AMFShaderInfo));
            asi.name = si.sName;
            asi.SaveData(si);
            if (!mats.ContainsKey(si.sName))
            {
                string   path     = workingDir + "Materials/" + si.sName + ".mat";
                Material material = (Material)AssetDatabase.LoadAssetAtPath(workingDir + "Materials/" + si.sName + ".mat", typeof(Material));

                if (material == null)
                {
                    asi.workingDir = workingDir;
                    material       = asi.CreateMaterial();

                    /* if(si.GetType()==typeof(RegularShader)){
                     *  material=SetupRegularMaterial((RegularShader)si,workingDir);
                     * }else{
                     *  material=SetupTerrainMaterial((TerrainShader)si,workingDir);
                     * } */

                    AssetDatabase.CreateAsset(material, workingDir + "Materials/" + si.sName + ".mat");
                }



                mats.Add(si.sName, material);
                matsHelpers.Add(si.sName, asi);
                ctx.AddObjectToAsset("MaterialHelper-" + asi.sName, asi);
                ctx.DependsOnSourceAsset(workingDir + "Materials/" + si.sName + ".mat");

                /* if(material!=null)
                 *  ctx.AddObjectToAsset(material.name,material); */
            }
            matsComplete++;
        }

        /*
         * Create Meshes
         */

        GameObject root = new GameObject(amf.modelName);

        //amf.name=amf.modelName+"-RawAMF";
        ctx.AddObjectToAsset(amf.modelName, root);

        /* ctx.AddObjectToAsset(amf.name,amf);
         * EditorUtility.SetDirty(amf); */
        ctx.SetMainObject(root);
        Dictionary <long, Mesh> meshList = ConvertMeshes(amf, mats, matsHelpers, root);

        EditorUtility.DisplayProgressBar("Parsing " + ctx.assetPath, "[5/5] Finishing up...", (5f / 5f));
        foreach (Mesh m in meshList.Values)
        {
            ctx.AddObjectToAsset(m.name, m);
        }
        if (CreateSkinnedMeshes)
        {
            Avatar a = root.GetComponent <Animator>().avatar;
            ctx.AddObjectToAsset(a.name, a);
        }


        Debug.Log("AMF import complete");
        EditorUtility.ClearProgressBar();
        shouldReimport = false;
    }
Esempio n. 2
0
    public override void OnImportAsset(AssetImportContext ctx)
    {
        Debug.Log("Attempting to import AMF:" + ctx.assetPath);
        progressString += ctx.assetPath;
        EditorUtility.DisplayProgressBar(progressString, "Parsing...", 0);
        AMF amf = ParseAMF(ctx.assetPath);

        string workingDir = ctx.assetPath.Substring(0, ctx.assetPath.LastIndexOf("/") + 1);

        /*
         * Setup materials first
         */
        Dictionary <string, Material>      mats        = new Dictionary <string, Material>();
        Dictionary <string, AMFShaderInfo> matsHelpers = new Dictionary <string, AMFShaderInfo>();

        System.IO.Directory.CreateDirectory(workingDir + "Materials/");
        //System.IO.Directory.CreateDirectory(workingDir+"MaterialHelpers/");
        AMFShaderInfo asi;
        float         totalMats    = amf.shaderInfos.Count;
        float         matsComplete = 0;

        foreach (AdjutantSharp.ShaderInfo si in amf.shaderInfos)
        {
            EditorUtility.DisplayProgressBar("Setting up Materials...", si.sName, (matsComplete / totalMats));
            asi      = (AMFShaderInfo)AMFShaderInfo.CreateInstance(typeof(AMFShaderInfo));
            asi.name = si.sName;
            asi.SaveData(si);
            if (!mats.ContainsKey(si.sName))
            {
                string   path     = workingDir + "Materials/" + si.sName + ".mat";
                Material material = (Material)AssetDatabase.LoadAssetAtPath(workingDir + "Materials/" + si.sName + ".mat", typeof(Material));

                if (material == null)
                {
                    asi.workingDir = workingDir;
                    material       = asi.CreateMaterial();

                    /* if(si.GetType()==typeof(RegularShader)){
                     *  material=SetupRegularMaterial((RegularShader)si,workingDir);
                     * }else{
                     *  material=SetupTerrainMaterial((TerrainShader)si,workingDir);
                     * } */

                    AssetDatabase.CreateAsset(material, workingDir + "Materials/" + si.sName + ".mat");
                }



                mats.Add(si.sName, material);
                matsHelpers.Add(si.sName, asi);
                ctx.AddObjectToAsset("MaterialHelper-" + asi.sName, asi);
                ctx.DependsOnSourceAsset(workingDir + "Materials/" + si.sName + ".mat");

                /* if(material!=null)
                 *  ctx.AddObjectToAsset(material.name,material); */
            }
            matsComplete++;
        }
        //EditorUtility.DisplayProgressBar(progressString,"[4/5] Creating Meshes...",(4f/5f));

        /*
         * Create Meshes
         */

        GameObject root = new GameObject(amf.modelName);

        ctx.AddObjectToAsset(amf.modelName, root);
        ctx.SetMainObject(root);
        Dictionary <long, Mesh> meshList = ConvertMeshes(amf, mats, matsHelpers, root);

        //root.transform.rotation=Quaternion.Euler(-90f,0f,0f);

        /* LoadRegions(amf,root);
         * List<Mesh> meshList=CreateMeshes(amf,root.transform,mats);
         */
        UnwrapParam.SetDefaults(out uvSettings);
        EditorUtility.DisplayProgressBar(progressString, "[5/5] Finishing up...", (5f / 5f));
        float lightCount = 0;
        float totalLight = meshList.Count;

        foreach (Mesh m in meshList.Values)
        {
            /* if(GenerateLightmapUVs){
             *  EditorUtility.DisplayProgressBar("Generating Lightmaps","["+lightCount+"/"+totalLight+"] Generating UVs...",(lightCount/totalLight));
             *  Unwrapping.GenerateSecondaryUVSet(m,uvSettings);
             *  lightCount++;
             * } */
            ctx.AddObjectToAsset(m.name, m);
        }

        Debug.Log("AMF import complete");
        EditorUtility.ClearProgressBar();
    }