Ejemplo n.º 1
0
        public override void ReadDataXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            if (ele.TryPathTo("EditorID", false, out subEle))
            {
                if (EditorID == null)
                {
                    EditorID = new SimpleSubrecord <String>();
                }

                EditorID.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Model", false, out subEle))
            {
                if (Model == null)
                {
                    Model = new Model();
                }

                Model.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("NamedBodyParts", false, out subEle))
            {
                if (NamedBodyParts == null)
                {
                    NamedBodyParts = new List <NamedBodyPart>();
                }

                foreach (XElement e in subEle.Elements())
                {
                    NamedBodyPart tempBPTN = new NamedBodyPart();
                    tempBPTN.ReadXML(e, master);
                    NamedBodyParts.Add(tempBPTN);
                }
            }
            if (ele.TryPathTo("BodyParts", false, out subEle))
            {
                if (BodyParts == null)
                {
                    BodyParts = new List <BodyPart>();
                }

                foreach (XElement e in subEle.Elements())
                {
                    BodyPart tempBPNN = new BodyPart();
                    tempBPNN.ReadXML(e, master);
                    BodyParts.Add(tempBPNN);
                }
            }
            if (ele.TryPathTo("Ragdoll", false, out subEle))
            {
                if (Ragdoll == null)
                {
                    Ragdoll = new RecordReference();
                }

                Ragdoll.ReadXML(subEle, master);
            }
        }
Ejemplo n.º 2
0
        public void AddSnakeBody()
        {
            var snakeHead = BodyParts[BodyParts.Count - 1].DrawArea;
            var newTail   = new FilledRect(CalculateBodyDrawArea(snakeHead), color)
            {
                RenderLayer = 3
            };

            BodyParts.Add(newTail);
        }
Ejemplo n.º 3
0
        private void PlaceSnakeHead()
        {
            var startPosition = blockSize * (float)Math.Floor(gridSize / 2.0f);
            var firstPart     = new FilledRect(CalculateHeadDrawArea(startPosition), color)
            {
                RenderLayer = 3
            };

            BodyParts.Add(firstPart);
        }
Ejemplo n.º 4
0
        public void AddMesh(string bodyPartName, int groupid, Mesh mesh)
        {
            var g = BodyParts.FirstOrDefault(x => x.Name == bodyPartName);

            if (g == null)
            {
                g = new BodyPart(bodyPartName);
                BodyParts.Add(g);
            }
            g.AddMesh(groupid, mesh);
        }
Ejemplo n.º 5
0
        private void CreateBody()
        {
            BodyPart head = CreateBodyPart(AreaWidth / 2 + (int)(AreaWidth / 2 % BodyPartSize) - Convert.ToInt32(BodyPartSize) * 2, AreaWidth / 2 + (int)(AreaWidth / 2 % BodyPartSize), BodyPartSize, HeadColor);
            BodyPart body = CreateBodyPart(AreaWidth / 2 + (int)(AreaWidth / 2 % BodyPartSize) - Convert.ToInt32(BodyPartSize), AreaWidth / 2 + (int)(AreaWidth / 2 % BodyPartSize), BodyPartSize, BodyColor);
            BodyPart tail = CreateBodyPart(AreaWidth / 2 + (int)(AreaWidth / 2 % BodyPartSize), AreaWidth / 2 + (int)(AreaWidth / 2 % BodyPartSize), BodyPartSize, BodyColor);

            BodyParts.Add(head);
            BodyParts.Add(body);
            BodyParts.Add(tail);

            Directions.AddFirst(SnakeDirections.Left);
            Directions.AddFirst(SnakeDirections.Left);
            Directions.AddFirst(SnakeDirections.Left);

            CurrentDirection = SnakeDirections.Left;
        }
Ejemplo n.º 6
0
        public override void WriteObject(XmlWriter writer, object graph)
        {
            MtomData MtomDataField = ((MtomData)(graph));

            if (WriteParentElement(writer, true, true, graph))
            {
                if (WriteChildElement(writer, "Data", true, false, MtomDataField.Data))
                {
                    BodyParts.Add(CreateNewBodyPart(MtomDataField.Data, "<1@body>"));
                    writer.WriteStartElement("xop", "Include", "http://www.w3.org/2004/08/xop/include");
                    writer.WriteAttributeString(null, "href", null, "cid:1@body");
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            return;
        }
        public override void WriteObject(XmlWriter writer, object graph)
        {
            OneWayAttachmentRequest OneWayAttachmentRequestField = ((OneWayAttachmentRequest)(graph));

            if (WriteParentElement(writer, true, true, graph))
            {
                WriteAnyAttribute(writer, OneWayAttachmentRequestField.AnyAttr);
                if (WriteChildElement(writer, "Param", true, true, OneWayAttachmentRequestField.Param))
                {
                    BodyParts.Add(CreateNewBodyPart(OneWayAttachmentRequestField.Param, "<1@body>"));
                    writer.WriteStartElement("xop", "Include", "http://www.w3.org/2004/08/xop/include");
                    writer.WriteAttributeString(null, "href", null, "cid:1@body");
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                }
                WriteAnyElement(writer, OneWayAttachmentRequestField.Any, false);
                writer.WriteEndElement();
            }
            return;
        }
Ejemplo n.º 8
0
        public override void WriteObject(XmlWriter writer, object graph)
        {
            NestedClass NestedClassField = ((NestedClass)(graph));

            if (WriteParentElement(writer, true, true, graph))
            {
                MtomDataDataContractSerializer MTDataDCS = new MtomDataDataContractSerializer("MTData", "http://schemas.datacontract.org/2004/07/WcfMtomService", "http://schemas.datacontract.org/2004/07/WcfMtomService");
                MTDataDCS.BodyParts = this.BodyParts;
                MTDataDCS.WriteObject(writer, NestedClassField.MTData);
                if (WriteChildElement(writer, "MyData", true, false, NestedClassField.MyData))
                {
                    BodyParts.Add(CreateNewBodyPart(NestedClassField.MyData, "<2@body>"));
                    writer.WriteStartElement("xop", "Include", "http://www.w3.org/2004/08/xop/include");
                    writer.WriteAttributeString(null, "href", null, "cid:2@body");
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            return;
        }
Ejemplo n.º 9
0
        public void ExtendBody()
        {
            BodyPart newPart = new BodyPart();

            newPart.Color = BodyColor;
            newPart.Size  = BodyPartSize;

            switch (Directions.Last.Value)
            {
            case SnakeDirections.Up:
                newPart.StartPosition = new Point(
                    BodyParts[BodyParts.Count - 1].CurrentPosition.X,
                    BodyParts[BodyParts.Count - 1].CurrentPosition.Y + BodyPartSize);
                break;

            case SnakeDirections.Down:
                newPart.StartPosition = new Point(
                    BodyParts[BodyParts.Count - 1].CurrentPosition.X,
                    BodyParts[BodyParts.Count - 1].CurrentPosition.Y - BodyPartSize);
                break;

            case SnakeDirections.Left:
                newPart.StartPosition = new Point(
                    BodyParts[BodyParts.Count - 1].CurrentPosition.X + BodyPartSize,
                    BodyParts[BodyParts.Count - 1].CurrentPosition.Y);
                break;

            case SnakeDirections.Right:
                newPart.StartPosition = new Point(
                    BodyParts[BodyParts.Count - 1].CurrentPosition.X - BodyPartSize,
                    BodyParts[BodyParts.Count - 1].CurrentPosition.Y);
                break;
            }

            BodyParts.Add(newPart);
            Directions.AddLast(Directions.Last.Value);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Get the list of additional body parts from UncensorSelector and add them to the body parts list
        /// </summary>
        private static IEnumerator GetUncensorSelectorParts()
        {
            yield return(null);

            var uncensorSelectorType = Type.GetType($"KK_Plugins.UncensorSelector, {Constants.Prefix}_UncensorSelector");

            if (uncensorSelectorType == null)
            {
                yield break;
            }
            var uncensorSelectorObject = FindObjectOfType(uncensorSelectorType);

            if (uncensorSelectorObject == null)
            {
                yield break;
            }

            var AllAdditionalParts = Traverse.Create(uncensorSelectorObject).Field("AllAdditionalParts").GetValue <HashSet <string> >();

            foreach (var parts in AllAdditionalParts)
            {
                BodyParts.Add(parts);
            }
        }
Ejemplo n.º 11
0
        private void GenerateElements(Transform parent, BVHElement bvh)
        {
            GameObject bodyPartGO = new GameObject()
            {
                name = bvh.Name
            };

            bodyPartGO.transform.parent        = parent;
            bodyPartGO.transform.localPosition = bvh.Offset / 10f;
            BodyPart bodyPart = new BodyPart(bodyPartGO, bvh);

            bodyPart.SetLastFrame();
            BodyParts.Add(bodyPart);

            if (BodyData.bodySpec.ContainsKey(bvh.Name))
            {
                foreach (PrimitiveSpec ps in BodyData.bodySpec[bvh.Name].Shapes)
                {
                    GameObject go = GameObject.CreatePrimitive(ps.Type);
                    go.transform.parent        = bodyPart.GameObject.transform;
                    go.transform.localPosition = ps.Position;
                    go.transform.localRotation = ps.Rotation;
                    go.transform.localScale    = ps.Scale;
                    go.layer = 8; // Body
                    if (Material)
                    {
                        go.GetComponent <Renderer>().material = Material;
                    }
                }
            }

            foreach (BVHElement child in bvh.Children)
            {
                GenerateElements(bodyPart.GameObject.transform, child);
            }
        }
Ejemplo n.º 12
0
        private void Read(BinaryReader br, Dictionary <string, BinaryReader> sequenceGroups)
        {
            Header = new Header
            {
                ID             = ID.Idst,
                Version        = Version.Goldsource,
                Name           = br.ReadFixedLengthString(Encoding.ASCII, 64),
                Size           = br.ReadInt32(),
                EyePosition    = br.ReadVector3(),
                HullMin        = br.ReadVector3(),
                HullMax        = br.ReadVector3(),
                BoundingBoxMin = br.ReadVector3(),
                BoundingBoxMax = br.ReadVector3(),
                Flags          = br.ReadInt32()
            };

            // Read all the nums/offsets from the header
            var sections = new int[(int)Section.NumSections][];

            for (var i = 0; i < (int)Section.NumSections; i++)
            {
                var sec = (Section)i;

                int indexNum;
                if (sec == Section.Texture || sec == Section.Skin)
                {
                    indexNum = 3;
                }
                else
                {
                    indexNum = 2;
                }

                sections[i] = new int[indexNum];
                for (var j = 0; j < indexNum; j++)
                {
                    sections[i][j] = br.ReadInt32();
                }
            }

            // Bones
            var num      = SeekToSection(br, Section.Bone, sections);
            var numBones = num;

            for (var i = 0; i < num; i++)
            {
                var bone = new Bone
                {
                    Name          = br.ReadFixedLengthString(Encoding.ASCII, 32),
                    Parent        = br.ReadInt32(),
                    Flags         = br.ReadInt32(),
                    Controllers   = br.ReadIntArray(6),
                    Position      = br.ReadVector3(),
                    Rotation      = br.ReadVector3(),
                    PositionScale = br.ReadVector3(),
                    RotationScale = br.ReadVector3()
                };
                Bones.Add(bone);
            }

            // Bone controllers
            num = SeekToSection(br, Section.BoneController, sections);
            for (var i = 0; i < num; i++)
            {
                var boneController = new BoneController
                {
                    Bone  = br.ReadInt32(),
                    Type  = br.ReadInt32(),
                    Start = br.ReadSingle(),
                    End   = br.ReadSingle(),
                    Rest  = br.ReadInt32(),
                    Index = br.ReadInt32()
                };
                BoneControllers.Add(boneController);
            }

            // Hitboxes
            num = SeekToSection(br, Section.Hitbox, sections);
            for (var i = 0; i < num; i++)
            {
                var hitbox = new Hitbox
                {
                    Bone  = br.ReadInt32(),
                    Group = br.ReadInt32(),
                    Min   = br.ReadVector3(),
                    Max   = br.ReadVector3()
                };
                Hitboxes.Add(hitbox);
            }

            // Sequence groups
            num = SeekToSection(br, Section.SequenceGroup, sections);
            for (var i = 0; i < num; i++)
            {
                var group = new SequenceGroup
                {
                    Label = br.ReadFixedLengthString(Encoding.ASCII, 32),
                    Name  = br.ReadFixedLengthString(Encoding.ASCII, 64)
                };
                br.ReadBytes(8); // unused
                SequenceGroups.Add(group);
            }

            // Sequences
            num = SeekToSection(br, Section.Sequence, sections);
            for (var i = 0; i < num; i++)
            {
                var sequence = new Sequence
                {
                    Name                  = br.ReadFixedLengthString(Encoding.ASCII, 32),
                    Framerate             = br.ReadSingle(),
                    Flags                 = br.ReadInt32(),
                    Activity              = br.ReadInt32(),
                    ActivityWeight        = br.ReadInt32(),
                    NumEvents             = br.ReadInt32(),
                    EventIndex            = br.ReadInt32(),
                    NumFrames             = br.ReadInt32(),
                    NumPivots             = br.ReadInt32(),
                    PivotIndex            = br.ReadInt32(),
                    MotionType            = br.ReadInt32(),
                    MotionBone            = br.ReadInt32(),
                    LinearMovement        = br.ReadVector3(),
                    AutoMovePositionIndex = br.ReadInt32(),
                    AutoMoveAngleIndex    = br.ReadInt32(),
                    Min            = br.ReadVector3(),
                    Max            = br.ReadVector3(),
                    NumBlends      = br.ReadInt32(),
                    AnimationIndex = br.ReadInt32(),
                    BlendType      = br.ReadIntArray(2),
                    BlendStart     = br.ReadSingleArray(2),
                    BlendEnd       = br.ReadSingleArray(2),
                    BlendParent    = br.ReadInt32(),
                    SequenceGroup  = br.ReadInt32(),
                    EntryNode      = br.ReadInt32(),
                    ExitNode       = br.ReadInt32(),
                    NodeFlags      = br.ReadInt32(),
                    NextSequence   = br.ReadInt32()
                };

                var seqGroup = SequenceGroups[sequence.SequenceGroup];

                // Only load seqence group 0 for now (others are in other files)
                if (sequence.SequenceGroup == 0)
                {
                    var pos = br.BaseStream.Position;
                    sequence.Blends        = LoadAnimationBlends(br, sequence, numBones);
                    br.BaseStream.Position = pos;
                }
                else if (sequenceGroups.ContainsKey(seqGroup.Name))
                {
                    var reader = sequenceGroups[seqGroup.Name];
                    sequence.Blends = LoadAnimationBlends(reader, sequence, numBones);
                }

                Sequences.Add(sequence);
            }

            // Textures
            num = SeekToSection(br, Section.Texture, sections);
            var firstTextureIndex = Textures.Count;

            for (var i = 0; i < num; i++)
            {
                var texture = new Texture
                {
                    Name   = br.ReadFixedLengthString(Encoding.ASCII, 64),
                    Flags  = (TextureFlags)br.ReadInt32(),
                    Width  = br.ReadInt32(),
                    Height = br.ReadInt32(),
                    Index  = br.ReadInt32()
                };
                Textures.Add(texture);
            }

            // Texture data
            for (var i = firstTextureIndex; i < firstTextureIndex + num; i++)
            {
                var t = Textures[i];
                br.BaseStream.Position = t.Index;
                t.Data      = br.ReadBytes(t.Width * t.Height);
                t.Palette   = br.ReadBytes(256 * 3);
                Textures[i] = t;
            }

            // Skins
            var skinSection     = sections[(int)Section.Skin];
            var numSkinRefs     = skinSection[0];
            var numSkinFamilies = skinSection[1];

            br.BaseStream.Seek(skinSection[2], SeekOrigin.Begin);
            for (var i = 0; i < numSkinFamilies; i++)
            {
                var skin = new SkinFamily
                {
                    Textures = br.ReadShortArray(numSkinRefs)
                };
                Skins.Add(skin);
            }

            // Body parts
            num = SeekToSection(br, Section.BodyPart, sections);
            for (var i = 0; i < num; i++)
            {
                var part = new BodyPart
                {
                    Name       = br.ReadFixedLengthString(Encoding.ASCII, 64),
                    NumModels  = br.ReadInt32(),
                    Base       = br.ReadInt32(),
                    ModelIndex = br.ReadInt32()
                };
                var pos = br.BaseStream.Position;
                part.Models            = LoadModels(br, part);
                br.BaseStream.Position = pos;
                BodyParts.Add(part);
            }

            // Attachments
            num = SeekToSection(br, Section.Attachment, sections);
            for (var i = 0; i < num; i++)
            {
                var attachment = new Attachment
                {
                    Name    = br.ReadFixedLengthString(Encoding.ASCII, 32),
                    Type    = br.ReadInt32(),
                    Bone    = br.ReadInt32(),
                    Origin  = br.ReadVector3(),
                    Vectors = br.ReadVector3Array(3)
                };
                Attachments.Add(attachment);
            }

            // Transitions

            // Sounds & Sound groups aren't used
        }
Ejemplo n.º 13
0
        private void GenerateElements(Transform parent, BVHElement bvh)
        {
            GameObject bodyPartGO = new GameObject()
            {
                name = bvh.Name
            };

            bodyPartGO.transform.parent        = parent;
            bodyPartGO.transform.localPosition = bvh.Offset / 10f;

            BVHElementLimit bvhLimit   = bvhLimits.Limits[bvh.Name];
            float           meanXLimit = (bvhLimit.AngularXLow + bvhLimit.AngularXHigh) / 2f;
            float           meanYLimit = (bvhLimit.AngularYLow + bvhLimit.AngularYHigh) / 2f;
            float           meanZLimit = (bvhLimit.AngularZLow + bvhLimit.AngularZHigh) / 2f;

            bodyPartGO.transform.localRotation  = Quaternion.identity;
            bodyPartGO.transform.localRotation *= Quaternion.AngleAxis(meanXLimit, Vector3.right);
            bodyPartGO.transform.localRotation *= Quaternion.AngleAxis(meanYLimit, Vector3.up);
            bodyPartGO.transform.localRotation *= Quaternion.AngleAxis(meanZLimit, Vector3.forward);

            bodyPartGO.AddComponent <Rigidbody>();
            //bodyPartGO.GetComponent<Rigidbody>().useGravity = false;
            BodyPart bodyPart = new BodyPart(bodyPartGO, bvh);

            BodyParts.Add(bodyPart);

            if (BodyData.bodySpec.ContainsKey(bvh.Name))
            {
                foreach (PrimitiveSpec ps in BodyData.bodySpec[bvh.Name].Shapes)
                {
                    GameObject go = GameObject.CreatePrimitive(ps.Type);
                    go.transform.parent        = bodyPart.GameObject.transform;
                    go.transform.localPosition = ps.Position;
                    go.transform.localRotation = ps.Rotation;
                    go.transform.localScale    = ps.Scale;
                    go.layer = 8; // Body
                    if (Material)
                    {
                        go.GetComponent <Renderer>().material = Material;
                    }
                }

                if (bvh.Name != "Hips")
                {
                    bodyPartGO.AddComponent <ConfigurableJoint>();
                    ConfigurableJoint cj = bodyPartGO.GetComponent <ConfigurableJoint>();
                    cj.connectedBody = parent.GetComponent <Rigidbody>();
                    cj.xMotion       = ConfigurableJointMotion.Locked;
                    cj.yMotion       = ConfigurableJointMotion.Locked;
                    cj.zMotion       = ConfigurableJointMotion.Locked;
                    cj.anchor        = BodyData.bodySpec[bvh.Name].JointParameters.Anchor;

                    cj.angularXMotion   = ConfigurableJointMotion.Limited;
                    cj.angularYMotion   = ConfigurableJointMotion.Limited;
                    cj.angularZMotion   = ConfigurableJointMotion.Limited;
                    cj.lowAngularXLimit = new SoftJointLimit {
                        limit = bvhLimit.AngularXLow - meanXLimit
                    };
                    cj.highAngularXLimit = new SoftJointLimit {
                        limit = bvhLimit.AngularXHigh - meanXLimit
                    };
                    cj.angularYLimit = new SoftJointLimit {
                        limit = bvhLimit.AngularYHigh - meanYLimit
                    };
                    cj.angularZLimit = new SoftJointLimit {
                        limit = bvhLimit.AngularZHigh - meanZLimit
                    };
                }
            }

            foreach (BVHElement child in bvh.Children)
            {
                GenerateElements(bodyPart.GameObject.transform, child);
            }
        }
Ejemplo n.º 14
0
        public override void ReadData(ESPReader reader, long dataEnd)
        {
            while (reader.BaseStream.Position < dataEnd)
            {
                string subTag = reader.PeekTag();

                switch (subTag)
                {
                case "EDID":
                    if (EditorID == null)
                    {
                        EditorID = new SimpleSubrecord <String>();
                    }

                    EditorID.ReadBinary(reader);
                    break;

                case "MODL":
                    if (Model == null)
                    {
                        Model = new Model();
                    }

                    Model.ReadBinary(reader);
                    break;

                case "BPTN":
                    if (NamedBodyParts == null)
                    {
                        NamedBodyParts = new List <NamedBodyPart>();
                    }

                    NamedBodyPart tempBPTN = new NamedBodyPart();
                    tempBPTN.ReadBinary(reader);
                    NamedBodyParts.Add(tempBPTN);
                    break;

                case "BPNN":
                    if (BodyParts == null)
                    {
                        BodyParts = new List <BodyPart>();
                    }

                    BodyPart tempBPNN = new BodyPart();
                    tempBPNN.ReadBinary(reader);
                    BodyParts.Add(tempBPNN);
                    break;

                case "RAGA":
                    if (Ragdoll == null)
                    {
                        Ragdoll = new RecordReference();
                    }

                    Ragdoll.ReadBinary(reader);
                    break;

                default:
                    throw new Exception();
                }
            }
        }
Ejemplo n.º 15
0
        // ------------------------------------------------------------------------------------------------------------------------------------------------------------


        private bool InsertParts(List <BodyPart> pBodyParts, List <string> pPuppetTextures, out string pErrorText)
        {
            pErrorText = null;
            if ((pBodyParts == null) || (pBodyParts.Count == 0))
            {
                return(true);
            }

            bool insertOk = false;

            try
            {
                List <BodyModelSumDecal> puppetDecals = null;
                bool externDecalsReferenced           = false;
                foreach (BodyPart item in pBodyParts)
                {
                    BodyModelSumBodyPart part = new BodyModelSumBodyPart(_Archiver, PuppetName);

                    bool addNewPart;
                    List <BodyModelSumDecal> decals;
                    if (!part.ExtractData(item, pPuppetTextures, out addNewPart, out decals, out externDecalsReferenced, out pErrorText))
                    {
                        return(false);
                    }

                    if (addNewPart)
                    {
                        if (BodyParts == null)
                        {
                            BodyParts = new List <BodyModelSumBodyPart>();
                        }

                        BodyParts.Add(part);
                    }

                    if (decals != null)
                    {
                        if (puppetDecals == null)
                        {
                            puppetDecals = decals;
                        }
                        else
                        {
                            foreach (BodyModelSumDecal decal in puppetDecals)
                            {
                                if (!DecalAlreadyListed(decal))
                                {
                                    puppetDecals.Add(decal);
                                }
                            }
                        }
                    }
                }

                if ((puppetDecals != null) && (puppetDecals.Count > 0))
                {
                    Decals = puppetDecals.OrderBy(o => o.Group + o.DecalName).ToList();
                }
                ExternDecalReferenced = externDecalsReferenced;

                insertOk = true;
            }
            catch (Exception exception)
            {
                pErrorText = $"BodyModelSumPuppet.InsertParts(), EXCEPTION: {exception.Message}";
            }

            return(insertOk);
        }