Beispiel #1
0
        static void testLoadPartsAssemblerSubdir(string pathDir)
        {
            var patternsExtension = new string[] { "*.e1p", "*.l3p", "*.l2p", "*.fsc" };

            foreach (var patternExtension in patternsExtension)
            {
                var namesFile = Directory.GetFiles(pathDir, patternExtension);
                foreach (var nameFile in namesFile)
                {
                    Console.WriteLine(@"=== Parsing " + nameFile + @"===");
                    try {
                        var            context = TotekanParse.parseE1P(nameFile);
                        DoGAE1PVisitor visitor = new DoGAE1PVisitor(pathDir);
                        visitor.Visit(context as IParseTree);
                        var listSufObjs = visitor.listSufObjs;
                    } catch (Exception ex) {
                        Console.WriteLine(@"Caught Exception: " + ex.Message);
                        Console.WriteLine(@"StackTrace: " + ex.StackTrace);
                    }
                }
            }
            var namesDir = Directory.GetDirectories(pathDir);

            foreach (var nameDir in namesDir)
            {
                testLoadPartsAssemblerSubdir(nameDir);
            }
        }
Beispiel #2
0
        static void testLoadL2P(DetectInstall detectInstall)
        {
            var            nameFile = @"c:\home\tomotaco-doga\Unity\work\data\unity3d\testdir\dogal2-sample\mecha\l2_samp\human\gal1\GAL_1HD.L2P";
            var            context  = TotekanParse.parseE1P(nameFile);
            DoGAE1PVisitor visitor  = new DoGAE1PVisitor(Path.GetDirectoryName(nameFile));

            visitor.Visit(context as IParseTree);
            var listSufObjs = visitor.listSufObjs;
            var mapAtrs     = visitor.mapAtrsPalette;
        }
Beispiel #3
0
        static void testLoadE1P()
        {
//			var nameFileE1P = @"C:\Program Files (x86)\DoGA\PLAYAnimation\data\sample\01vehicle\01aircraft\airship.E1P";
            var nameFileE1P = @"C:\home\tomotaco-doga\Unity\work\data\unity3d\testdir\playanimation-sample\01vehicle\01aircraft\airship.E1P";

//			var nameFileE1P = @"D:\Program Files (x86)\DOGACGA\PLAYAnimation\data\sample\02life\01animal\unicorn.E1P";
            var            context = TotekanParse.parseE1P(nameFileE1P);
            DoGAE1PVisitor visitor = new DoGAE1PVisitor(Path.GetDirectoryName(nameFileE1P));

            visitor.Visit(context as IParseTree);
            var listSufObjs = visitor.listSufObjs;
        }
Beispiel #4
0
        static void testLoadL3P(DetectInstall detectInstall)
        {
//			var nameFileL3P = @"D:\home\tomotaco-doga\Unity\work\data\dogal3\l3_samp\parts\ball_particle_samp.L3P";
//			var nameFileL3P = @"C:\home\tomotaco-doga\Unity\work\data\unity3d\testdir\dogal3-sample\animation\demo1data\base.l3p";
//			var nameFileL3P = @"C:\home\tomotaco-doga\Unity\work\data\texture\doga-tank.l3p";
//			var nameFileL3P = @"D:\Home\tomotaco-doga\Unity\work\data\bugreport\20141018-texture-test\texture\doga-tank.l3p";
//			var nameFileL3P = @"C:\H\VRW\背景作成\objs\back\river.l3p";
//			var nameFileL3P = @"C:\H\VRW\背景作成\objs\back\riverbridge.l3p";
            var            nameFileL3P = @"C:\H\VRW\背景作成\objs\back\tree.l3p";
            var            context     = TotekanParse.parseE1P(nameFileL3P);
            DoGAE1PVisitor visitor     = new DoGAE1PVisitor(Path.GetDirectoryName(nameFileL3P));

            visitor.Visit(context as IParseTree);
            var listSufObjs = visitor.listSufObjs;
            var mapAtrs     = visitor.mapAtrsPalette;

            var nameProduct = "DOGA-L3";
            var infoInstall = detectInstall.tableInfosInstall[nameProduct];
            var infoAtr     = new DoGAAtrInfo(nameProduct, infoInstall.pathInstalled + infoInstall.pathRelativeExe, infoInstall.profiles);

//			var atr0 = infoAtr.getAtrFromPalette("bodym", "c20", "no", "m4");
            var atr0    = infoAtr.getAtrFromPalette("grayg", "#01", "no", "m4", mapAtrs);
            var pathAtr = atr0.path;
        }
Beispiel #5
0
    public IEnumerator <bool> importPartsAsm(List <ImportTask> tasks, Vector3 scaleImport)
    {
        foreach (var task in tasks)
        {
            if (task.status != ImportTask.Status.READY)
            {
                continue;
            }

            task.status       = ImportTask.Status.IMPORTING;
            task.statusImport = ImportTask.ImportStatus.PARSE_PARTS_ASSEMBLER;
            yield return(false);

            var idProduct          = task.idsProductToSelect[task.indexIdProductSelected];
            var infoInstall        = this.detectedInstall.tableInfosInstall[idProduct];
            var pathDirParts       = infoInstall.pathInstalled + infoInstall.pathRelativeExe + infoInstall.profiles["PartsDir"] + @"\";
            var pathFileAtr        = infoInstall.pathInstalled + infoInstall.pathRelativeExe + infoInstall.profiles["AtrFile"];
            var pathDirAtr         = Path.GetDirectoryName(pathFileAtr) + @"\";
            var pathDirData        = infoInstall.pathInstalled + @"\data\";
            var pathPartsAssembler = Path.GetDirectoryName(task.nameAssetFullPath) + Path.DirectorySeparatorChar;

            var            context = TotekanParse.parseE1P(task.nameAssetFullPath);
            DoGAE1PVisitor visitor = new DoGAE1PVisitor(pathPartsAssembler);
            visitor.Visit(context as IParseTree);


            var    nameE1P       = Path.GetFileNameWithoutExtension(task.nameAssetFullPath);
            string nameE1PUnique = "";
            if (!AssetNameUtil.getNameAssetUtil("Assets", nameE1P, @".prefab", out nameE1PUnique, 1000))
            {
                Debug.Log("Failed to find alternative name for existing file/dir for \"" + nameE1P + "\".");
                task.status = ImportTask.Status.FAILED;
                yield return(true);
            }
            else
            {
                nameE1P = nameE1PUnique;
            }

            var guidFolder = AssetDatabase.CreateFolder("Assets", nameE1P);
            var pathAsset  = AssetDatabase.GUIDToAssetPath(guidFolder) + @"/";

            task.statusImport = ImportTask.ImportStatus.PARSE_SUFS;
            yield return(false);

            var pathsParts = new Dictionary <string, bool>(); // path, need to split relative dir
            pathsParts.Add("", false);                        // use absolute dir
            pathsParts.Add(pathPartsAssembler, true);
            pathsParts.Add(pathDirParts, false);
            pathsParts.Add(pathDirData, false);

            var listSufObjs     = visitor.listSufObjs;
            var mapNamesFileSuf = getMapNamesFileSuf(pathsParts, listSufObjs);
            var mapSufs         = importSufs(mapNamesFileSuf);
            var mapAtrsSufDir   = importAtrsSufDir(mapNamesFileSuf);

            task.statusImport = ImportTask.ImportStatus.CONVERT_MESH;
            yield return(false);

            var mapMeshSuf = new Dictionary <string, Dictionary <Pair <string, bool>, List <Mesh> > >();

            foreach (var pair in mapSufs)
            {
                var nameFileSuf = pair.Key;
                var listSufs    = pair.Value;
                Debug.Log("Creating mesh: nameFileSuf=" + nameFileSuf);

                var mapInfoMeshes = new Dictionary <Pair <string, bool>, List <TotekanMeshInfo> >();
                buildSufMesh(listSufs, ref mapInfoMeshes);
                var mapMeshes = new Dictionary <Pair <string, bool>, List <Mesh> >();
                foreach (var keyInfoMesh in mapInfoMeshes.Keys)
                {
                    var infosMesh = mapInfoMeshes[keyInfoMesh];
                    var meshes    = new List <Mesh>();
                    foreach (var infoMesh in infosMesh)
                    {
                        var mesh = createMesh(infoMesh);
                        meshes.Add(mesh);
                    }
                    mapMeshes.Add(keyInfoMesh, meshes);
                }
                mapMeshSuf.Add(nameFileSuf, mapMeshes);
            }

            task.statusImport = ImportTask.ImportStatus.PARSE_ATRS;
            yield return(false);

            DoGAAtrInfo infoAtr = null;
            if (idProduct != "DOGA-L1")
            {
                infoAtr = this.getInfoAtrWithLoad(idProduct);
            }

            Dictionary <string, DoGAAtr> atrsColorL1 = null;
            if (idProduct == "DOGA-L1")
            {
                atrsColorL1 = this.loadAtrsColorL1(pathDirAtr, ImportTask.enumsColorL1[task.indexColorL1]);
            }

            // Create game object
            var objectGameRoot = new GameObject(nameE1P);
            objectGameRoot.transform.rotation   = Quaternion.AngleAxis(-120.0f, new Vector3(1.0f, 1.0f, 1.0f));
            objectGameRoot.transform.localScale = new Vector3(-scaleImport.x, scaleImport.y, scaleImport.z);

            task.statusImport = ImportTask.ImportStatus.CONVERT_MATERIAL;
            yield return(false);

            var mapAtrsPalette = visitor.mapAtrsPalette;             // atrs in PartsAssembler (L3)

            // Create materials from atr
            var mapAtrs = new Dictionary <string, Material>();
            var setNamesFileImageTextureNotFound = new HashSet <string>();
            foreach (var sufobj in listSufObjs)
            {
                var nameFileSuf = sufobj.nameFileSuf;
//				Debug.Log(" sufobj.nameFileSuf: " +  sufobj.nameFileSuf + ", nameFileSuf: " + nameFileSuf);

                if (!mapMeshSuf.ContainsKey(nameFileSuf))
                {
                    Debug.LogError("Suf file: " + nameFileSuf + " not found.");
                    continue;
                }

                var namesAtrInSuf = mapMeshSuf[nameFileSuf].Keys;
                foreach (var nameAtrInSuf in namesAtrInSuf)
                {
                    var nameAtrAsset = getNameAtrAsset(sufobj.nameAtrColor, sufobj.nameTexture, sufobj.nameMaterial, nameAtrInSuf);
//					Debug.Log("nameAtrAsset=" + nameAtrAsset);
                    if (mapAtrs.ContainsKey(nameAtrAsset))
                    {
                        continue;
                    }

                    DoGAAtr atr = null;
                    // retrieve atr from atr placed atr the suf dir..
                    var nameFileAtr = Path.GetFileNameWithoutExtension(mapNamesFileSuf[nameFileSuf]) + @".atr";
                    if (atr == null)
                    {
                        if (mapAtrsSufDir.ContainsKey(nameFileAtr))
                        {
                            var mapAtrSuf = mapAtrsSufDir[nameFileAtr];
                            if (mapAtrSuf.ContainsKey(nameAtrInSuf.First))
                            {
                                atr = mapAtrSuf[nameAtrInSuf.First];
                            }
                        }
                    }
                    // retrieve atr from global palette
                    if (atr == null)
                    {
                        if (infoAtr != null)
                        {
                            try {
                                atr = infoAtr.getAtrFromPalette(nameAtrInSuf.First, sufobj.nameAtrColor, sufobj.nameTexture, sufobj.nameMaterial, mapAtrsPalette);
                            } catch (KeyNotFoundException ex) {
                                Debug.Log("Cannot found atr palette: " +
                                          "Caught exception: " + ex.Message + ", " +
                                          "nameAtrInSuf=" + nameAtrInSuf.First + ", " +
                                          "nameAtrColor=" + sufobj.nameAtrColor + ", " +
                                          "nameAtrTexture=" + sufobj.nameTexture + ", " +
                                          "nameAtrMaterial=" + sufobj.nameMaterial);
                            }
                        }
                        if (atrsColorL1 != null)
                        {
                            if (atrsColorL1.ContainsKey(nameAtrInSuf.First))
                            {
                                atr = atrsColorL1[nameAtrInSuf.First];
                            }
                        }
                    }

                    if (atr != null)
                    {
                        Material material = null;
                        var      textures = new Dictionary <string, Texture2D>();
                        try {
                            if (nameAtrInSuf.Second)
                            {
                                foreach (var nameKey in atr.textures.Keys)
                                {
                                    if (nameKey != "colormap")
                                    {
                                        continue;
                                    }
                                    var namesFileTexture     = getNamesFileTexture(atr.textures[nameKey]);
                                    var namesFileTextureFull = getPathTexture(namesFileTexture, atr.pathsTexture);
                                    var nameKeyTexture       = String.Join(@"_", namesFileTextureFull.ToArray());

                                    Texture2D texture = null;
                                    if (!this.tableTextures.ContainsKey(nameKeyTexture))
                                    {
                                        texture = TextureUtil.loadAndBlendTextures(namesFileTextureFull);
                                        if (texture != null)
                                        {
                                            this.tableTextures.Add(nameKeyTexture, texture);

                                            var nameFileTextureAsset = getNameFilesTextureAsset(namesFileTexture);
                                            AssetDatabase.CreateAsset(texture, pathAsset + nameFileTextureAsset + "_texture.asset");
                                        }
                                        else
                                        {
                                            foreach (var nameFileTextureFull in namesFileTextureFull)
                                            {
                                                if (setNamesFileImageTextureNotFound.Contains(nameFileTextureFull))
                                                {
                                                    continue;
                                                }
                                                Debug.Log("Could not find texture image: " + nameFileTextureFull);
                                                setNamesFileImageTextureNotFound.Add(nameFileTextureFull);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        texture = this.tableTextures[nameKeyTexture];
                                    }
                                    if (texture != null)
                                    {
                                        textures.Add(nameKey, texture);
                                    }
                                }
                            }
                        } catch (Exception ex) {
                            Debug.Log("Caught exception for creating textures: " +
                                      ex.Message + ", " +
                                      "nameAtrInSuf=" + nameAtrInSuf.First + ", " +
                                      "nameAtrColor=" + sufobj.nameAtrColor + ", " +
                                      "nameAtrTexture=" + sufobj.nameTexture + ", " +
                                      "nameAtrMaterial=" + sufobj.nameMaterial);
                        }
                        try {
                            // if atr contains transparent texture, material is also transparent.
                            bool isMaterialTransparent = false;
                            foreach (var texture in textures.Values)
                            {
                                if (texture.alphaIsTransparency)
                                {
                                    isMaterialTransparent = true;
                                }
                            }
                            var color = atr.getColor("col");
                            if (color != null)
                            {
                                material       = new Material(Shader.Find(isMaterialTransparent ? "Transparent/Diffuse" : "Diffuse"));
                                material.color = new Color(color.r, color.g, color.b);

                                // Set texture to materal.
                                foreach (var pairTexture in textures)
                                {
                                    if (pairTexture.Key == "colormap")
                                    {
                                        material.mainTexture       = pairTexture.Value;
                                        material.mainTextureOffset = Vector2.zero;
                                        material.mainTextureScale  = new Vector2(1.0f, -1.0f);
                                    }
                                    if (pairTexture.Key == "bumpmap")
                                    {
                                        //set bump texture to material
                                    }
                                }
                            }
                        } catch (Exception ex) {
                            Debug.Log("Caught exception in attaching texture to material: " +
                                      ex.Message + ", " +
                                      "nameAtrInSuf=" + nameAtrInSuf.First + ", " +
                                      "nameAtrColor=" + sufobj.nameAtrColor + ", " +
                                      "nameAtrTexture=" + sufobj.nameTexture + ", " +
                                      "nameAtrMaterial=" + sufobj.nameMaterial);
                        }
                        if (material != null)
                        {
                            AssetDatabase.CreateAsset(material, pathAsset + nameAtrAsset + "_material.asset");
                            mapAtrs.Add(nameAtrAsset, material);
                        }
                    }
                }
            }

            task.statusImport = ImportTask.ImportStatus.BUILD_GAME_OBJECT;
            yield return(false);

            var mapCombines = new Dictionary <string, List <CombineInstance> >();          // atr name to combine instances
            foreach (var nameAtr in mapAtrs.Keys)
            {
                mapCombines.Add(nameAtr, new List <CombineInstance>());
            }

            int indexSufObj = 0;
            foreach (var sufobj in listSufObjs)
            {
                Vector3    pos;
                Quaternion quat;
                Vector3    scal;
                getMatrixTransform(sufobj.listTransforms, out pos, out quat, out scal);
                var nameFileSuf = sufobj.nameFileSuf;
                Debug.Log("Creating CombineInstance for suf file: " + nameFileSuf);
                if (!mapMeshSuf.ContainsKey(nameFileSuf))
                {
                    Debug.LogError("Combining: Not found suf=" + nameFileSuf + ", skipped.");
                    continue;
                }

                var transformLocal = new Matrix4x4();
                transformLocal.SetTRS(pos, quat, scal);
                var transformWorld = objectGameRoot.transform.localToWorldMatrix * transformLocal;

                var mapInfosMesh = mapMeshSuf[nameFileSuf];
                foreach (var pairAtr in mapInfosMesh.Keys)
                {
                    var nameAtrAsset = getNameAtrAsset(sufobj.nameAtrColor, sufobj.nameTexture, sufobj.nameMaterial, pairAtr);
//					Debug.Log("Creating CombineInstance: nameAtr=" + pairAtr.First + "uv=" + (pairAtr.Second ? "true" : "false") + ", nameAtrAsset=" + nameAtrAsset);
                    if (!mapAtrs.ContainsKey(nameAtrAsset))
                    {
                        Debug.LogError("nameAtrAsset=" + nameAtrAsset + " does not exist in mapAtrs. Skipping...");
                        continue;
                    }

                    var meshes = mapInfosMesh[pairAtr];
                    foreach (var mesh in meshes)
                    {
                        for (int index = 0; index < mesh.subMeshCount; index++)
                        {
                            var combine = new CombineInstance();
                            combine.mesh         = mesh;
                            combine.subMeshIndex = index;
                            combine.transform    = transformWorld;
                            mapCombines[nameAtrAsset].Add(combine);
                        }
                    }
                }
                indexSufObj++;
            }

            int indexMaterial = 0;
            foreach (var pairCombine in mapCombines)
            {
                if (pairCombine.Value.Count == 0)
                {
                    continue;
                }
                var nameAtrAsset = pairCombine.Key;
//				Debug.Log("atrName=" + nameAtrAsset + ", combines =" + pairCombine.Value.Count.ToString());
                int indexCombine = 0;
                int numVertices  = 0;
                var combines     = new List <CombineInstance>();
                foreach (var combine in pairCombine.Value)
                {
                    if (maxVerticesMesh < numVertices + combine.mesh.vertexCount)
                    {
                        createAssetCombinedMesh(combines, pathAsset, nameAtrAsset, indexMaterial, indexCombine, mapAtrs[nameAtrAsset], objectGameRoot);
                        combines    = new List <CombineInstance>();
                        numVertices = 0;
                        indexCombine++;
                    }
                    combines.Add(combine);
                    numVertices += combine.mesh.vertexCount;
                }
                if (0 < combines.Count)
                {
                    createAssetCombinedMesh(combines, pathAsset, nameAtrAsset, indexMaterial, indexCombine, mapAtrs[nameAtrAsset], objectGameRoot);
                }
                indexMaterial++;
            }

            AssetDatabase.DeleteAsset(task.nameAssetFullPath);
            AssetDatabase.SaveAssets();
            Debug.Log("Saved all assets");

            var pathPrefab       = "Assets/" + nameE1P + ".prefab";
            var pathPrefabUnique = AssetDatabase.GenerateUniqueAssetPath(pathPrefab);
            PrefabUtility.CreatePrefab(pathPrefabUnique, objectGameRoot, ReplacePrefabOptions.ConnectToPrefab);

            task.statusImport = ImportTask.ImportStatus.COMPLETED;
            task.status       = ImportTask.Status.COMPLETED;
            yield return(false);
        }

        this.tableInfosAtr.Clear();
        this.tableTextures.Clear();

        yield return(true);
    }