public void DeserializePart(Vector3I minBone, Vector3I maxBone, float boneRange, List <byte> data)
        {
            var size = maxBone - minBone;

            size += Vector3I.One; // bounds inclusive

            if (size.Size * 3 < data.Count)
            {
                Debug.Fail("Data has wrong length");
                return;
            }

            int index = 0;

            Vector3I pos;

            for (pos.X = minBone.X; pos.X <= maxBone.X; pos.X++)
            {
                for (pos.Y = minBone.Y; pos.Y <= maxBone.Y; pos.Y++)
                {
                    for (pos.Z = minBone.Z; pos.Z <= maxBone.Z; pos.Z++)
                    {
                        this[pos] = Vector3UByte.Denormalize(new Vector3UByte(data[index], data[index + 1], data[index + 2]), boneRange);
                        index    += 3;
                    }
                }
            }
        }
        public void Deserialize(List <BoneInfo> data, float boneRange, float gridSize, bool clear = false)
        {
            ProfilerShort.Begin("MyGridSkeleton.Deserialize(...)");
            if (clear)
            {
                Bones.Clear();
            }

            foreach (var bone in data)
            {
                Bones[bone.BonePosition] = Vector3UByte.Denormalize(bone.BoneOffset, boneRange);
                //FixBone(bone.BonePosition, gridSize);
            }
            ProfilerShort.End();
        }
Exemple #3
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_CubeBlockDefinition;

            MyDebug.AssertDebug(ob != null);

            this.Size  = ob.Size;
            this.Model = ob.Model;
            this.UseModelIntersection = ob.UseModelIntersection;
            this.CubeSize             = ob.CubeSize;
            this.ModelOffset          = ob.ModelOffset;
            this.BlockTopology        = ob.BlockTopology;
            this.PhysicsOption        = ob.PhysicsOption;
            this.BlockPairName        = ob.BlockPairName;
            this.m_center             = ob.Center ?? ((Size - 1) / 2);
            this.m_symmetryX          = ob.MirroringX;
            this.m_symmetryY          = ob.MirroringY;
            this.m_symmetryZ          = ob.MirroringZ;
            this.DeformationRatio     = ob.DeformationRatio;
            this.EdgeType             = ob.EdgeType;
            this.AutorotateMode       = ob.AutorotateMode;
            this.m_mirroringBlock     = ob.MirroringBlock;
            this.MultiBlock           = ob.MultiBlock;
            this.GuiVisible           = ob.GuiVisible;
            this.Rotation             = ob.Rotation;
            this.Direction            = ob.Direction;
            this.Mirrored             = ob.Mirrored;
            this.RandomRotation       = ob.RandomRotation;
            this.BuildType            = ob.BuildType != null?ob.BuildType.ToLower() : null;

            this.GeneratedBlockType = MyStringId.GetOrCompute(ob.GeneratedBlockType != null ? ob.GeneratedBlockType.ToLower() : null);
            if (ob.DamageEffectId != 0)
            {
                this.DamageEffectID = ob.DamageEffectId;
            }

            this.CompoundTemplates = ob.CompoundTemplates;
            Debug.Assert(this.CompoundTemplates == null || this.CompoundTemplates.Length > 0, "Wrong compound templates, array is empty");

            if (ob.SubBlockDefinitions != null)
            {
                SubBlockDefinitions = new Dictionary <string, MyDefinitionId>();

                foreach (var definition in ob.SubBlockDefinitions)
                {
                    MyDefinitionId defId;
                    if (SubBlockDefinitions.TryGetValue(definition.SubBlock, out defId))
                    {
                        MyDebug.AssertDebug(false, "Subblock definition already defined!");
                        continue;
                    }

                    defId = definition.Id;
                    SubBlockDefinitions.Add(definition.SubBlock, defId);
                }
            }

            if (ob.BlockVariants != null)
            {
                BlockStages = new MyDefinitionId[ob.BlockVariants.Length];

                for (int i = 0; i < ob.BlockVariants.Length; ++i)
                {
                    BlockStages[i] = ob.BlockVariants[i];
                }
            }

            var cubeDef = ob.CubeDefinition;

            if (cubeDef != null)
            {
                MyCubeDefinition tmp = new MyCubeDefinition();
                tmp.CubeTopology = cubeDef.CubeTopology;
                tmp.ShowEdges    = cubeDef.ShowEdges;

                var sides = cubeDef.Sides;
                tmp.Model       = new string[sides.Length];
                tmp.PatternSize = new Vector2I[sides.Length];
                for (int j = 0; j < sides.Length; ++j)
                {
                    var side = sides[j];
                    tmp.Model[j]       = side.Model;
                    tmp.PatternSize[j] = side.PatternSize;
                }
                this.CubeDefinition = tmp;
            }

            var components = ob.Components;

            MyDebug.AssertDebug(components != null);
            MyDebug.AssertDebug(components.Length != 0);
            float mass = 0.0f;
            float criticalIntegrity  = 0f;
            float ownershipIntegrity = 0f;

            if (components != null && components.Length != 0)
            {
                Components = new MyCubeBlockDefinition.Component[components.Length];

                float integrity           = 0.0f;
                int   criticalTypeCounter = 0;
                for (int j = 0; j < components.Length; ++j)
                {
                    var component = components[j];

                    MyCubeBlockDefinition.Component tmp = new MyCubeBlockDefinition.Component()
                    {
                        Count      = component.Count,
                        Definition = MyDefinitionManager.Static.GetComponentDefinition(new MyDefinitionId(component.Type, component.Subtype))
                    };

                    if (component.Type == typeof(MyObjectBuilder_Component) && component.Subtype == "Computer")
                    {
                        if (ownershipIntegrity == 0)
                        {
                            ownershipIntegrity = integrity + tmp.Definition.MaxIntegrity;
                        }
                    }

                    integrity += tmp.Count * tmp.Definition.MaxIntegrity;
                    if (component.Type == ob.CriticalComponent.Type &&
                        component.Subtype == ob.CriticalComponent.Subtype)
                    {
                        if (criticalTypeCounter == ob.CriticalComponent.Index)
                        {
                            CriticalGroup     = (UInt16)j;
                            criticalIntegrity = integrity - 1;
                        }
                        ++criticalTypeCounter;
                    }

                    mass += tmp.Count * tmp.Definition.Mass;

                    Components[j] = tmp;
                }
                MaxIntegrity          = integrity;
                IntegrityPointsPerSec = integrity / ob.BuildTimeSeconds;
                DisassembleRatio      = ob.DisassembleRatio;
                Mass = mass;
            }

            CriticalIntegrityRatio  = criticalIntegrity / MaxIntegrity;
            OwnershipIntegrityRatio = ownershipIntegrity / MaxIntegrity;

            if (ob.BuildProgressModels != null)
            {
                ob.BuildProgressModels.Sort((a, b) => a.BuildPercentUpperBound.CompareTo(b.BuildPercentUpperBound));
                this.BuildProgressModels = new BuildProgressModel[ob.BuildProgressModels.Count];
                for (int i = 0; i < BuildProgressModels.Length; ++i)
                {
                    var builderModel = ob.BuildProgressModels[i];
                    if (!string.IsNullOrEmpty(builderModel.File))
                    {
                        this.BuildProgressModels[i] = new BuildProgressModel()
                        {
                            BuildRatioUpperBound = builderModel.BuildPercentUpperBound * CriticalIntegrityRatio,
                            File = builderModel.File,
                            RandomOrientation = builderModel.RandomOrientation
                        };
                    }
                }
            }

            if (ob.GeneratedBlocks != null)
            {
                this.GeneratedBlockDefinitions = new MyDefinitionId[ob.GeneratedBlocks.Length];

                for (int i = 0; i < ob.GeneratedBlocks.Length; ++i)
                {
                    var genBlockId = ob.GeneratedBlocks[i];
                    Debug.Assert(!string.IsNullOrEmpty(genBlockId.SubtypeName));
                    Debug.Assert(!string.IsNullOrEmpty(genBlockId.TypeIdString));

                    this.GeneratedBlockDefinitions[i] = genBlockId;
                }
            }

            Skeleton = ob.Skeleton;
            if (Skeleton != null)
            {
                Bones = new Dictionary <Vector3I, Vector3>(ob.Skeleton.Count);
                foreach (var bone in Skeleton)
                {
                    Bones[bone.BonePosition] = Vector3UByte.Denormalize(bone.BoneOffset, MyDefinitionManager.Static.GetCubeSize(ob.CubeSize));
                }
            }

            IsAirTight = ob.IsAirTight;

            InitMountPoints(ob);
            InitPressurization();

            InitNavigationInfo(ob, ob.NavigationDefinition);

            CheckBuildProgressModels();
            // Components and CriticalComponent will be initialized elsewhere

            this.PrimarySound = new MySoundPair(ob.PrimarySound);
        }
 static MyGridSkeleton()
 {
     MAX_BONE_ERROR = Vector3UByte.Denormalize(new Vector3UByte(128, 128, 128), 1f).X * 0.75f;
 }