Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Assets/Scripts/Terrain/TerrainNature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using DaggerfallConnect.Arena2;
using DaggerfallConnect;
using DaggerfallWorkshop.Utility.AssetInjection;
using System.Collections.Generic;

namespace DaggerfallWorkshop
{
Expand Down Expand Up @@ -109,6 +110,7 @@ public virtual void LayoutNature(DaggerfallTerrain dfTerrain, DaggerfallBillboar
float maxTerrainHeight = DaggerfallUnity.Instance.TerrainSampler.MaxTerrainHeight;
float beachLine = DaggerfallUnity.Instance.TerrainSampler.BeachElevation;

List<DaggerfallBillboardBatch.BasicInfo> basicItems = new List<DaggerfallBillboardBatch.BasicInfo>(tDim * tDim);
for (int y = 0; y < tDim; y++)
{
for (int x = 0; x < tDim; x++)
Expand Down Expand Up @@ -162,15 +164,24 @@ public virtual void LayoutNature(DaggerfallTerrain dfTerrain, DaggerfallBillboar
// Add to batch unless a mesh replacement is found
int record = Random.Range(1, 32);
if (terrainDist > 1 || !MeshReplacement.ImportNatureGameObject(dfBillboardBatch.TextureArchive, record, terrain, x, y))
dfBillboardBatch.AddItem(record, pos);
{
basicItems.Add(new DaggerfallBillboardBatch.BasicInfo
{
textureRecord = record,
localPosition = new Unity.Mathematics.float3(pos.x, pos.y, pos.z)
});
}
else if (!NatureMeshUsed)
NatureMeshUsed = true; // Signal that nature mesh has been used to initiate extra terrain updates
}
}

if (basicItems.Count > 0)
{
dfBillboardBatch.AddItemsAsync(basicItems.ToArray()).Complete();
}
// Apply new batch
dfBillboardBatch.Apply();
}
}

}
}
22 changes: 20 additions & 2 deletions Assets/Scripts/Utility/RMBLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public static void AddNatureFlats(
if (!dfUnity.IsReady)
return;

List<DaggerfallBillboardBatch.BasicInfo> basicItems = new List<DaggerfallBillboardBatch.BasicInfo>();
for (int y = 0; y < 16; y++)
{
for (int x = 0; x < 16; x++)
Expand All @@ -256,7 +257,11 @@ public static void AddNatureFlats(
// Add billboard to batch or standalone
if (billboardBatch != null)
{
billboardBatch.AddItem(scenery.TextureRecord, billboardPosition);
basicItems.Add(new DaggerfallBillboardBatch.BasicInfo
{
textureRecord = scenery.TextureRecord,
localPosition = new Unity.Mathematics.float3(billboardPosition.x, billboardPosition.y, billboardPosition.z)
});
}
else
{
Expand All @@ -266,6 +271,10 @@ public static void AddNatureFlats(
}
}
}
if (billboardBatch != null && basicItems.Count > 0)
{
billboardBatch.AddItemsAsync(basicItems.ToArray()).Complete();
}
}

/// <summary>
Expand All @@ -285,6 +294,7 @@ public static void AddLights(
if (!dfUnity.Option_ImportLightPrefabs || dfUnity.Option_CityLightPrefab == null)
return;

List<DaggerfallBillboardBatch.BasicInfo> basicItems = new List<DaggerfallBillboardBatch.BasicInfo>();
// Iterate block flats for lights
foreach (DFBlock.RmbBlockFlatObjectRecord obj in blockData.RmbBlock.MiscFlatObjectRecords)
{
Expand All @@ -304,7 +314,11 @@ public static void AddLights(
// Add billboard to batch or standalone
if (billboardBatch != null)
{
billboardBatch.AddItem(obj.TextureRecord, billboardPosition);
basicItems.Add(new DaggerfallBillboardBatch.BasicInfo
{
textureRecord = obj.TextureRecord,
localPosition = new Unity.Mathematics.float3(billboardPosition.x, billboardPosition.y, billboardPosition.z)
});
}
else
{
Expand All @@ -317,6 +331,10 @@ public static void AddLights(
AddLight(dfUnity, obj, lightsParent);
}
}
if (billboardBatch != null && basicItems.Count > 0)
{
billboardBatch.AddItemsAsync(basicItems.ToArray()).Complete();
}
}

/// <summary>
Expand Down