public RenderModel3D CreateRenderModel(int id, int lod) { try { if (geometryCache.ContainsKey(id)) { return(geometryCache[id].BuildElement(lod)); } } catch { } return(RenderModel3D.Error(id.ToString())); }
public RenderModel3D CreateModelSection(int id, int lod, int meshIndex, int meshCount, float scale, Matrix4x4 transform) { try { if (geometryCache.ContainsKey(id)) { var geom = geometryCache[id]; return(geom.BuildSection(lod, meshIndex, meshCount, scale, transform)); } } catch { } return(RenderModel3D.Error(id.ToString())); }
//builds a single permutation and ignores instancing public RenderModel3D BuildSection(int lod, int meshIndex, int meshCount, float scale, Matrix4x4 transform) { var model = LodProperties[lod]; var elements = new List <Helix.GroupElement3D>(); for (int i = meshIndex; i < meshIndex + meshCount; i++) { var template = templates[lod][i]; if (template.IsEmpty) { continue; } elements.Add(template.GenerateModelNoInstance((mesh, matIndex) => { if (matIndex < 0 || matIndex >= model.Materials.Count) { mesh.IsTransparent = false; mesh.Material = ErrorMaterial; } bool isTransparent; var mat = factory.CreateMaterial(model.Materials[matIndex], out isTransparent); mesh.IsTransparent = isTransparent; mesh.Material = mat; })); } Helix.GroupElement3D permutationRoot; if (elements.Count == 1) { permutationRoot = elements[0]; } else { permutationRoot = new Helix.GroupModel3D(); foreach (var e in elements) { permutationRoot.Children.Add(e); } } permutationRoot.Transform = GetTransform(scale, transform); return(RenderModel3D.FromElement(permutationRoot)); }