internal void Merge(MyActor child) { var r = child.GetRenderable(); var model = r.GetModel(); var material = MyMeshes.GetMeshPart(model, 0, 0).Info.Material; bool fracture = model.Info.RuntimeGenerated || model.Info.Dynamic; if (MyMeshMaterials1.IsMergable(material) && MyBigMeshTable.Table.IsMergable(model) && !fracture) { var materialRk = MyMeshMaterials1.Table[material.Index].RepresentationKey; var mergeGroupForMaterial = m_materialGroups.Get(materialRk); if (mergeGroupForMaterial == null) { var proxyIndex = m_materialGroups.Count; mergeGroupForMaterial = new MyMaterialMergeGroup(MyBigMeshTable.Table, material, proxyIndex); m_materialGroups[MyMeshMaterials1.Table[material.Index].RepresentationKey] = mergeGroupForMaterial; m_dirtyProxy = true; } r.SetStandaloneRendering(false); child.GetGroupLeaf().m_mergeGroup = mergeGroupForMaterial; mergeGroupForMaterial.AddEntity(child, model); mergeGroupForMaterial.UpdateEntity(child); } }
internal override void OnRemove(MyActor owner) { if (m_children != null) { for (int i = 0; i < m_children.Count; i++) { m_children[i].RemoveComponent(m_children[i].GetGroupLeaf()); } m_children = null; } foreach (var val in m_materialGroups.Values) { val.Release(); } m_materialGroups.Clear(); m_dirtyTree = true; if (m_proxy != null) { MyCullProxy_2.Free(m_proxy); m_proxy = null; } if (m_btreeProxy != -1) { MyScene.GroupsDBVH.RemoveProxy(m_btreeProxy); m_btreeProxy = -1; } base.OnRemove(owner); this.Deallocate(); }
internal void UpdateProxySectionSubmeshes(ref MyRenderableProxy_2 proxy) { int filledSize; MyInstanceEntityInfo[] infos = m_mergeGroup.GetEntityInfos(out filledSize); // NB: It's important here to keep SectionSubmeshes same fill size as the // merge group instances, keeping also the holes. In this way, indexing // is kept consistent with the shader and we don't need other indirections proxy.SectionSubmeshes = new MyDrawSubmesh_2[filledSize][]; m_actorIndices.Clear(); int actorIndex = 0; for (int it = 0; it < filledSize; it++) { MyInstanceEntityInfo info = infos[it]; if (info.EntityId.HasValue) { MyActor actor = m_actors[info.EntityId.Value]; int indexOffset = info.PageOffset * m_mergeGroup.TablePageSize; UpdateActorSubmeshes(ref proxy, actor, actorIndex, indexOffset); m_actorIndices[actor] = actorIndex; } actorIndex++; } }
internal override void Construct() { base.Construct(); Type = MyActorComponentEnum.GroupLeaf; m_parent = null; m_mergeGroup = null; }
internal override void Assign(MyActor owner) { Debug.Assert(m_owners.Find(x => x == owner) == null); base.Assign(owner); m_owners.Add(owner); owner.MarkRenderDirty(); }
internal void PropagateMatrixChange(MyActor child) { var matrix = child.m_relativeTransform.HasValue ? (MatrixD)child.m_relativeTransform.Value * m_owner.WorldMatrix : m_owner.WorldMatrix; child.SetMatrix(ref matrix); }
internal void UpdateEntity(MyActor actor, ref MatrixD matrix, uint depthBias) { uint ID = actor.ID; m_perInstance.Data[m_entities[ID].InstanceIndex] = MyPerInstanceData.FromWorldMatrix(ref matrix, depthBias); m_instancesDataDirty = true; }
internal static MyActor GetInstanceActor(MyRenderableComponent original) { if (m_instanceActor == null) { m_instanceActor = MyActorFactory.Create(); m_instanceActor.AddComponent <MyInstanceLodComponent>(MyComponentFactory <MyInstanceLodComponent> .Create()); } return(m_instanceActor); }
internal void Unload() { if (m_actor != null && !m_actor.IsDestroyed) { MyActorFactory.Destroy(m_actor); } m_actor = null; MyMeshes.RemoveVoxelCell(m_mesh); }
private static void DisposeInstanceActor() { if (m_instanceActor != null) { if (!m_instanceActor.IsDestroyed) { MyActorFactory.Destroy(m_instanceActor); } m_instanceActor = null; } }
internal MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix, RenderFlags additionalFlags = 0) { m_worldMatrix = worldMatrix; m_actor = MyActorFactory.CreateSceneObject(); m_actor.SetMatrix(ref worldMatrix); m_actor.AddComponent(MyComponentFactory <MyFoliageComponent> .Create()); m_lod = cellCoord.Lod; Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod); m_actor.GetRenderable().SetModel(Mesh); m_actor.GetRenderable().m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags); }
internal MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix, RenderFlags additionalFlags = 0) { m_worldMatrix = worldMatrix; m_actor = MyActorFactory.CreateSceneObject(); m_actor.SetMatrix(ref worldMatrix); m_actor.AddComponent(MyComponentFactory<MyFoliageComponent>.Create()); m_lod = cellCoord.Lod; Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod); m_actor.GetRenderable().SetModel(Mesh); m_actor.GetRenderable().m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags); }
/// <returns>Actor full mesh indices count</returns> private void UpdateActorSubmeshes(ref MyRenderableProxy_2 proxy, MyActor actor, int actorIndex, int indexOffset) { MyRenderableComponent component = actor.GetRenderable(); MyRenderableProxy proxy1 = component.Lods[0].RenderableProxies[0]; MyDrawSubmesh_2 sectionSubmesh = proxy.Submeshes[0]; MyDrawSubmesh_2[] sectionSubmeshes = new MyDrawSubmesh_2[proxy1.SectionSubmeshes.Length]; proxy.SectionSubmeshes[actorIndex] = sectionSubmeshes; for (int it = 0; it < proxy1.SectionSubmeshes.Length; it++) { MyDrawSubmesh sectionSubmesh1 = proxy1.SectionSubmeshes[it]; sectionSubmesh.Count = sectionSubmesh1.IndexCount; sectionSubmesh.Start = indexOffset + sectionSubmesh1.StartIndex; sectionSubmeshes[it] = sectionSubmesh; } }
internal void RemoveEntity(MyActor actor) { uint ID = actor.ID; MyInstanceInfo info = m_entities[ID]; m_perInstance.Free(info.InstanceIndex); m_entityInfos.Free(info.InstanceIndex); foreach (var page in m_entities[ID].PageHandles) { m_instancingTable.Free(page); } // CHECK-ME m_entities.Remove(ID) is missing m_tableDirty = true; }
private static void RecordMeshPartCommands(MeshId model, MyActor actor, MyGroupRootComponent group, MyCullProxy_2 proxy, MyOutlineDesc desc, ref float maxThickness) { MeshSectionId sectionId; bool found = MyMeshes.TryGetMeshSection(model, 0, desc.SectionIndex, out sectionId); if (!found) { return; } OutlineConstantsLayout constants = new OutlineConstantsLayout(); maxThickness = Math.Max(desc.Thickness, maxThickness); constants.Color = desc.Color.ToVector4(); if (desc.PulseTimeInFrames > 0) { constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.Settings.GameplayFrame / (float)desc.PulseTimeInFrames), 2.0); } MyMeshSectionInfo1 section = sectionId.Info; MyMeshSectionPartInfo1[] meshes = section.Meshes; for (int idx = 0; idx < meshes.Length; idx++) { MyMaterialMergeGroup materialGroup; found = group.TryGetMaterialGroup(meshes[idx].Material, out materialGroup); if (!found) { DebugRecordMeshPartCommands(model, desc.SectionIndex, meshes[idx].Material); return; } int actorIndex; found = materialGroup.TryGetActorIndex(actor, out actorIndex); if (!found) { return; } var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants); mapping.WriteAndPosition(ref constants); mapping.Unmap(); MyOutlinePass.Instance.RecordCommands(ref proxy.Proxies[materialGroup.Index], actorIndex, meshes[idx].PartIndex); } }
internal MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix) { m_worldMatrix = worldMatrix; m_actor = MyActorFactory.CreateSceneObject(); //m_mesh = new MyVoxelMesh(cellCoord.CoordInLod, cellCoord.Lod, ""); //m_actor.GetRenderable().SetModel(m_mesh); m_actor.SetMatrix(ref worldMatrix); m_actor.AddComponent(MyComponentFactory <MyFoliageComponent> .Create()); m_lod = cellCoord.Lod; Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod); m_actor.GetRenderable().SetModel(Mesh); m_discardingOn = false; }
internal MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.Matrix worldMatrix) { m_worldMatrix = worldMatrix; m_actor = MyActorFactory.CreateSceneObject(); //m_mesh = new MyVoxelMesh(cellCoord.CoordInLod, cellCoord.Lod, ""); //m_actor.GetRenderable().SetModel(m_mesh); m_actor.SetMatrix(ref worldMatrix); m_actor.AddComponent(MyComponentFactory<MyFoliageComponent>.Create()); m_lod = cellCoord.Lod; Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod); m_actor.GetRenderable().SetModel(Mesh); m_discardingOn = false; }
internal MyClipmapCellProxy(MyCellCoord cellCoord, ref MatrixD worldMatrix, Vector3D massiveCenter, float massiveRadius, RenderFlags additionalFlags = 0) { m_worldMatrix = worldMatrix; m_actor = MyActorFactory.CreateVoxelCell(); m_actor.SetMatrix(ref worldMatrix); m_lod = cellCoord.Lod; MyVoxelRenderableComponent renderableComponent = m_actor.GetRenderable() as MyVoxelRenderableComponent; m_mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod); renderableComponent.SetVoxelLod(m_lod, ScaleGroup); renderableComponent.SetModel(m_mesh); renderableComponent.m_massiveCenter = massiveCenter; renderableComponent.m_massiveRadius = massiveRadius; renderableComponent.m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags); }
internal override void OnRemove(MyActor owner) { if (MergeGroup != null) { MergeGroup.RemoveEntity(Owner); MergeGroup = null; } if (Parent != null) { var root = Parent.GetGroupRoot(); if (root != null) { root.Remove(this); } Parent = null; } base.OnRemove(owner); this.Deallocate(); }
internal override void OnRemove(MyActor owner) { if (m_mergeGroup != null) { m_mergeGroup.RemoveEntity(m_owner); m_mergeGroup = null; } if (m_parent != null) { var root = m_parent.GetGroupRoot(); if (root != null) { root.Remove(this); } m_parent = null; } base.OnRemove(owner); this.Deallocate(); }
internal void AddEntity(MyActor actor, MeshId model) { uint ID = actor.ID; var instanceIndex = m_perInstance.Allocate(); var entityIndex = m_entityInfos.Allocate(); Debug.Assert(instanceIndex == entityIndex); m_entities[ID] = new MyInstanceInfo { InstanceIndex = instanceIndex, PageHandles = new List <MyPackedPoolHandle>() }; int pageOffset = -1; var key = MyMeshTableSrv.MakeKey(model); foreach (var id in m_meshTable.Pages(key)) { if (pageOffset == -1) { pageOffset = id; } var pageHandle = m_instancingTable.Allocate(); m_instancingTable.Data[m_instancingTable.AsIndex(pageHandle)] = new MyInstancingTableEntry { InstanceId = instanceIndex, InnerMeshId = id }; m_entities[ID].PageHandles.Add(pageHandle); } m_perInstance.Data[instanceIndex] = MyPerInstanceData.FromWorldMatrix(ref MatrixD.Zero, 0); m_entityInfos.Data[instanceIndex] = new MyInstanceEntityInfo { EntityId = ID, PageOffset = pageOffset }; m_tableDirty = true; }
internal override void OnRemove(MyActor owner) { if (m_mergeGroup != null) { m_mergeGroup.RemoveEntity(m_owner); m_mergeGroup = null; } if (m_parent != null) { // well, this if shouldn't be needed, but somehow it is if (m_parent.GetGroupRoot() != null) { m_parent.GetGroupRoot().m_children.Remove(m_owner); } m_parent = null; } base.OnRemove(owner); this.Deallocate(); }
static void DrawRenderableComponent(MyActor actor, MyRenderableComponent renderableComponent, List <MyHighlightDesc> highlightDescs) { var renderLod = renderableComponent.Lods[renderableComponent.CurrentLod]; var model = renderableComponent.GetModel(); LodMeshId currentModelId; if (!MyMeshes.TryGetLodMesh(model, renderableComponent.CurrentLod, out currentModelId)) { Debug.Fail("Mesh for outlining not found!"); return; } foreach (MyHighlightDesc descriptor in highlightDescs) { if (!renderableComponent.IsRenderedStandAlone) { MyGroupLeafComponent leafComponent = actor.GetGroupLeaf(); MyGroupRootComponent groupComponent = leafComponent.RootGroup; if (groupComponent != null) { RecordMeshPartCommands(model, actor, groupComponent, groupComponent.m_proxy, descriptor); } continue; } if (!string.IsNullOrEmpty(descriptor.SectionName)) { RecordMeshSectionCommands(model, renderableComponent, renderLod, descriptor); } else { RecordMeshPartCommands(model, currentModelId, renderableComponent, renderLod, descriptor); } } }
static void RecordMeshPartCommands(MeshId model, MyActor actor, MyGroupRootComponent group, MyCullProxy_2 proxy, MyHighlightDesc desc) { MeshSectionId sectionId; bool found = MyMeshes.TryGetMeshSection(model, 0, desc.SectionName, out sectionId); if (!found) { return; } WriteHighlightConstants(ref desc); MyMeshSectionInfo1 section = sectionId.Info; MyMeshSectionPartInfo1[] meshes = section.Meshes; for (int idx = 0; idx < meshes.Length; idx++) { MyMaterialMergeGroup materialGroup; found = group.TryGetMaterialGroup(meshes[idx].Material, out materialGroup); if (!found) { DebugRecordMeshPartCommands(model, desc.SectionName, meshes[idx].Material); return; } int actorIndex; found = materialGroup.TryGetActorIndex(actor, out actorIndex); if (!found) { return; } MyHighlightPass.Instance.RecordCommands(ref proxy.Proxies[materialGroup.Index], actorIndex, meshes[idx].PartIndex); } }
internal void AddEntity(MyActor actor, MeshId model) { m_actors[actor.ID] = actor; m_mergeGroup.AddEntity(actor, model); }
internal void AddEntity(MyActor actor, MeshId model) { m_actors.Add(actor); m_mergeGroup.AddEntity(actor.ID, model); }
internal void UpdateEntity(MyActor actor) { //var matrix = actor.WorldMatrix; //matrix.Translation = matrix.Translation - MyEnvironment.CameraPosition; m_mergeGroup.UpdateEntity(actor.ID, ref actor.WorldMatrix); }
internal override void OnRemove(MyActor owner) { base.OnRemove(owner); this.Deallocate(); }
internal static void Destroy(MyActor item) { item.Destruct(); m_pool.Deallocate(item); }
internal void UpdateEntity(MyActor actor) { //var matrix = actor.WorldMatrix; //matrix.Translation = matrix.Translation - MyRender11.Environment.CameraPosition; m_mergeGroup.UpdateEntity(actor, ref actor.WorldMatrix, actor.GetRenderable().m_depthBias); }
internal void Add(MyActor child) { child.AddComponent(MyComponentFactory<MyGroupLeafComponent>.Create()); child.GetGroupLeaf().m_parent = m_owner; m_children.Add(child); if (child.m_relativeTransform == null) { child.m_relativeTransform = (Matrix)( child.WorldMatrix * MatrixD.Invert(m_owner.WorldMatrix) ); } if (!m_owner.m_localAabb.HasValue) { m_owner.m_localAabb = child.m_localAabb; } else { var localAabb = child.m_localAabb.Value; m_owner.m_localAabb = m_owner.m_localAabb.Value.Include(ref localAabb); } PropagateMatrixChange(child); if(child.GetRenderable() == null) { return; } //var mesh = child.GetRenderable().GetMesh(); var model = child.GetRenderable().GetModel(); var material = MyMeshes.GetMeshPart(model, 0, 0).Info.Material; bool fracture = model.Info.RuntimeGenerated || model.Info.Dynamic; if (MyMeshMaterials1.IsMergable(material) && MyBigMeshTable.Table.IsMergable(model) && !fracture) { child.GetGroupLeaf().m_mergable = true; MyBigMeshTable.Table.AddMesh(model); m_mergablesCounter++; if(!m_isMerged && m_mergablesCounter >= MERGE_THRESHOLD) { TurnIntoMergeInstancing(); } else if(m_isMerged) { Merge(child); } //var materialRk = MyMeshMaterials1.Table[material.Index].RepresentationKey; //var mergeGroupForMaterial = m_materialGroups.Get(materialRk); //if (mergeGroupForMaterial == null) //{ // var proxyIndex = m_materialGroups.Count; // mergeGroupForMaterial = new MyMaterialMergeGroup(MyBigMeshTable.Table, material, proxyIndex); // m_materialGroups[MyMeshMaterials1.Table[material.Index].RepresentationKey] = mergeGroupForMaterial; // m_dirtyProxy = true; //} //child.GetRenderable().SetStandaloneRendering(false); //child.GetGroupLeaf().m_mergeGroup = mergeGroupForMaterial; //mergeGroupForMaterial.AddEntity(child, model); //mergeGroupForMaterial.UpdateEntity(child); } else { //Debug.WriteLine(String.Format("Mesh {0}, material {1} is not mergable", mesh.Name, material)); } m_dirtyTree = true; }
internal void RemoveEntity(MyActor actor) { uint ID = actor.ID; MyInstanceInfo info = m_entities[ID]; m_perInstance.Free(info.InstanceIndex); m_entityInfos.Free(info.InstanceIndex); foreach (var page in m_entities[ID].PageHandles) m_instancingTable.Free(page); // CHECK-ME m_entities.Remove(ID) is missing m_tableDirty = true; }
internal override void OnRemove(MyActor owner) { base.OnRemove(owner); m_owners.Remove(owner); }
internal override void OnRemove(MyActor owner) { FreeCustomRenderTextures(); DebrisEntityVoxelMaterial.Remove(owner.ID); base.OnRemove(owner); this.Deallocate(); }
private static void RecordMeshPartCommands(MeshId model, MyActor actor, MyGroupRootComponent group, MyCullProxy_2 proxy, MyOutlineDesc desc, ref float maxThickness) { MeshSectionId sectionId; bool found = MyMeshes.TryGetMeshSection(model, 0, desc.SectionIndex, out sectionId); if (!found) return; OutlineConstantsLayout constants = new OutlineConstantsLayout(); maxThickness = Math.Max(desc.Thickness, maxThickness); constants.Color = desc.Color.ToVector4(); if (desc.PulseTimeInFrames > 0) constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.GameplayFrameCounter / (float)desc.PulseTimeInFrames), 2.0); MyMeshSectionInfo1 section = sectionId.Info; MyMeshSectionPartInfo1[] meshes = section.Meshes; for (int idx = 0; idx < meshes.Length; idx++) { MyMaterialMergeGroup materialGroup; found = group.TryGetMaterialGroup(meshes[idx].Material, out materialGroup); if (!found) { DebugRecordMeshPartCommands(model, desc.SectionIndex, meshes[idx].Material); return; } int actorIndex; found = materialGroup.TryGetActorIndex(actor, out actorIndex); if (!found) return; var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants); mapping.WriteAndPosition(ref constants); mapping.Unmap(); MyOutlinePass.Instance.RecordCommands(ref proxy.Proxies[materialGroup.Index], actorIndex, meshes[idx].PartIndex); } }
private static void RecordMeshPartCommands(MeshId model, MyActor actor, MyGroupRootComponent group, MyCullProxy_2 proxy, MyHighlightDesc desc, ref float maxThickness) { MeshSectionId sectionId; bool found = MyMeshes.TryGetMeshSection(model, 0, desc.SectionIndex, out sectionId); if (!found) return; WriteHighlightConstants(ref desc, ref maxThickness); MyMeshSectionInfo1 section = sectionId.Info; MyMeshSectionPartInfo1[] meshes = section.Meshes; for (int idx = 0; idx < meshes.Length; idx++) { MyMaterialMergeGroup materialGroup; found = group.TryGetMaterialGroup(meshes[idx].Material, out materialGroup); if (!found) { DebugRecordMeshPartCommands(model, desc.SectionIndex, meshes[idx].Material); return; } int actorIndex; found = materialGroup.TryGetActorIndex(actor, out actorIndex); if (!found) return; MyHighlightPass.Instance.RecordCommands(ref proxy.Proxies[materialGroup.Index], actorIndex, meshes[idx].PartIndex); } }
internal override void OnRemove(MyActor owner) { if (m_children != null) { for (int i = 0; i < m_children.Count; i++) { m_children[i].RemoveComponent(m_children[i].GetGroupLeaf()); } m_children = null; } foreach (var val in m_materialGroups.Values) { val.Release(); } m_materialGroups.Clear(); m_dirtyTree = true; if (m_proxy != null) { MyCullProxy_2.Free(m_proxy); m_proxy = null; } if(m_btreeProxy != -1) { MyScene.GroupsDBVH.RemoveProxy(m_btreeProxy); m_btreeProxy = -1; } base.OnRemove(owner); this.Deallocate(); }
public bool TryGetActorIndex(MyActor actor, out int index) { return m_actorIndices.TryGetValue(actor, out index); }
internal MyClipmapCellProxy(MyCellCoord cellCoord, ref MatrixD worldMatrix, Vector3D massiveCenter, float massiveRadius, RenderFlags additionalFlags = 0, bool mergedMesh = false) { m_worldMatrix = worldMatrix; m_actor = MyActorFactory.CreateVoxelCell(); m_actor.SetMatrix(ref worldMatrix); m_lod = cellCoord.Lod; MyVoxelRenderableComponent renderableComponent = m_actor.GetRenderable() as MyVoxelRenderableComponent; m_mesh = !mergedMesh ? MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod) : MyMeshes.CreateMergedVoxelCell(cellCoord.CoordInLod, cellCoord.Lod); renderableComponent.SetVoxelLod(m_lod, ScaleGroup); renderableComponent.SetModel(m_mesh); renderableComponent.m_massiveCenter = massiveCenter; renderableComponent.m_massiveRadius = massiveRadius; renderableComponent.m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags); }
internal override void Assign(MyActor owner) { base.Assign(owner); }
internal void RemoveEntity(MyActor actor) { m_actors.Remove(actor); m_mergeGroup.RemoveEntity(actor.ID); }
internal void AddEntity(MyActor actor, MeshId model) { uint ID = actor.ID; var instanceIndex = m_perInstance.Allocate(); var entityIndex = m_entityInfos.Allocate(); Debug.Assert(instanceIndex == entityIndex); m_entities[ID] = new MyInstanceInfo { InstanceIndex = instanceIndex, PageHandles = new List<MyPackedPoolHandle>() }; int pageOffset = -1; foreach (var id in m_meshTable.Pages(MyMeshTableSRV.MakeKey(model))) { if (pageOffset == -1) pageOffset = id; var pageHandle = m_instancingTable.Allocate(); m_instancingTable.Data[m_instancingTable.AsIndex(pageHandle)] = new MyInstancingTableEntry { InstanceId = instanceIndex, InnerMeshId = id }; m_entities[ID].PageHandles.Add(pageHandle); } m_perInstance.Data[instanceIndex] = MyPerInstanceData.FromWorldMatrix(ref MatrixD.Zero, 0); m_entityInfos.Data[instanceIndex] = new MyInstanceEntityInfo { EntityId = ID, PageOffset = pageOffset }; m_tableDirty = true; }
internal void Add(MyActor child) { child.AddComponent(MyComponentFactory <MyGroupLeafComponent> .Create()); child.GetGroupLeaf().m_parent = m_owner; m_children.Add(child); if (child.m_relativeTransform == null) { child.m_relativeTransform = (Matrix)(child.WorldMatrix * MatrixD.Invert(m_owner.WorldMatrix)); } if (!m_owner.m_localAabb.HasValue) { m_owner.m_localAabb = child.m_localAabb; } else { var localAabb = child.m_localAabb.Value; m_owner.m_localAabb = m_owner.m_localAabb.Value.Include(ref localAabb); } PropagateMatrixChange(child); if (child.GetRenderable() == null) { return; } //var mesh = child.GetRenderable().GetMesh(); var model = child.GetRenderable().GetModel(); var material = MyMeshes.GetMeshPart(model, 0, 0).Info.Material; bool fracture = model.Info.RuntimeGenerated || model.Info.Dynamic; if (MyMeshMaterials1.IsMergable(material) && MyBigMeshTable.Table.IsMergable(model) && !fracture) { child.GetGroupLeaf().m_mergable = true; MyBigMeshTable.Table.AddMesh(model); m_mergablesCounter++; if (!m_isMerged && m_mergablesCounter >= MERGE_THRESHOLD) { TurnIntoMergeInstancing(); } else if (m_isMerged) { Merge(child); } //var materialRk = MyMeshMaterials1.Table[material.Index].RepresentationKey; //var mergeGroupForMaterial = m_materialGroups.Get(materialRk); //if (mergeGroupForMaterial == null) //{ // var proxyIndex = m_materialGroups.Count; // mergeGroupForMaterial = new MyMaterialMergeGroup(MyBigMeshTable.Table, material, proxyIndex); // m_materialGroups[MyMeshMaterials1.Table[material.Index].RepresentationKey] = mergeGroupForMaterial; // m_dirtyProxy = true; //} //child.GetRenderable().SetStandaloneRendering(false); //child.GetGroupLeaf().m_mergeGroup = mergeGroupForMaterial; //mergeGroupForMaterial.AddEntity(child, model); //mergeGroupForMaterial.UpdateEntity(child); } else { //Debug.WriteLine(String.Format("Mesh {0}, material {1} is not mergable", mesh.Name, material)); } m_dirtyTree = true; }
internal static void Run() { ProfilerShort.Begin("MyOutline.Run"); MyGpuProfiler.IC_BeginBlock("MyOutline.Run"); // set resolved depth/ stencil // render all with proper depth-stencil state // blur // blend to main target testing with stencil again MyOutlinePass.Instance.ViewProjection = MyEnvironment.ViewProjectionAt0; MyOutlinePass.Instance.Viewport = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); MyOutlinePass.Instance.PerFrame(); MyOutlinePass.Instance.Begin(); RC.Clear(); RC.DeviceContext.VertexShader.SetShaderResources(0, null, null, null, null, null, null); RC.DeviceContext.GeometryShader.SetShaderResources(0, null, null, null, null, null, null); RC.DeviceContext.PixelShader.SetShaderResources(0, null, null, null, null, null, null); RC.DeviceContext.ComputeShader.SetShaderResources(0, null, null, null, null, null, null); if (MyRender11.MultisamplingEnabled) { RC.DeviceContext.ClearRenderTargetView(MyRender11.m_rgba8_ms.m_RTV, new SharpDX.Color4(0, 0, 0, 0)); RC.DeviceContext.OutputMerger.SetTargets(MyGBuffer.Main.DepthStencil.m_DSV, MyRender11.m_rgba8_ms.m_RTV); } else { RC.DeviceContext.ClearRenderTargetView(MyRender11.m_rgba8_1.m_RTV, new SharpDX.Color4(0, 0, 0, 0)); RC.DeviceContext.OutputMerger.SetTargets(MyGBuffer.Main.DepthStencil.m_DSV, MyRender11.m_rgba8_1.m_RTV); } float maxThickness = 0f; foreach (var pair in m_outlines) { MyActor actor = MyIDTracker <MyActor> .FindByID(pair.Key); MyRenderableComponent renderableComponent; if (actor == null || (renderableComponent = actor.GetRenderable()) == null) { // If an actor has been removed without removing outlines, just remove the outlines too m_keysToRemove.Add(pair.Key); continue; } var renderLod = renderableComponent.Lods[renderableComponent.CurrentLod]; var model = renderableComponent.GetModel(); LodMeshId currentModelId; if (!MyMeshes.TryGetLodMesh(model, renderableComponent.CurrentLod, out currentModelId)) { Debug.Fail("Mesh for outlining not found!"); continue; } foreach (MyOutlineDesc descriptor in pair.Value) { if (!renderableComponent.IsRenderedStandAlone) { MyGroupLeafComponent leafComponent = actor.GetGroupLeaf(); MyGroupRootComponent groupComponent = leafComponent.RootGroup; if (groupComponent != null) { RecordMeshPartCommands(model, actor, groupComponent, groupComponent.m_proxy, descriptor, ref maxThickness); } continue; } if (descriptor.SectionIndex == -1) { RecordMeshPartCommands(model, currentModelId, renderableComponent, renderLod, descriptor, ref maxThickness); } else { RecordMeshSectionCommands(model, currentModelId, renderableComponent, renderLod, descriptor, ref maxThickness); } } } MyOutlinePass.Instance.End(); RC.SetBS(null); foreach (var outlineKey in m_keysToRemove) { m_outlines.Remove(outlineKey); } m_keysToRemove.SetSize(0); ShaderResourceView initialSourceView = MyRender11.MultisamplingEnabled ? MyRender11.m_rgba8_ms.m_SRV : MyRender11.m_rgba8_1.m_SRV; RenderTargetView renderTargetview = MyRender11.MultisamplingEnabled ? MyRender11.m_rgba8_ms.m_RTV : MyRender11.m_rgba8_1.m_RTV; if (maxThickness > 0) { MyBlur.Run(renderTargetview, MyRender11.m_rgba8_2.m_RTV, MyRender11.m_rgba8_2.m_SRV, initialSourceView, (int)Math.Round(5 * maxThickness), MyBlur.MyBlurDensityFunctionType.Exponential, 0.25f, null, MyFoliageRenderingPass.GrassStencilMask, MyRender11.Settings.BlurCopyOnDepthStencilFail); } MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); }