コード例 #1
0
            public static BodyTemplate ParseBod2(ushort version, IMutagenReadStream frame, SubrecordHeader subrecordHeader)
            {
                var len = subrecordHeader.ContentLength;

                if (version <= 22 && len <= 8)
                {
                    throw SubrecordException.Create("BOD2 can not be parsed on Form Versions <= 22 with length <= 8", RecordTypes.BOD2);
                }

                var item = new BodyTemplate();

                item.ActsLike44       = true;
                item.FirstPersonFlags = EnumBinaryTranslation <BipedObjectFlag, IMutagenReadStream, MutagenWriter> .Instance.Parse(
                    reader : frame,
                    length : 4);

                if (len == 8)
                {
                    item.ArmorType = EnumBinaryTranslation <ArmorType, IMutagenReadStream, MutagenWriter> .Instance.Parse(
                        reader : frame,
                        length : 4);
                }
                else
                {
                    item.Flags = EnumBinaryTranslation <BodyTemplate.Flag, IMutagenReadStream, MutagenWriter> .Instance.Parse(
                        reader : frame,
                        length : 4);

                    item.ArmorType = EnumBinaryTranslation <ArmorType, IMutagenReadStream, MutagenWriter> .Instance.Parse(
                        reader : frame,
                        length : 4);
                }
                return(item);
            }
コード例 #2
0
ファイル: Util.cs プロジェクト: SpencasaurusRex/AetheriumMono
        public static BodyTemplate Scale(this BodyTemplate bodyTemplate, Vector2 scale)
        {
            List <FixtureTemplate> fixtures = new List <FixtureTemplate>(bodyTemplate.Fixtures.Count);

            foreach (var fixture in bodyTemplate.Fixtures)
            {
                Shape shapeCopy;

                switch (fixture.Shape.ShapeType)
                {
                case ShapeType.Polygon:
                    Vertices verticesCopy = new Vertices();
                    verticesCopy.AddRange(((PolygonShape)fixture.Shape).Vertices);
                    verticesCopy.Scale(scale);
                    shapeCopy = new PolygonShape(verticesCopy, fixture.Shape.Density);
                    break;

                // TODO: support other shape types
                default:
                    throw new NotSupportedException();
                }

                FixtureTemplate fixtureCopy = new FixtureTemplate();
                fixtureCopy.Shape = shapeCopy;
                fixtures.Add(fixtureCopy);
            }

            BodyTemplate newBodyTemplate = new BodyTemplate();

            newBodyTemplate.Fixtures = fixtures;

            return(newBodyTemplate);
        }
コード例 #3
0
        public CreatureType process(RawCreatureType raw)
        {
            CreatureType type = new CreatureType(raw);

            if (!typeMap.templates.ContainsKey(raw.bodyTemplate))
            {
                Debug.LogWarning("Creature " + type.name + " has invalid body template " + raw.bodyTemplate);
                return(null);
            }

            // if(type.combinedAppearance != null) type.combinedAppearance.process();

            // Arrays.stream(GameplayStatEnum.values())
            //     .forEach(value -> type.statMap.put(value, value.DEFAULT)); // save default values
            // for (String statName : raw.statMap.keySet()) { // override default values
            //     if (GameplayStatEnum.map.containsKey(statName)) {
            //         type.statMap.put(GameplayStatEnum.map.get(statName), raw.statMap.get(statName));
            //     } else {
            //         Logger.LOADING.logError("Invalid stat name " + statName + " in creature type " + raw.name);
            //     }
            // }
            BodyTemplate template = typeMap.templates[raw.bodyTemplate];

            foreach (var part in template.body.Values)
            {
                type.bodyParts.Add(part.name, part.clone());
            }
            foreach (var slot in template.slots)
            {
                type.slots.Add(slot.Key, new List <string>(slot.Value));
            }
            type.desiredSlots.AddRange(raw.desiredSlots);
            // type.needs.AddRange(defaultNeeds);
            return(type);
        }
コード例 #4
0
        public (CastRef <PhysicsObject>, PhysicsObject) Create(IScene scene)
        {
            // Scale vertices of body template
            BodyTemplate bodyTemplateCopy = BodyTemplate.Scale(Scale);

            PhysicsObject physicsObject = PhysicsObject ?? new PhysicsObject();

            physicsObject.Texture = Texture;
            physicsObject.Scale   = Scale;

            CastRef <PhysicsObject> poref = scene.SetupPhysicsObject(physicsObject, bodyTemplateCopy);

            physicsObject.Body.Position = Position;
            physicsObject.Body.Rotation = Rotation;
            physicsObject.Depth         = Depth;

            physicsObject.Body.Tag         = physicsObject;
            physicsObject.Body.LocalCenter = Vector2.Zero;

            CalculateVertices(physicsObject);

            if (!Offset.HasValue)
            {
                physicsObject.Offset = new Vector2(Texture.Width * 0.5f, Texture.Height * 0.5f);
            }

            return(poref, physicsObject);
        }
コード例 #5
0
            public static BodyTemplate Parse(MutagenFrame frame)
            {
                var subFrame = frame.GetSubrecordFrame();
                var version  = frame.MetaData.FormVersion !.Value;

                switch (subFrame.RecordTypeInt)
                {
                case RecordTypeInts.BODT:
                    if (version >= 44)
                    {
                        throw new ArgumentException("BODT type not expected on versions >= 44");
                    }
                    return(BodyTemplate.CreateFromBinary(frame));

                case RecordTypeInts.BOD2:
                    if (version < 43)
                    {
                        throw new ArgumentException("BOD2 type not expected on versions < 43");
                    }
                    if (version >= 44)
                    {
                        return(BodyTemplate.CreateFromBinary(frame));
                    }
                    frame.MetaData.FormVersion = 44;
                    var template = BodyTemplate.CreateFromBinary(frame);
                    template.ActsLike44        = true;
                    frame.MetaData.FormVersion = 43;
                    return(template);

                default:
                    throw new ArgumentException();
                }
            }
コード例 #6
0
 public BodyTemplateSelectModel(BodyTemplate bodyTemplate)
     : this()
 {
     Id          = bodyTemplate.Id;
     ImageUrl    = bodyTemplate.ImageUrl;
     Name        = bodyTemplate.Name;
     Description = bodyTemplate.Description;
 }
コード例 #7
0
 public BodyTemplateDownloadModel(BodyTemplate bodyTemplate) : this()
 {
     Id          = bodyTemplate.Id;
     ImageUrl    = bodyTemplate.ImageUrl.ToAbsoluteUrl();
     Name        = bodyTemplate.Name;
     Description = bodyTemplate.Description;
     Content     = bodyTemplate.Content;
 }
コード例 #8
0
ファイル: Body.cs プロジェクト: shiliupingGitHub/SFLFramework
        public Transform _xf; // the body origin transform

        internal Body(World world, BodyTemplate template)
        {
            FixtureList = new List <Fixture>(1);

            if (template.AllowCCD)
            {
                _flags |= BodyFlags.BulletFlag;
            }
            if (template.AllowRotation)
            {
                _flags |= BodyFlags.FixedRotationFlag;
            }
            if (template.AllowSleep)
            {
                _flags |= BodyFlags.AutoSleepFlag;
            }
            if (template.Awake)
            {
                _flags |= BodyFlags.AwakeFlag;
            }
            if (template.Active)
            {
                _flags |= BodyFlags.Enabled;
            }

            _world = world;

            _xf.p = template.Position;
            _xf.q.Set(template.Angle);

            _sweep.C0 = _xf.p;
            _sweep.C  = _xf.p;
            _sweep.A0 = template.Angle;
            _sweep.A  = template.Angle;

            _linearVelocity  = template.LinearVelocity;
            _angularVelocity = template.AngularVelocity;

            LinearDamping  = template.LinearDamping;
            AngularDamping = template.AngularDamping;
            GravityScale   = 1.0f;

            _type = template.Type;

            if (_type == BodyType.Dynamic)
            {
                _mass    = 1.0f;
                _invMass = 1.0f;
            }
            else
            {
                _mass    = 0.0f;
                _invMass = 0.0f;
            }

            UserData = template.UserData;
        }
コード例 #9
0
ファイル: World.cs プロジェクト: GolfNorth/VelcroPhysicsUnity
        internal Body CreateBody(BodyTemplate template)
        {
            var b = new Body(this, template);

            b.BodyId = _bodyIdCounter++;

            AddBody(b);
            return(b);
        }
コード例 #10
0
 public BodyTemplateManageModel(BodyTemplate bodyTemplate)
     : this()
 {
     Id          = bodyTemplate.Id;
     Name        = bodyTemplate.Name;
     ImageUrl    = bodyTemplate.ImageUrl;
     Description = bodyTemplate.Description;
     Content     = bodyTemplate.Content;
 }
コード例 #11
0
        public static Dictionary <string, BodyTemplate> LoadBodies(string xml)
        {
            Dictionary <string, BodyTemplate> results = new Dictionary <string, BodyTemplate>();

            XDocument bodyXml = XDocument.Parse(xml);

            float ptm = 1f / (float)Convert.ToDouble(bodyXml.XPathSelectElement("bodydef/metadata/ptm_ratio").Value);

            World world = new World();

            var xmlBodies = bodyXml.XPathSelectElements("bodydef/bodies/body");

            foreach (var xmlBody in xmlBodies)
            {
                var bodyName = xmlBody.Attribute("name").Value;

                BodyTemplate body = new BodyTemplate();
                results.Add(bodyName, body);

                var xmlFixtures = xmlBody.XPathSelectElements("fixtures/fixture");
                foreach (var xmlFixture in xmlFixtures)
                {
                    float density = (float)Convert.ToDouble(xmlFixture.XPathSelectElement("density").Value);

                    var xmlPolygons = xmlFixture.XPathSelectElements("polygons/polygon");
                    foreach (var xmlPolygon in xmlPolygons)
                    {
                        Vertices     vertices = new Vertices();
                        List <float> values   = xmlPolygon.Value.Split(',')
                                                .Select(x => (float)Convert.ToDouble(x.Trim())).ToList();

                        for (int i = 0; i < values.Count; i += 2)
                        {
                            vertices.Add(new Vector2(values[i], values[i + 1]) * ptm);
                        }

                        PolygonShape polygon = new PolygonShape(vertices, density);

                        FixtureTemplate fixture = new FixtureTemplate();
                        fixture.Shape = polygon;
                        body.Fixtures.Add(fixture);
                        body.Mass = 1;
                    }
                }

                var actualBody = body.Create(world);
                actualBody.BodyType = BodyType.Dynamic;
                foreach (var fixture in body.Fixtures)
                {
                    var polygon = (PolygonShape)fixture.Shape;
                    polygon.Vertices.Translate(-actualBody.LocalCenter);
                }
            }

            return(results);
        }
コード例 #12
0
        public static Body CreateBody(World world, Vector2 position = new Vector2(), float rotation = 0, BodyType bodyType = BodyType.Static, object userData = null)
        {
            BodyTemplate template = new BodyTemplate();

            template.Position = position;
            template.Angle    = rotation;
            template.Type     = bodyType;
            template.UserData = userData;

            return(world.CreateBody(template));
        }
コード例 #13
0
ファイル: BootstrapModal.cs プロジェクト: lurienanofab/lnf
        public void CreateBody(HtmlGenericControl parent)
        {
            HtmlGenericControl body = new HtmlGenericControl("div");

            body.Attributes.Add("class", "modal-body");
            if (BodyTemplate != null)
            {
                BodyTemplate.InstantiateIn(body);
            }
            parent.Controls.Add(body);
        }
コード例 #14
0
 /**
  * Creates body parts and links the between each other.
  */
 private void fillBodyParts(Dictionary <string, RawBodyPart> rawPartsMap, BodyTemplate bodyTemplate)
 {
     foreach (RawBodyPart rawPart in rawPartsMap.Values)   // create limbs
     {
         bodyTemplate.body.Add(rawPart.name, new BodyPart(rawPart));
     }
     foreach (BodyPart part in bodyTemplate.body.Values)   // link limbs
     {
         part.root = bodyTemplate.body[rawPartsMap[part.name].root];
     }
 }
コード例 #15
0
        public void CheckBodyTemplateHashingWorks()
        {
            BodyTemplate a = new BodyTemplate();
            BodyTemplate b = new BodyTemplate();
            BodyTemplate c = new BodyTemplate();
            BodyTemplate d = new BodyTemplate();
            BodyTemplate e = new BodyTemplate();

            a.Slots.Add("torso", BodyPartType.Torso);
            a.Slots.Add("left arm", BodyPartType.Arm);
            a.Connections.Add("torso", new List <string>()
            {
                "left arm"
            });
            a.CenterSlot = "torso";

            b.Slots.Add("left arm", BodyPartType.Arm);
            b.Slots.Add("torso", BodyPartType.Torso);
            b.Connections.Add("left arm", new List <string>()
            {
                "torso"
            });
            b.CenterSlot = "torso";

            c.Slots.Add("torso", BodyPartType.Head);
            c.Slots.Add("left arm", BodyPartType.Arm);
            c.Connections.Add("torso", new List <string>()
            {
                "left arm"
            });
            a.CenterSlot = "torso";

            d.Slots.Add("torso", BodyPartType.Torso);
            d.Slots.Add("left arm", BodyPartType.Arm);
            d.Slots.Add("left hand", BodyPartType.Hand);
            d.Connections.Add("left arm", new List <string>()
            {
                "left hand"
            });
            d.CenterSlot = "torso";

            e.Slots.Add("torso", BodyPartType.Torso);
            e.Slots.Add("left arm", BodyPartType.Arm);
            e.Slots.Add("left hand", BodyPartType.Hand);
            e.Connections.Add("left arm", new List <string>()
            {
                "torso"
            });
            e.CenterSlot = "left hand";

            Assert.That(a.Equals(b) && a.GetHashCode() != 0 && b.GetHashCode() != 0);
            Assert.That(!a.Equals(c) && a.GetHashCode() != 0 && c.GetHashCode() != 0);
            Assert.That(!d.Equals(e) && d.GetHashCode() != 0 && e.GetHashCode() != 0);
        }
コード例 #16
0
        public BodyTemplateDetailModel(BodyTemplate bodyTemplate)
            : this()
        {
            Id = bodyTemplate.Id;

            BodyTemplate = new BodyTemplateManageModel(bodyTemplate);

            ContentPreviewModel = new ContentPreviewModel(bodyTemplate.Content);

            Created      = bodyTemplate.Created;
            CreatedBy    = bodyTemplate.CreatedBy;
            LastUpdate   = bodyTemplate.LastUpdate;
            LastUpdateBy = bodyTemplate.LastUpdateBy;
        }
コード例 #17
0
        public bool Load()
        {
            using (var connection = DatabaseManager.Instance.GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM prans WHERE acc_id=@acc_id and item_id=@item_id";
                    command.Parameters.AddWithValue("@acc_id", Account.DbId);
                    command.Parameters.AddWithValue("@item_id", ItemId);
                    command.Prepare();

                    using (var reader = command.ExecuteReader())
                    {
                        if (!reader.Read())
                        {
                            return(false);
                        }

                        Id       = (ushort)(Account.ActiveCharacter.Connection.Id + 10240); // TODO - Find a way to use IdPranManager
                        DbId     = reader.GetUInt32("id");
                        Name     = reader.GetString("name");
                        Food     = reader.GetByte("food");
                        Devotion = reader.GetInt32("devotion");
                        Class    = (Profession)reader.GetInt16("class");
                        Personalities[Personality.Cute]      = reader.GetUInt16("p_cute");
                        Personalities[Personality.Smart]     = reader.GetUInt16("p_smart");
                        Personalities[Personality.Sexy]      = reader.GetUInt16("p_sexy");
                        Personalities[Personality.Energetic] = reader.GetUInt16("p_energetic");
                        Personalities[Personality.Tough]     = reader.GetUInt16("p_tough");
                        Personalities[Personality.Corrupt]   = reader.GetUInt16("p_corrupt");
                        Level        = reader.GetUInt16("level");
                        Hp           = reader.GetInt32("hp");
                        MaxHp        = reader.GetInt32("max_hp");
                        Mp           = reader.GetInt32("mp");
                        MaxMp        = reader.GetInt32("max_mp");
                        Experience   = reader.GetUInt32("xp");
                        DefPhy       = reader.GetUInt16("def_p");
                        DefMag       = reader.GetUInt16("def_m");
                        BodyTemplate = new BodyTemplate
                        {
                            Width = reader.GetByte("width"),
                            Chest = reader.GetByte("chest"),
                            Leg   = reader.GetByte("leg")
                        };
                        Position = MathUtils.CalculateNextFollowPosition(1, Account.ActiveCharacter.Position);
                    }
                }

            return(true);
        }
コード例 #18
0
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // header
            if (HeaderTemplate != null)
            {
                _headerTemplate = new HtmlGenericControl("header");
                _headerTemplate.Attributes.Add("class", "modal-header");
                HtmlGenericControl h2 = new HtmlGenericControl("h2");
                h2.Attributes.Add("class", "modal-title");
                _headerTemplate.Controls.Add(h2);
                this.Controls.Add(_headerTemplate);
                HeaderTemplate.InstantiateIn(h2);
            }

            // body with empty content by default
            _bodyTemplate = new HtmlGenericControl("div");
            _bodyTemplate.Attributes.Add("class", "modal-body");
            this.Controls.Add(_bodyTemplate);
            if (BodyTemplate != null)
            {
                BodyTemplate.InstantiateIn(_bodyTemplate);
            }

            // footer
            if (FooterTemplate != null)
            {
                _footerTemplate = new HtmlGenericControl("div");
                _footerTemplate.Attributes.Add("class", "modal-footer");
                this.Controls.Add(_footerTemplate);
                FooterTemplate.InstantiateIn(_footerTemplate);
            }

            try
            {
                Control target = Page.FindControlRecursive(this.AssociateControlID);

                if (target is WebControl wc)
                {
                    wc.Attributes["href"] = "#" + this.ClientID;
                    wc.AddCssClass(IsClosable ? "wb-lbx" : "wb-lbx lbx-modal");
                }
            }
            catch (Exception)
            {
                throw new Exception("AssociateControlID property for WetModal with ID " + this.ID + " should refer to an html control with the href attribute.");
            }
        }
コード例 #19
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = Vector2.Zero;

            _border = new Border(World, LineBatch, Framework.GraphicsDevice);

            BodyContainer bodyContainer = Framework.Content.Load <BodyContainer>("Pipeline/BreakableBody");
            BodyTemplate  bodyTemplate  = bodyContainer["Cookie"];

            if (!_isLoaded) //we flip vertices once.
            {
                foreach (FixtureTemplate f in bodyTemplate.Fixtures)
                {
                    var shape = (PolygonShape)f.Shape;
                    shape.Vertices.Scale(new Vector2(1f, -1f)); // flip Vert
                    shape.Vertices.Translate(new Vector2(-5.33f, 5.33f));
                }
                _isLoaded = true;
            }

            for (int i = 0; i < 3; i++)
            {
                List <Shape> shapes = new List <Shape>();
                foreach (FixtureTemplate f in bodyTemplate.Fixtures)
                {
                    shapes.Add(f.Shape);
                }
                _breakableCookie[i] = new tainicom.Aether.Physics2D.Common.PhysicsLogic.BreakableBody(World, shapes);

                _breakableCookie[i].Strength          = 120f;
                _breakableCookie[i].MainBody.Position = new Vector2(-15.0f + 15f * i, 0f);
            }

            _breakableSprite = new List <Sprite>();
            List <Texture2D> textures = ContentWrapper.BreakableTextureFragments(_breakableCookie[0], "Cookie", 24f);

            for (int i = 0; i < _breakableCookie[0].Parts.Count; i++)
            {
                AABB      bounds;
                Transform transform;
                _breakableCookie[0].Parts[i].Body.GetTransform(out transform);
                _breakableCookie[0].Parts[i].Shape.ComputeAABB(out bounds, ref transform, 0);
                Vector2 origin = 24f * (_breakableCookie[0].Parts[i].Body.Position - bounds.LowerBound);
                _breakableSprite.Add(new Sprite(textures[i], origin));
            }
            _completeSprite = new Sprite(ContentWrapper.GetTexture("Cookie"));
        }
コード例 #20
0
        CastRef <Ship> CreateShip(Texture2D shipTexture, BodyTemplate bodyTemplate, Vector2 position, Texture2D bulletTexture, BodyTemplate bulletTemplate, float health)
        {
            Ship ship = new Ship();

            ship.SetAssets(this, bulletTexture, bulletTemplate);
            ship.HealthAmount = health;

            PhysicsObjectTemplate template = new PhysicsObjectTemplate
            {
                Position      = position,
                BodyTemplate  = bodyTemplate,
                Texture       = shipTexture,
                PhysicsObject = ship
            };

            return(template.Create(this).Item1.Convert <Ship>());
        }
コード例 #21
0
        public override string GetTemplate(BodyTemplate template)
        {
            if (!string.IsNullOrEmpty(template.Body))
            {
                return(template.Body);
            }
            else if (template.Url != null)
            {
                if (cache.ContainsKey(template.Url))
                {
                    return(cache[template.Url]);
                }

                var templateBody = GetTemplateFromUrl(template.Url);
                cache[template.Url] = templateBody;
                return(templateBody);
            }

            return(string.Empty);
        }
コード例 #22
0
        private TemplatesTest()
        {
            BodyTemplate b1 = new BodyTemplate();

            b1.Type           = BodyType.Dynamic;
            b1.LinearVelocity = new Vector2(15.0f, 0.0f);

            Body body = BodyFactory.CreateFromTemplate(World, b1);

            //CircleShapeTemplate circle = new CircleShapeTemplate();
            //circle.Density = 1f;
            //circle.Radius = 2f;

            Shape circle = new CircleShape(2f, 2f);

            FixtureTemplate f1 = new FixtureTemplate();

            f1.Shape = circle;

            FixtureFactory.CreateFromTemplate(body, f1);
        }
コード例 #23
0
        public BodyTemplate process(RawBodyTemplate rawTemplate)
        {
            BodyTemplate template = new BodyTemplate(rawTemplate);

            log("processing " + rawTemplate.name + " body template");
            Dictionary <string, RawBodyPart> rawPartMap = rawTemplate.body
                                                          .ToDictionary(part => part.name, part => part); // part name to part

            log("    rawPartMap " + rawPartMap.Count + " " + rawPartMap.Keys);
            updateLimbsMirroringFlags(rawPartMap);
            log("    unmirrored slots " + rawTemplate.slots.Count);
            mirrorSlots(rawTemplate, rawPartMap);
            foreach (var slot in rawTemplate.slots)   // copy slots to new template
            {
                template.slots.Add(slot[0], slot.GetRange(1, slot.Count - 1));
            }
            log("    mirrored slots " + template.slots.Count + " " + template.slots.Keys);
            doubleMirroredParts(rawPartMap);
            log("    doubled parts " + rawPartMap.Count + " " + rawPartMap.Keys);
            fillBodyParts(rawPartMap, template);
            return(template);
        }
コード例 #24
0
        public override void ExposeData(ObjectSerializer serializer)
        {
            base.ExposeData(serializer);

            serializer.DataReadWriteFunction(
                "baseTemplate",
                "bodyTemplate.Humanoid",
                template =>
            {
                if (!_prototypeManager.TryIndex(template, out BodyTemplatePrototype prototype))
                {
                    // Invalid prototype
                    throw new InvalidOperationException(
                        $"No {nameof(BodyTemplatePrototype)} found with name {template}");
                }

                Template = new BodyTemplate();
                Template.Initialize(prototype);
            },
                () => Template.Name);

            serializer.DataReadWriteFunction(
                "basePreset",
                "bodyPreset.BasicHuman",
                preset =>
            {
                if (!_prototypeManager.TryIndex(preset, out BodyPresetPrototype prototype))
                {
                    // Invalid prototype
                    throw new InvalidOperationException(
                        $"No {nameof(BodyPresetPrototype)} found with name {preset}");
                }

                Preset = new BodyPreset();
                Preset.Initialize(prototype);
            },
                () => _presetName);
        }
コード例 #25
0
        private BodyScannerInterfaceState InterfaceState(BodyTemplate template, IReadOnlyDictionary <string, IBodyPart> bodyParts)
        {
            var partsData = new Dictionary <string, BodyScannerBodyPartData>();

            foreach (var(slotName, part) in bodyParts)
            {
                var mechanismData = new List <BodyScannerMechanismData>();

                foreach (var mechanism in part.Mechanisms)
                {
                    mechanismData.Add(new BodyScannerMechanismData(mechanism.Name, mechanism.Description,
                                                                   mechanism.RSIPath,
                                                                   mechanism.RSIState, mechanism.MaxDurability, mechanism.CurrentDurability));
                }

                partsData.Add(slotName,
                              new BodyScannerBodyPartData(part.Name, part.RSIPath, part.RSIState, part.MaxDurability,
                                                          part.CurrentDurability, mechanismData));
            }

            var templateData = new BodyScannerTemplateData(template.Name, template.Slots);

            return(new BodyScannerInterfaceState(partsData, templateData));
        }
コード例 #26
0
 public static Body CreateFromTemplate(World world, BodyTemplate bodyTemplate)
 {
     return(world.CreateBody(bodyTemplate));
 }
コード例 #27
0
 public void SetAssets(IScene scene, Texture2D bulletTexture, BodyTemplate bulletTemplate)
 {
     this.scene          = scene;
     this.bulletTexture  = bulletTexture;
     this.bulletTemplate = bulletTemplate;
 }
コード例 #28
0
        public CastRef <PhysicsObject> SetupPhysicsObject(PhysicsObject physicsObject, BodyTemplate bodyTemplate)
        {
            var body = bodyTemplate.Create(physicsWorld);

            body.BodyType        = BodyType.Dynamic;
            body.SleepingAllowed = false;

            physicsObject.Body = body;


            var entityRef = SetupGameObject(physicsObject);
            var poRef     = new CastRef <PhysicsObject>(entityRef);

            poRef.EntityRef.RegisterRemovedCallback(PhysicsObjectDestroyed);

            physicsObjects.Add(poRef);

            return(poRef);
        }
コード例 #29
0
 public abstract string GetTemplate(BodyTemplate template);
コード例 #30
0
        public override BodyContainer Process(List <RawBodyTemplate> input, ContentProcessorContext context)
        {
            if (ScaleFactor < 1)
            {
                throw new Exception("Pixel to meter ratio must be greater than zero.");
            }

            if (BezierIterations < 1)
            {
                throw new Exception("Cubic bézier iterations must be greater than zero.");
            }

            Matrix        matScale = Matrix.CreateScale(_scaleFactor, _scaleFactor, 1f);
            SVGPathParser parser   = new SVGPathParser(BezierIterations);
            BodyContainer bodies   = new BodyContainer();

            foreach (RawBodyTemplate rawBody in input)
            {
                if (rawBody.Name == "importer_default_path_container")
                {
                    continue;
                }

                BodyTemplate currentBody = new BodyTemplate();
                currentBody.Mass     = rawBody.Mass;
                currentBody.BodyType = rawBody.BodyType;
                foreach (RawFixtureTemplate rawFixture in rawBody.Fixtures)
                {
                    List <Polygon> paths = parser.ParseSVGPath(rawFixture.Path, rawFixture.Transformation * matScale);
                    for (int i = 0; i < paths.Count; i++)
                    {
                        if (paths[i].Closed)
                        {
                            List <Vertices> partition = Triangulate.ConvexPartition(paths[i].Vertices, TriangulationAlgorithm.Bayazit);
                            foreach (Vertices v in partition)
                            {
                                currentBody.Fixtures.Add(new FixtureTemplate
                                {
                                    Shape       = new PolygonShape(v, rawFixture.Density),
                                    Restitution = rawFixture.Restitution,
                                    Friction    = rawFixture.Friction,
                                    Name        = rawFixture.Name
                                });
                            }
                        }
                        else
                        {
                            Shape shape;
                            if (paths[i].Vertices.Count > 2)
                            {
                                shape = new ChainShape(paths[i].Vertices);
                            }
                            else
                            {
                                shape = new EdgeShape(paths[i].Vertices[0], paths[i].Vertices[1]);
                            }
                            currentBody.Fixtures.Add(new FixtureTemplate
                            {
                                Shape       = shape,
                                Restitution = rawFixture.Restitution,
                                Friction    = rawFixture.Friction,
                                Name        = rawFixture.Name
                            });
                        }
                    }
                }
                if (currentBody.Fixtures.Count > 0)
                {
                    bodies[rawBody.Name] = currentBody;
                    currentBody          = null;
                }
            }
            return(bodies);
        }