Ejemplo n.º 1
0
        public void Export(SceneFormat fmt)
        {
            // 유니티 씬을 제대로 읽었는지 확인
            bool useDump = false;

            if (useDump)
            {
                DumpUnitySceneRoot(unitySceneRoot);
            }

            // 유니티씬을 threejs 씬으로 변환
            ThreeSceneRoot threeSceneRoot = BuildThreeSceneRoot(unitySceneRoot);

            WriteTextureFiles(threeSceneRoot, fmt);
            WriteModelFiles(threeSceneRoot, fmt);


            switch (fmt)
            {
            case SceneFormat.AFrame:
                WriteToAFrame(threeSceneRoot);
                break;

            case SceneFormat.ThreeJS:
                WriteToThreeJS(threeSceneRoot);
                break;

            default:
                Debug.Assert(false, "unknown format");
                break;
            }
        }
Ejemplo n.º 2
0
        void WriteModelFiles(ThreeSceneRoot root, SceneFormat fmt)
        {
            // three.js는 단일 파일로 출력하는게 목적이라서 model 파일을 생성하지 않는다
            var pathHelper = ExportPathHelper.Instance;

            if (fmt == SceneFormat.AFrame)
            {
                foreach (var el in root.SharedNodeTable.GetEnumerable <MeshElem>())
                {
                    var bufferGeom = el.Geometry as BufferGeometryElem;
                    if (bufferGeom != null)
                    {
                        string filepath = pathHelper.ToModelPath(bufferGeom.CreateMeshFileName(".obj"));
                        ObjExporter.MeshToFile(bufferGeom.Mesh, filepath);
                    }

                    var mtl = MaterialFacade.Instance.CreateMaterial(el.Material);
                    if (bufferGeom != null)
                    {
                        string filepath = pathHelper.ToModelPath(bufferGeom.CreateMeshFileName(".mtl"));
                        MtlExporter.ToFile(mtl, bufferGeom.SafeName, filepath);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void WriteTextureFiles(ThreeSceneRoot root, SceneFormat fmt)
        {
            var pathHelper = ExportPathHelper.Instance;

            // 일반 텍스쳐 export
            foreach (var el in root.SharedNodeTable.GetEnumerable <ImageElem>())
            {
                el.ExpoortImageFile(pathHelper);
            }
        }
Ejemplo n.º 4
0
        void WriteMaterialFiles(ThreeSceneRoot root, SceneFormat fmt)
        {
            var pathHelper = ExportPathHelper.Instance;

            if (fmt == SceneFormat.AFrame)
            {
                foreach (var el in root.SharedNodeTable.GetEnumerable <MaterialElem>())
                {
                    var    aframeMtl = MaterialFacade.Instance.CreateMaterial(el);
                    var    name      = el.Name;
                    string filepath  = pathHelper.ToModelPath(name + ".mtl");
                    MtlExporter.ToFile(aframeMtl, name, filepath);
                }
            }
        }
Ejemplo n.º 5
0
        void WriteModelFiles(ThreeSceneRoot root, SceneFormat fmt)
        {
            // three.js는 단일 파일로 출력하는게 목적이라서 model 파일을 생성하지 않는다
            var pathHelper = ExportPathHelper.Instance;

            if (fmt == SceneFormat.AFrame)
            {
                foreach (var el in root.SharedNodeTable.GetEnumerable <AbstractGeometryElem>())
                {
                    // TODO 타입에 따라서 obj 굽는게 바뀔텐데
                    var bufferGeom = el as BufferGeometryElem;
                    if (bufferGeom == null)
                    {
                        continue;
                    }

                    string filepath = pathHelper.ToModelPath(bufferGeom.CreateMeshFileName(".obj"));
                    ObjExporter.MeshToFile(bufferGeom.Mesh, filepath);
                }
            }
        }
Ejemplo n.º 6
0
        protected void ExportCommon(string extension, SceneFormat fmt)
        {
            string targetFilePath = EditorUtility.SaveFilePanel("Save scene", lastExportPath, "", extension);

            if (targetFilePath == "")
            {
                // cancel 버튼 처리
                return;
            }

            var pathHelper = ExportPathHelper.Instance;

            pathHelper.UpdateTargetFilePath(targetFilePath);

            lastExportPath = pathHelper.RootPath;

            // 설정값을 전역변수로 연결
            // 그래야 밖에서 조회하기 쉽다
            ExportSettings.Instance             = settings;
            ExportSettings.Instance.destination = new DestinationSettings()
            {
                extension = extension,
                format    = fmt,
                rootPath  = pathHelper.RootPath,
            };
            Report.Instance.Level      = settings.log.level;
            Report.Instance.UseConsole = settings.log.useConsole;

            Debug.LogFormat("Platform: {0}", SystemInfo.operatingSystem);
            Debug.LogFormat("Unity player: {0}", Application.unityVersion);

            var gameObjects = GameObjectHelper.GetExportGameObjects();
            var exporter    = new SceneExporter(gameObjects);

            exporter.Export(fmt);

            Debug.LogFormat("Export to {0} finish.", fmt);
        }