public Dictionary <int, Tuple <List <DefaultVertex>, List <uint> > > PrecalculateGeometryTriangulation() { Dictionary <int, Tuple <List <DefaultVertex>, List <uint> > > result = new Dictionary <int, Tuple <List <DefaultVertex>, List <uint> > >(); for (int i = 0; i < geometry.Count; ++i) { LevelGeometry thisGeom = geometry[i]; List <DefaultVertex> outVertices; List <uint> outIndices; thisGeom.GetVertexData(out outVertices, out outIndices); if (this is GameLevelDescription) { var singleMatchingEntity = levelGeometryEntities.FindSingleOrDefault(lge => lge.Geometry == thisGeom); if (singleMatchingEntity != null) { outVertices = outVertices.Select(v => new DefaultVertex( v.Position, v.Normal, v.Tangent, v.TexUV + singleMatchingEntity.TexPan )).ToList(); } } result.Add(thisGeom.ID, Tuple.Create(outVertices, outIndices)); } return(result); }
public void RecreateGeometry(bool forceInvalidation = false) { lock (instanceMutationLock) { if (!cacheInvalid && !forceInvalidation) { return; } } using (RenderingModule.RenderStateBarrier.AcquirePermit(withLock: instanceMutationLock)) { currentGeometryEntities.Values.ForEach(e => e.Dispose()); currentGeometryEntities.Clear(); if (currentCache != null) { AssetLocator.MainGeometryPass.SetVSForCache(currentCache, null); currentCache.Dispose(); } if (currentSkydomeCache != null) { AssetLocator.MainGeometryPass.SetVSForCache(currentSkydomeCache, null); currentSkydomeCache.Dispose(); } currentModelHandles.Clear(); cachedDefaultModelHandles.Clear(); if (geometry.Count == 0) { return; } LevelGeometry skydome = null; GeometryCacheBuilder <DefaultVertex> gcb = new GeometryCacheBuilder <DefaultVertex>(); if (this is GameLevelDescription) { gcb.OrderFirst = true; } for (int i = 0; i < geometry.Count; ++i) { LevelGeometry thisGeom = geometry[i]; if (thisGeom.IsSkydome) { skydome = thisGeom; continue; } List <DefaultVertex> outVertices; List <uint> outIndices; if (precalculatedTriangles.ContainsKey(thisGeom.ID)) { outVertices = precalculatedTriangles[thisGeom.ID].Item1; outIndices = precalculatedTriangles[thisGeom.ID].Item2; } else { thisGeom.GetVertexData(out outVertices, out outIndices); if (this is GameLevelDescription) { var singleMatchingEntity = levelGeometryEntities.FindSingleOrDefault(lge => lge.Geometry == thisGeom); if (singleMatchingEntity != null) { outVertices = outVertices.Select(v => new DefaultVertex( v.Position, v.Normal, v.Tangent, v.TexUV + singleMatchingEntity.TexPan )).ToList(); } } } if (thisGeom is LevelGeometry_Model && thisGeom.Transform == Transform.DEFAULT_TRANSFORM) { string filename = ((LevelGeometry_Model)thisGeom).ModelFileName; if (cachedDefaultModelHandles.ContainsKey(filename)) { currentModelHandles.Add(thisGeom, cachedDefaultModelHandles[filename]); } else { var newHandle = gcb.AddModel(Title + "_Geometry_" + i + "_[" + thisGeom + "]", outVertices, outIndices); currentModelHandles.Add(thisGeom, newHandle); cachedDefaultModelHandles.Add(filename, newHandle); } } else { currentModelHandles.Add(thisGeom, gcb.AddModel(Title + "_Geometry_" + i + "_[" + thisGeom + "]", outVertices, outIndices)); } } currentCache = gcb.Build(); currentSkydomeCache = null; if (skydome != null) { gcb = new GeometryCacheBuilder <DefaultVertex>(); List <DefaultVertex> outVertices; List <uint> outIndices; if (precalculatedTriangles.ContainsKey(skydome.ID)) { outVertices = precalculatedTriangles[skydome.ID].Item1; outIndices = precalculatedTriangles[skydome.ID].Item2; } else { skydome.GetVertexData(out outVertices, out outIndices); if (this is GameLevelDescription) { var singleMatchingEntity = levelGeometryEntities.FindSingleOrDefault(lge => lge.Geometry == skydome); if (singleMatchingEntity != null) { outVertices = outVertices.Select(v => new DefaultVertex( v.Position, v.Normal, v.Tangent, v.TexUV + singleMatchingEntity.TexPan )).ToList(); } } } if (skydome is LevelGeometry_Model && skydome.Transform == Transform.DEFAULT_TRANSFORM) { string filename = ((LevelGeometry_Model)skydome).ModelFileName; if (cachedDefaultModelHandles.ContainsKey(filename)) { currentModelHandles.Add(skydome, cachedDefaultModelHandles[filename]); } else { var newHandle = gcb.AddModel(Title + "_Skydome_" + skydome + "_[" + skydome + "]", outVertices, outIndices); currentModelHandles.Add(skydome, newHandle); cachedDefaultModelHandles.Add(filename, newHandle); } } else { currentModelHandles.Add(skydome, gcb.AddModel(Title + "_Geometry_" + "_[" + skydome + "]", outVertices, outIndices)); } currentSkydomeCache = gcb.Build(); } cacheInvalid = false; AssetLocator.MainGeometryPass.SetVSForCache(currentCache, GetRecommendedVertexShader()); if (currentSkydomeCache != null) { AssetLocator.MainGeometryPass.SetVSForCache(currentSkydomeCache, GetRecommendedVertexShader()); } } }