Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        internal override void Construct()
        {
            base.Construct();
            Type = MyActorComponentEnum.GroupLeaf;

            m_parent = null;
            m_mergeGroup = null;
        }
Esempio n. 3
0
        internal override void Construct()
        {
            base.Construct();
            Type = MyActorComponentEnum.GroupLeaf;

            m_parent     = null;
            m_mergeGroup = null;
        }
Esempio n. 4
0
        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 = group.GetMaterialGroup(meshes[idx].Material);
                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);
            }
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
        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();
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
 public bool TryGetMaterialGroup(MyMeshMaterialId matId, out MyMaterialMergeGroup group)
 {
     int rootMaterialRK = MyMeshMaterials1.Table[matId.Index].RepresentationKey;
     return m_materialGroups.TryGetValue(rootMaterialRK, out group);
 }
Esempio n. 11
0
        public bool TryGetMaterialGroup(MyMeshMaterialId matId, out MyMaterialMergeGroup group)
        {
            int rootMaterialRK = MyMeshMaterials1.Table[matId.Index].RepresentationKey;

            return(m_materialGroups.TryGetValue(rootMaterialRK, out group));
        }
Esempio n. 12
0
        internal void Add(MyActor child)
        {
            child.AddComponent(MyComponentFactory<MyGroupLeafComponent>.Create());

            child.GetGroupLeaf().m_parent = m_owner;

            if (m_children == null)
                m_children = new List<MyActor>();
            m_children.Add(child);

            if (child.m_relativeTransform == null)
            {
                child.m_relativeTransform = child.WorldMatrix * Matrix.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)
            {
                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;

                MyBigMeshTable.Table.AddMesh(model);
                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;
        }
Esempio n. 13
0
        internal void Add(MyActor child)
        {
            child.AddComponent(MyComponentFactory <MyGroupLeafComponent> .Create());

            child.GetGroupLeaf().m_parent = m_owner;

            if (m_children == null)
            {
                m_children = new List <MyActor>();
            }
            m_children.Add(child);

            if (child.m_relativeTransform == null)
            {
                child.m_relativeTransform = child.WorldMatrix * Matrix.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)
            {
                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;

                MyBigMeshTable.Table.AddMesh(model);
                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;
        }