Пример #1
0
        public void RecursiveSearch(GameObject root)
        {
            if (room.IgnoreInactiveObjects &&
                !root.activeInHierarchy)
            {
                return;
            }

            // loop thorugh all the gameObjects components
            // to see what we can extract
            Component[] comps = root.GetComponents <Component>();
            if (!compExtractor.CanExport(comps))
            {
                compExtractor.Process(comps);
                return;
            }

            for (int i = 0; i < comps.Length; i++)
            {
                Component comp = comps[i];
                if (!comp)
                {
                    continue;
                }

                if (comp is MeshRenderer)
                {
                    MeshRenderer meshRen = (MeshRenderer)comp;
                    MeshFilter   filter  = comps.FirstOrDefault(c => c is MeshFilter) as MeshFilter;
                    if (filter == null)
                    {
                        continue;
                    }

                    Mesh mesh = filter.sharedMesh;
                    if (mesh == null ||
                        !room.CanExportObj(comps) ||
                        mesh.GetTopology(0) != MeshTopology.Triangles)
                    {
                        continue;
                    }

                    if (!room.ExportDynamicGameObjects &&
                        !root.isStatic)
                    {
                        continue;
                    }

                    sceneBounds.Encapsulate(meshRen.bounds);

                    // Only export the mesh if we never exported this one mesh
                    BruteForceMeshExportData exp;
                    if (!meshesToExport.TryGetValue(mesh, out exp))
                    {
                        exp      = new BruteForceMeshExportData();
                        exp.Mesh = mesh;
                        // generate name
                        string meshId = mesh.name;
                        if (string.IsNullOrEmpty(meshId) ||
                            meshNames.Contains(meshId))
                        {
                            meshId = "ExportedMesh" + meshNames.Count;
                        }
                        meshNames.Add(meshId);

                        // keep our version of the data
                        exp.MeshId = meshId;
                        meshesToExport.Add(mesh, exp);

                        // but also supply the data to the Janus Room so the Html can be built
                        AssetObject asset = new AssetObject();
                        exp.Asset = asset;

                        asset.id  = meshId;
                        asset.src = meshId + ".fbx";

                        room.AddAssetObject(asset);
                    }

                    // We are brute force, so all objects become Room Objects
                    RoomObject obj = new RoomObject();
                    obj.id = exp.Asset.id;
                    obj.SetUnityObj(root, room);
                    room.AddRoomObject(obj);
                    compExtractor.ProcessNewRoomObject(obj, comps);

                    // let the material scanner process this object
                    materialScanner.PreProcessObject(meshRen, mesh, exp.Asset, obj, true);
                }
            }

            // loop through all this GameObject children
            foreach (Transform child in root.transform)
            {
                RecursiveSearch(child.gameObject);
            }
        }
Пример #2
0
        public void RecursiveSearch(GameObject root)
        {
            if (room.IgnoreInactiveObjects &&
                !root.activeInHierarchy)
            {
                return;
            }

            // loop thorugh all the gameObjects components
            // to see what we can extract
            Component[] comps = root.GetComponents <Component>();
            if (!compExtractor.CanExport(comps))
            {
                compExtractor.Process(comps);
                return;
            }

            for (int i = 0; i < comps.Length; i++)
            {
                Component comp = comps[i];
                if (!comp)
                {
                    continue;
                }

                if (comp is MeshRenderer)
                {
                    MeshRenderer meshRen = (MeshRenderer)comp;
                    MeshFilter   filter  = comps.FirstOrDefault(c => c is MeshFilter) as MeshFilter;
                    if (filter == null || !meshRen.isVisible)
                    {
                        continue;
                    }

                    Mesh mesh = filter.sharedMesh;
                    if (mesh == null ||
                        !room.CanExportObj(comps))
                    {
                        continue;
                    }

                    Material mat = meshRen.sharedMaterial;
                    if (!mat)
                    {
                        continue;
                    }

                    if (!room.ExportDynamicGameObjects &&
                        !root.isStatic)
                    {
                        continue;
                    }

                    sceneBounds.Encapsulate(meshRen.bounds);

                    PerMaterialMeshExportData data;
                    if (!meshesToExport.TryGetValue(mat, out data))
                    {
                        data = new PerMaterialMeshExportData();
                        meshesToExport.Add(mat, data);

                        AssetObject asset = new AssetObject();
                        data.Asset = asset;

                        asset.id  = mat.name;
                        asset.src = mat.name + ".fbx";
                        room.AddAssetObject(asset);

                        RoomObject obj = new RoomObject();
                        data.Object = obj;
                        obj.id      = mat.name;
                        obj.SetNoUnityObj(room);

                        room.AddRoomObject(obj);
                        compExtractor.ProcessNewRoomObject(obj, comps);
                    }

                    materialScanner.PreProcessObject(meshRen, mesh, data.Asset, data.Object, false);

                    PerMaterialMeshExportDataObj dObj = new PerMaterialMeshExportDataObj();
                    dObj.Mesh      = mesh;
                    dObj.Transform = root.transform;
                    dObj.Renderer  = meshRen;
                    data.Meshes.Add(dObj);
                }
            }

            // loop through all this GameObject children
            foreach (Transform child in root.transform)
            {
                RecursiveSearch(child.gameObject);
            }
        }