コード例 #1
0
        internal bool IsMergable(MeshId model)
        {
            // check if one and only spoorted vertex format
            // check if same material as the rest
            // check if has one part(!) 
            // check if has one lod - for now

            return
                model.Info.LodsNum == 1 && MyMeshes.GetLodMesh(model, 0).Info.PartsNum == 1 && m_meshTable.IsMergable(model);
        }
コード例 #2
0
		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);
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        internal override void Construct()
        {
            base.Construct();

            Type = MyActorComponentEnum.Renderable;
            //m_mesh = null;
            m_lods = null;
            m_cullProxy = MyProxiesFactory.CreateCullProxy();
            m_btreeProxy = -1;

            Mesh = MeshId.NULL;
            Instancing = InstancingId.NULL;
            
            m_instanceCount = 0;
            m_startInstance = 0;

            m_isRenderedStandalone = true;

            m_keyColor = Vector3.One;
            m_objectDithering = 0;

            m_renderableProxiesForLodTransition = null;

            m_lodTransitionState = 0;
            m_lod = 0;

            m_voxelLod = -1;
            m_additionalFlags = 0;

            ModelProperties = new Dictionary<MyEntityMaterialKey, MyModelProperties>();
        }
コード例 #5
0
ファイル: MyHighlight.cs プロジェクト: 2asoft/SpaceEngineers
 static void DebugRecordMeshPartCommands(MeshId model, int sectionIndex, MyRenderableComponent render,
     MyRenderLod renderLod, MyMeshSectionPartInfo1[] meshes, int index)
 {
     Debug.Assert(false, "DebugRecordMeshPartCommands1: Call Francesco");
     MyLog.Default.WriteLine("DebugRecordMeshPartCommands1");
     MyLog.Default.WriteLine("sectionIndex: " + sectionIndex);
     MyLog.Default.WriteLine("model.Info.Name: " + model.Info.Name);
     MyLog.Default.WriteLine("render.CurrentLod: " + render.CurrentLod);
     MyLog.Default.WriteLine("renderLod.RenderableProxies.Length: " + renderLod.RenderableProxies.Length);
     MyLog.Default.WriteLine("meshes.Length: " + meshes.Length);
     MyLog.Default.WriteLine("Mesh index: " + index);
     MyLog.Default.WriteLine("Mesh part index: " + meshes[index].PartIndex);
 }
コード例 #6
0
 internal static MyMeshTableEntry MakeKey(MeshId model)
 {
     return new MyMeshTableEntry { Model = model, Lod = 0, Part = 0 };
 }
コード例 #7
0
ファイル: MyHighlight.cs プロジェクト: 2asoft/SpaceEngineers
        private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyHighlightDesc desc, ref float maxThickness)
        {
            WriteHighlightConstants(ref desc, ref maxThickness);

            var submeshCount = lodModelId.Info.PartsNum;
            for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex)
            {
                var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex);

                MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[submeshIndex].HighlightShaders);
                MyHighlightPass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex], -1, desc.InstanceId);
            }
        }
コード例 #8
0
        /// <returns>True if the section was found</returns>
        private static bool RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyOutlineDesc desc, ref OutlineConstantsLayout constants, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId);
            if (!found)
                return false;

            MyMeshSectionInfo1 section = sectionId.Info;
            MyMeshSectionPartInfo1[] meshes = section.Meshes;
            for (int idx = 0; idx < meshes.Length; idx++)
            {
                maxThickness = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[meshes[idx].PartIndex]);

                MyRenderableProxy proxy = renderLod.RenderableProxies[meshes[idx].PartIndex];
                MyOutlinePass.Instance.RecordCommands(proxy, meshes[idx].PartSubmeshIndex);
            }

            return true;
        }
コード例 #9
0
        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;
        }
コード例 #10
0
        internal bool IsMergable(MeshId model)
        {
            var mesh = MyMeshes.GetLodMesh(model, 0);

            return(mesh.Info.Data.VertexLayout == OneAndOnlySupportedVertexLayout && mesh.Info.IndicesNum > 0 && model.Info.RuntimeGenerated == false && model.Info.Dynamic == false);
        }
コード例 #11
0
        private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyOutlineDesc desc, ref OutlineConstantsLayout constants, ref float maxThickness)
        {
            var submeshCount = lodModelId.Info.PartsNum;
            for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex)
            {
                var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex);

                maxThickness = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[submeshIndex]);
                MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex]);
            }
        }
コード例 #12
0
        internal unsafe void AddMesh(MeshId model)
        {
            Debug.Assert(IsMergable(model));

            var key = new MyMeshTableEntry {
                Model = model, Lod = 0, Part = 0
            };

            if (!ContainsKey(key))
            {
                var vertexOffset = m_vertices;
                var indexOffset  = m_indices;

                var mesh = MyMeshes.GetLodMesh(model, 0);
                Debug.Assert(mesh.Info.Data.IndicesFmt == SharpDX.DXGI.Format.R16_UInt);

                var meshInfo = mesh.Info;
                var data     = meshInfo.Data;

                int verticesCapacity = vertexOffset + meshInfo.VerticesNum;
                int indicesCapacity  = CalculateIndicesCapacity(indexOffset, meshInfo.IndicesNum);

                m_vertices = verticesCapacity;
                m_indices  = indicesCapacity;

                MyArrayHelpers.Reserve(ref m_vertexStream0, verticesCapacity * Stride0, 1024 * 1024);
                MyArrayHelpers.Reserve(ref m_vertexStream1, verticesCapacity * Stride1, 1024 * 1024);
                MyArrayHelpers.Reserve(ref m_indexStream, indicesCapacity * IndexStride, 1024 * 1024);

                var list = new List <int>();

                fixed(byte *src = data.VertexStream0, dst_ = m_vertexStream0)
                {
                    byte *dst = dst_ + data.Stride0 * vertexOffset;

                    SharpDX.Utilities.CopyMemory(new IntPtr(dst), new IntPtr(src), data.Stride0 * meshInfo.VerticesNum);
                }

                fixed(byte *src = data.VertexStream1, dst_ = m_vertexStream1)
                {
                    byte *dst = dst_ + data.Stride1 * vertexOffset;

                    SharpDX.Utilities.CopyMemory(new IntPtr(dst), new IntPtr(src), data.Stride1 * meshInfo.VerticesNum);
                }

                fixed(void *dst = m_indexStream)
                {
                    uint *stream = (uint *)dst;

                    stream += indexOffset;
                    fixed(void *src = data.Indices)
                    {
                        ushort *indices = (ushort *)src;

                        for (int k = 0; k < meshInfo.IndicesNum; k += m_indexPageSize)
                        {
                            int iEnd = Math.Min(k + m_indexPageSize, meshInfo.IndicesNum);

                            for (int i = k; i < iEnd; i++)
                            {
                                stream[i] = (uint)(indices[i] + vertexOffset);
                            }

                            list.Add(m_pagesUsed++);
                        }

                        if ((meshInfo.IndicesNum % m_indexPageSize) != 0)
                        {
                            var  pageIndex  = meshInfo.IndicesNum / m_indexPageSize;
                            var  pageOffset = meshInfo.IndicesNum % m_indexPageSize;
                            uint lastIndex  = stream[pageIndex * m_indexPageSize + pageOffset - 1];
                            for (int i = pageOffset; i < m_indexPageSize; i++)
                            {
                                stream[pageIndex * m_indexPageSize + i] = lastIndex;
                            }
                        }
                    }
                }

                m_table.Add(key, new MyMeshTableSRV_Entry {
                    Pages = list
                });
                m_dirty = true;
            }
        }
コード例 #13
0
 internal static MyMeshTableEntry MakeKey(MeshId model)
 {
     return(new MyMeshTableEntry {
         Model = model, Lod = 0, Part = 0
     });
 }
コード例 #14
0
 internal void AddEntity(MyActor actor, MeshId model)
 {
     m_actors.Add(actor);
     m_mergeGroup.AddEntity(actor.ID, model);
 }
コード例 #15
0
 internal void AddEntity(MyActor actor, MeshId model)
 {
     m_actors[actor.ID] = actor;
     m_mergeGroup.AddEntity(actor, model);
 }
コード例 #16
0
 private void AssignLodMeshToProxy(MeshId mesh, MyRenderableProxy proxy)
 {
     if (MyMeshes.IsMergedVoxelMesh(mesh))
         proxy.MergedMesh = MyMeshes.GetMergedLodMesh(mesh, 0);
     else
         proxy.Mesh = MyMeshes.GetLodMesh(mesh, 0);
 }
コード例 #17
0
        internal bool IsMergable(MeshId model)
        {
            var mesh = MyMeshes.GetLodMesh(model, 0);

            return mesh.Info.Data.VertexLayout == OneAndOnlySupportedVertexLayout && mesh.Info.IndicesNum > 0 && model.Info.RuntimeGenerated == false && model.Info.Dynamic == false;
        }
コード例 #18
0
 internal void AddEntity(MyActor actor, MeshId model)
 {
     m_actors[actor.ID] = actor;
     m_mergeGroup.AddEntity(actor, model);
 }
コード例 #19
0
ファイル: MyHighlight.cs プロジェクト: 2asoft/SpaceEngineers
        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);
            }
        }
コード例 #20
0
ファイル: Hierarchy.cs プロジェクト: fluxit/SpaceEngineers
 internal void AddEntity(MyActor actor, MeshId model)
 {
     m_actors.Add(actor);
     m_mergeGroup.AddEntity(actor.ID, model);
 }
コード例 #21
0
ファイル: MyHighlight.cs プロジェクト: 2asoft/SpaceEngineers
        /// <returns>True if the section was found</returns>
        private static void RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyHighlightDesc desc, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, 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++)
            {
                MyMeshSectionPartInfo1 sectionInfo = meshes[idx];
                if (renderLod.RenderableProxies.Length <= sectionInfo.PartIndex)
                {
                    DebugRecordMeshPartCommands(model, desc.SectionIndex, rendercomp, renderLod, meshes, idx);
                    return;
                }

                MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex];
                MyHighlightPass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId);
            }

            return;
        }
コード例 #22
0
        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);
        }
コード例 #23
0
ファイル: MyHighlight.cs プロジェクト: 2asoft/SpaceEngineers
 static void DebugRecordMeshPartCommands(MeshId model, int sectionIndex, MyMeshMaterialId material)
 {
     Debug.Assert(false, "DebugRecordMeshPartCommands2: Call Francesco");
     MyLog.Default.WriteLine("DebugRecordMeshPartCommands2");
     MyLog.Default.WriteLine("sectionIndex: " + sectionIndex);
     MyLog.Default.WriteLine("model.Info.Name: " + model.Info.Name);
     MyLog.Default.WriteLine("material.Info.Name: " + material.Info.Name);
 }
コード例 #24
0
ファイル: MyOutline.cs プロジェクト: rem02/SpaceEngineers
        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);
            }
        }
コード例 #25
0
        internal void AddEntity(uint ID, MeshId model)
        {
            var instanceIndex = m_perInstance.Allocate();

            m_entities[ID] = new MyInstanceInfo { InstanceIndex = instanceIndex, PageHandles = new List<MyPackedPoolHandle>() };

            foreach (var id in m_meshTable.Pages(MyMeshTableSRV.MakeKey(model)))
            {
                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_tablesDirty = true;
        }
コード例 #26
0
ファイル: MyOutline.cs プロジェクト: rem02/SpaceEngineers
        private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyOutlineDesc desc, ref float maxThickness)
        {
            OutlineConstantsLayout constants = new OutlineConstantsLayout();
            var submeshCount = lodModelId.Info.PartsNum;
            for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex)
            {
                var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex);

                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);

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[submeshIndex].HighlightShaders);
                MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex], -1, desc.InstanceId);
            }
        }
コード例 #27
0
            private bool TryCancelMergeJob(int divideIndex, MeshId meshIdToRemove)
            {
                bool canceled = false;
                if (m_mergeJobs[divideIndex].LodMeshesBeingMerged.Count > 0)
                {
                    // Send the cancel message
                    MyRenderProxy.CancelVoxelMeshMerge(m_parentClipmap.Id, m_mergeJobs[divideIndex].CurrentWorkId);

                    if (meshIdToRemove != MeshId.NULL)
                        m_mergeJobs[divideIndex].LodMeshesBeingMerged.Remove(MyMeshes.GetLodMesh(meshIdToRemove, 0));

                    // Put the canceled meshes back into the correct pending queue
                    var mergedId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0);
                    mergedId.Info.PendingLodMeshes.UnionWith(m_mergeJobs[divideIndex].LodMeshesBeingMerged);

                    ResetMerge(divideIndex);
                    canceled = true;
                }
                return canceled;
            }
コード例 #28
0
ファイル: MyOutline.cs プロジェクト: rem02/SpaceEngineers
        /// <returns>True if the section was found</returns>
        private static void RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId,
            MyRenderableComponent rendercomp, MyRenderLod renderLod,
            MyOutlineDesc desc, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId);
            if (!found)
                return;

            OutlineConstantsLayout constants = new OutlineConstantsLayout();
            MyMeshSectionInfo1 section = sectionId.Info;
            MyMeshSectionPartInfo1[] meshes = section.Meshes;
            for (int idx = 0; idx < meshes.Length; idx++)
            {
                MyMeshSectionPartInfo1 sectionInfo = meshes[idx];
                if (renderLod.RenderableProxies.Length <= sectionInfo.PartIndex)
                {
                    DebugRecordMeshPartCommands(model, desc.SectionIndex, rendercomp, renderLod, meshes, idx);
                    return;
                }

                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);

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[sectionInfo.PartIndex].HighlightShaders);

                MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex];
                MyOutlinePass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId);
            }

            return;
        }
コード例 #29
0
        internal static RenderableId CreateRenderable(EntityId entity, MeshId model, Vector3 keyColor)
        {
            var id = new RenderableId { Index = Renderables.Allocate() };

            Renderables.Data[id.Index] = new MyRenderableInfo
            {
                KeyColor = keyColor,
                ObjectDithering = 0,
                Mesh = model
            };

            EntityDirty.Add(entity);

            RenderableIndex[entity] = id;

            return id;
        }
コード例 #30
0
        internal unsafe void AddMesh(MeshId model)
        {
            Debug.Assert(IsMergable(model));

            var key = new MyMeshTableEntry { Model = model, Lod = 0, Part = 0 };
            if (!ContainsKey(key))
            {
                var vertexOffset = m_vertices;
                var indexOffset = m_indices;

                var mesh = MyMeshes.GetLodMesh(model, 0);
                Debug.Assert(mesh.Info.Data.IndicesFmt == SharpDX.DXGI.Format.R16_UInt);

                var meshInfo = mesh.Info;
                var data = meshInfo.Data;

                int verticesCapacity = vertexOffset + meshInfo.VerticesNum;
                int indicesCapacity = CalculateIndicesCapacity(indexOffset, meshInfo.IndicesNum);

                m_vertices = verticesCapacity;
                m_indices = indicesCapacity;

                MyArrayHelpers.Reserve(ref m_vertexStream0, verticesCapacity * Stride0, 1024 * 1024);
                MyArrayHelpers.Reserve(ref m_vertexStream1, verticesCapacity * Stride1, 1024 * 1024);
                MyArrayHelpers.Reserve(ref m_indexStream, indicesCapacity * IndexStride, 1024 * 1024);

                var list = new List<int>();

                fixed(byte* src = data.VertexStream0, dst_ = m_vertexStream0)
                {
                    byte* dst = dst_ + data.Stride0 * vertexOffset;
                    SharpDX.Utilities.CopyMemory(new IntPtr(dst), new IntPtr(src), data.Stride0 * meshInfo.VerticesNum);
                }
                fixed (byte* src = data.VertexStream1, dst_ = m_vertexStream1)
                {
                    byte* dst = dst_ + data.Stride1 * vertexOffset;
                    SharpDX.Utilities.CopyMemory(new IntPtr(dst), new IntPtr(src), data.Stride1 * meshInfo.VerticesNum);
                }

                fixed (void* dst = m_indexStream)
                {
                    uint* stream = (uint*) dst;
                    stream += indexOffset;
                    fixed(void* src = data.Indices)
                    {
                        ushort* indices = (ushort*)src;
                        for (int k = 0; k < meshInfo.IndicesNum; k += m_indexPageSize)
                        {
                            int iEnd = Math.Min(k + m_indexPageSize, meshInfo.IndicesNum);

                            for (int i = k; i < iEnd; i++)
                            {
                                stream[i] = (uint) (indices[i] + vertexOffset);
                            }

                            list.Add(m_pagesUsed++);
                        }

                        if ((meshInfo.IndicesNum % m_indexPageSize) != 0)
                        {
                            var pageIndex = meshInfo.IndicesNum / m_indexPageSize;
                            var pageOffset = meshInfo.IndicesNum % m_indexPageSize;
                            uint lastIndex = stream[pageIndex * m_indexPageSize + pageOffset - 1];
                            for (int i = pageOffset; i < m_indexPageSize; i++)
                            {
                                stream[pageIndex * m_indexPageSize + i] = lastIndex;
                            }
                        }
                    }
                }

                m_table.Add(key, new MyMeshTableSrv_Entry { Pages = list });
                m_dirty = true;
            }
        }
コード例 #31
0
        internal void SetModel(MeshId mesh)
        {
            Mesh = mesh;

            SetLocalAabbToModelLod(0);

            m_owner.MarkRenderDirty();
        }
コード例 #32
0
 internal static BoundingBox?GetBoundingBox(this MeshId meshId, int lod)
 {
     return(MyMeshes.IsMergedVoxelMesh(meshId) ? MyMeshes.GetMergedLodMesh(meshId, 0).Info.BoundingBox : MyMeshes.GetLodMesh(meshId, lod).Info.BoundingBox);
 }