Esempio n. 1
0
    public static void Build(DynamicMeshGenericMultiMaterialMesh _mesh, BuildrData _data)
    {
        switch (_data.generateCollider)
        {
        case BuildrData.ColliderGenerationModes.None:
            return;

//                break;

        case BuildrData.ColliderGenerationModes.Simple:
            BuildSimple(_mesh, _data);
            break;

        case BuildrData.ColliderGenerationModes.Complex:
            BuildrBuilding.Build(_mesh, _data);
            BuildrRoof.Build(_mesh, _data);
            int numberOfVolumes = _data.plan.numberOfVolumes;
            for (int v = 0; v < numberOfVolumes; v++)
            {
                BuildrInteriors.Build(_mesh, _data, v);
                BuildrStairs.Build(_mesh, _data, v, BuildrStairs.StairModes.Flat, false);
            }
            _mesh.CollapseSubmeshes();
            break;
        }
    }
Esempio n. 2
0
    private static int[] ExportInteriors(BuildrData data)
    {
        int numberOfVolumes = data.plan.numberOfVolumes;

        int[] returnNumberOfMeshes = new int[numberOfVolumes];

        for (int v = 0; v < numberOfVolumes; v++)
        {
            DynamicMeshGenericMultiMaterialMesh INT_MESH = new DynamicMeshGenericMultiMaterialMesh();
            INT_MESH.subMeshCount = data.textures.Count;
            BuildrInteriors.Build(INT_MESH, data, v);

            INT_MESH.Build(data.includeTangents);

            List <int>            unusedTextures           = INT_MESH.unusedSubmeshes;
            int                   numberOfUnpackedTextures = data.textures.Count;
            List <ExportMaterial> exportTextures           = new List <ExportMaterial>();
            for (int t = 0; t < numberOfUnpackedTextures; t++)
            {
                if (unusedTextures.Contains(t))
                {
                    continue;//skip, unused
                }
                ExportMaterial newTexture = new ExportMaterial();
                newTexture.name      = data.textures[t].name;
                newTexture.material  = data.textures[t].material;
                newTexture.generated = false;
                newTexture.filepath  = data.textures[t].filePath;
                exportTextures.Add(newTexture);
            }

            int numberOfMeshes = INT_MESH.meshCount;
            for (int i = 0; i < numberOfMeshes; i++)
            {
                MeshUtility.Optimize(INT_MESH[i].mesh);
                string VolumeSuffix      = ((numberOfVolumes > 1) ? "_" + v : "");
                string DetailSuffixIndex = ((numberOfMeshes > 1) ? "_" + i : "");
                string DetailFileName    = data.exportFilename + INTERIOR_SUFFIX + VolumeSuffix + DetailSuffixIndex;
                string DetailFolder      = ROOT_FOLDER + data.exportFilename + "/";
                Export(DetailFileName, DetailFolder, data, INT_MESH[i].mesh, exportTextures.ToArray());
            }

            returnNumberOfMeshes[v] = numberOfMeshes;
        }

        return(returnNumberOfMeshes);
    }
Esempio n. 3
0
    public void UpdateInteriors()
    {
        while (interiorMeshHolders.Count > 0)
        {
            GameObject destroyOld = interiorMeshHolders[0];
            interiorMeshHolders.RemoveAt(0);
            DestroyImmediate(destroyOld);
        }

        interiorMeshes.Clear();

        if (data.renderInteriors)
        {
            int numberOfVolumes = data.plan.numberOfVolumes;
            for (int v = 0; v < numberOfVolumes; v++)
            {
                DynamicMeshGenericMultiMaterialMesh interiorMesh = new DynamicMeshGenericMultiMaterialMesh();
                interiorMesh.subMeshCount = data.textures.Count;
                BuildrInteriors.Build(interiorMesh, data, v);
                interiorMesh.Build(false);

                int numberOfInteriorMeshes = interiorMesh.meshCount;
                for (int i = 0; i < numberOfInteriorMeshes; i++)
                {
                    string meshName = "model interior";
                    if (numberOfVolumes > 0)
                    {
                        meshName += " volume " + (v + 1);
                    }
                    if (numberOfInteriorMeshes > 1)
                    {
                        meshName += " mesh " + (i + 1);
                    }
                    GameObject newMeshHolder = new GameObject(meshName);
                    newMeshHolder.transform.parent        = transform;
                    newMeshHolder.transform.localPosition = Vector3.zero;
                    meshFilt      = newMeshHolder.AddComponent <MeshFilter>();
                    meshRend      = newMeshHolder.AddComponent <MeshRenderer>();
                    meshFilt.mesh = interiorMesh[i].mesh;
                    interiorMeshHolders.Add(newMeshHolder);
                }
            }
        }
    }
Esempio n. 4
0
    public void UpdateInteriors()
    {
        while (interiorMeshHolders.Count > 0)
        {
            GameObject destroyOld = interiorMeshHolders[0];
            interiorMeshHolders.RemoveAt(0);
            DestroyImmediate(destroyOld);
        }

        interiorMeshes.Clear();

        if (data.renderInteriors)
        {
            int numberOfVolumes = data.plan.numberOfVolumes;
            for (int v = 0; v < numberOfVolumes; v++)
            {
                DynamicMeshGenericMultiMaterialMesh interiorMesh = new DynamicMeshGenericMultiMaterialMesh();
                interiorMesh.subMeshCount = data.textures.Count;
                BuildrVolume volume = _data.plan.volumes[v];
                BuildrInteriors.Build(interiorMesh, data, v);
                interiorMesh.Build(false);

                List <int>      unusedInteriorTextures    = interiorMesh.unusedSubmeshes;
                int             numberOfInteriorMaterials = data.textures.Count;
                List <Material> interiorMaterials         = new List <Material>();
                for (int m = 0; m < numberOfInteriorMaterials; m++)
                {
                    if (unusedInteriorTextures.Contains(m))
                    {
                        continue;//skip, unused
                    }
                    BuildrTexture bTexture = data.textures[m];
                    interiorMaterials.Add(bTexture.usedMaterial);
                }

                int numberOfInteriorMeshes = interiorMesh.meshCount;
                for (int i = 0; i < numberOfInteriorMeshes; i++)
                {
                    string meshName = "model interior";
                    if (numberOfVolumes > 0)
                    {
                        meshName += " volume " + (v + 1);
                    }
                    if (numberOfInteriorMeshes > 1)
                    {
                        meshName += " mesh " + (i + 1);
                    }
                    GameObject newMeshHolder = new GameObject(meshName);
                    newMeshHolder.transform.parent        = transform;
                    newMeshHolder.transform.localPosition = Vector3.zero;
                    meshFilt      = newMeshHolder.AddComponent <MeshFilter>();
                    meshRend      = newMeshHolder.AddComponent <MeshRenderer>();
                    meshFilt.mesh = interiorMesh[i].mesh;
                    interiorMeshHolders.Add(newMeshHolder);

                    int numberOfInterior = interiorMeshHolders.Count;
                    for (int m = 0; m < numberOfInterior; m++)
                    {
                        meshRend.sharedMaterials = interiorMaterials.ToArray();
                    }
                }
                interiorMeshes.Add(interiorMesh);

                if (!volume.generateStairs)
                {
                    continue;
                }

                DynamicMeshGenericMultiMaterialMesh stairwellMesh = new DynamicMeshGenericMultiMaterialMesh();
                stairwellMesh.subMeshCount = data.textures.Count;
                BuildrStairs.Build(stairwellMesh, data, v, BuildrStairs.StairModes.Stepped, true);
                stairwellMesh.Build(false);


                List <int>      unusedStairTextures    = stairwellMesh.unusedSubmeshes;
                int             numberOfStairMaterials = data.textures.Count;
                List <Material> stairMaterials         = new List <Material>();
                for (int m = 0; m < numberOfStairMaterials; m++)
                {
                    if (unusedStairTextures.Contains(m))
                    {
                        continue;//skip, unused
                    }
                    BuildrTexture bTexture = data.textures[m];
                    stairMaterials.Add(bTexture.usedMaterial);
                }

                int numberOfStairMeshes = stairwellMesh.meshCount;
                for (int i = 0; i < numberOfStairMeshes; i++)
                {
                    string meshName = "model stairs";
                    if (numberOfVolumes > 0)
                    {
                        meshName += " volume " + (v + 1);
                    }
                    if (numberOfStairMeshes > 1)
                    {
                        meshName += " mesh " + (i + 1);
                    }
                    GameObject newMeshHolder = new GameObject(meshName);
                    newMeshHolder.transform.parent        = transform;
                    newMeshHolder.transform.localPosition = volume.stairBaseVector[i];
                    meshFilt      = newMeshHolder.AddComponent <MeshFilter>();
                    meshRend      = newMeshHolder.AddComponent <MeshRenderer>();
                    meshFilt.mesh = stairwellMesh[i].mesh;
                    interiorMeshHolders.Add(newMeshHolder);
                    meshRend.sharedMaterials = stairMaterials.ToArray();
                }
                interiorMeshes.Add(stairwellMesh);
            }
        }
    }