Beispiel #1
0
 public void BakeLevel(int amountCalls)
 {
     foreach (var part in _bakedObjectsList)
     {
         GameObject bakedObject = new GameObject();
         MeshBaker.BakeMeshes(part.Value.ToArray(), bakedObject, amountCalls);
         bakedObject.name             = part.Key;
         bakedObject.transform.parent = _level.transform;
         bakedObject.AddComponent <MeshCollider>();
     }
 }
Beispiel #2
0
    // Handles creation of celestial body when entering game mode
    // This differs from the edit-mode version in the following ways:
    // • creates all LOD meshes and stores them in mesh array (to be picked based on player position)
    // • creates its own instances of materials so multiple bodies can exist with their own shading
    // • doesn't support updating of shape/shading values once generated
    void HandleGameModeGeneration()
    {
        if (CanGenerateMesh())
        {
            Dummy();

            // Generate LOD meshes
            lodMeshes = new Mesh[ResolutionSettings.numLODLevels];
            for (int i = 0; i < lodMeshes.Length; i++)
            {
                Vector2 lodTerrainHeightMinMax = GenerateTerrainMesh(ref lodMeshes[i], resolutionSettings.GetLODResolution(i));
                // Use min/max height of first (most detailed) LOD
                if (i == 0)
                {
                    heightMinMax = lodTerrainHeightMinMax;
                }
            }

            // Generate collision mesh
            GenerateCollisionMesh(resolutionSettings.collider);

            // Create terrain renderer and set shading properties on the instanced material
            terrainMatInstance = new Material(body.shading.terrainMaterial);
            body.shading.Initialize(body.shape);
            body.shading.SetTerrainProperties(terrainMatInstance, heightMinMax, BodyScale);
            GameObject terrainHolder = GetOrCreateMeshObject("Terrain Mesh", null, terrainMatInstance);
            terrainMeshFilter = terrainHolder.GetComponent <MeshFilter> ();

            // Add collider
            MeshCollider collider;
            if (!terrainHolder.TryGetComponent <MeshCollider> (out collider))
            {
                collider = terrainHolder.AddComponent <MeshCollider> ();
            }

            var collisionBakeTimer = System.Diagnostics.Stopwatch.StartNew();
            MeshBaker.BakeMeshImmediate(collisionMesh);
            collider.sharedMesh = collisionMesh;
            LogTimer(collisionBakeTimer, "Mesh collider");
        }
        else
        {
            Debug.Log("Could not generate mesh");
        }

        ReleaseAllBuffers();
    }