示例#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);
            }
        }
示例#2
0
        internal void TurnIntoSeparateRenderables()
        {
            foreach (var child in m_children)
            {
                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)
                {
                    if (child.GetGroupLeaf().m_mergeGroup != null)
                    {
                        var materialRk            = MyMeshMaterials1.Table[material.Index].RepresentationKey;
                        var mergeGroupForMaterial = m_materialGroups.Get(materialRk);
                        if (mergeGroupForMaterial == null)
                        {
                            continue;
                        }

                        r.SetStandaloneRendering(true);
                        child.GetGroupLeaf().m_mergeGroup = null;

                        mergeGroupForMaterial.RemoveEntity(child);
                    }
                }
            }

            m_isMerged = false;
        }
示例#3
0
        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;
        }