Beispiel #1
0
 public Object(Bounding.IBounding bounding, float rotation, float scale)
 {
     IsColliding = false;
     IsOnGround = true;
     this.Bounding = bounding;
     Orientation = rotation;
     Scale = scale;
 }
 /// <summary>
 /// Writes a <see cref="Bounding"/> instance into the current stream.
 /// </summary>
 /// <param name="self">The extended <see cref="BinaryDataWriter"/>.</param>
 /// <param name="value">The <see cref="Bounding"/> instance.</param>
 public static void Write(this BinaryDataWriter self, Bounding value)
 {
     self.Write(value.Center);
     self.Write(value.Extent);
 }
Beispiel #3
0
 public static void ToLog <T>(this T[,] array, Bounding bounds, params string[] customContent)
 {
     ToLog(array, bounds, customContent);
 }
Beispiel #4
0
    protected bool PlaceMissingStair(bool up, Bounding otherStair, out Boxing placed)
    {
        Container2D <GenSpace> layout = Container.GetGrid();

        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printHeader(Logs.LevelGen, "Placing missing stair");
            BigBoss.Debug.w(Logs.LevelGen, "Up: " + up + ", other stair " + otherStair);
        }
        #endregion
        foreach (LayoutObject obj in Container.Flatten().Randomize(Rand))
        {
            #region DEBUG
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                obj.ToLog("Trying in.");
            }
            #endregion
            if (otherStair != null)
            {
                if (otherStair.GetCenter().Distance(obj.Bounding.GetCenter()) < MinStairDist)
                {
                    #region DEBUG
                    if (BigBoss.Debug.logging(Logs.LevelGen))
                    {
                        BigBoss.Debug.w(Logs.LevelGen, "Skipping due to distance to other stair.");
                    }
                    #endregion
                    continue;
                }
            }
            StairElement stair = Theme.Stair.SmartElement.Get(Rand) as StairElement;

            if (!stair.Place(layout, obj, Theme, Rand, out placed))
            {
                #region DEBUG
                if (BigBoss.Debug.logging(Logs.LevelGen))
                {
                    BigBoss.Debug.w(Logs.LevelGen, "No options.");
                }
                #endregion
                continue;
            }
            obj.DrawRect(placed, Draw.SetTo(up ? GridType.StairUp : GridType.StairDown, Theme).And(Draw.MergeIn(stair, Theme)));
            #region Debug
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                obj.ToLog(Logs.LevelGen, "Placed stairs");
                Container.ToLog(Logs.LevelGen, "Layout");
                BigBoss.Debug.printFooter("Placing Missing Stair");
            }
            #endregion
            return(true);
        }
        placed = null;
        #region Debug
        if (BigBoss.Debug.logging(Logs.LevelGen))
        {
            BigBoss.Debug.printFooter("Placing Missing Stair");
        }
        #endregion
        return(false);
    }
 /// <summary>
 /// RemoveHitbox Method, removes the selected hitbox.
 /// </summary>
 /// <param name="hitbox">Hitbox to remove.</param>
 public void RemoveHitbox(Bounding hitbox)
 {
     _hitboxes.Remove(hitbox);
 }
Beispiel #6
0
        public XElement SerializeToXml()
        {
            var rootElem = new XElement("LEGOPrimitive",
                                        new XAttribute("versionMajor", FileVersion.Major),
                                        new XAttribute("versionMinor", FileVersion.Minor));

            var annotations = rootElem.AddElement("Annotations");

            if (!Aliases.Contains(ID) && ID > 0)
            {
                Aliases.Add(ID);
            }

            if (Aliases.Any())
            {
                annotations.Add(new XElement("Annotation", new XAttribute("aliases", string.Join(";", Aliases))));
            }

            annotations.Add(new XElement("Annotation", new XAttribute("designname", Name)));

            if (MainGroup != null)
            {
                annotations.Add(new XElement("Annotation", new XAttribute("maingroupid", MainGroup.ID)));
                annotations.Add(new XElement("Annotation", new XAttribute("maingroupname", MainGroup.Name)));
            }

            if (Platform != null)
            {
                annotations.Add(new XElement("Annotation", new XAttribute("platformid", Platform.ID)));
                annotations.Add(new XElement("Annotation", new XAttribute("platformname", Platform.Name)));
            }

            annotations.Add(new XElement("Annotation", new XAttribute("version", PartVersion)));

            foreach (var extra in ExtraAnnotations)
            {
                annotations.Add(new XElement("Annotation", new XAttribute(extra.Key, extra.Value)));
            }

            if (Collisions.Any())
            {
                rootElem.Add(new XElement("Collision", Collisions.Select(x => x.SerializeToXml())));
            }

            if (Connectors.Any())
            {
                rootElem.Add(new XElement("Connectivity", Connectors.Select(x => x.SerializeToXml())));
            }

            if (PhysicsAttributes != null && !PhysicsAttributes.IsEmpty)
            {
                rootElem.Add(PhysicsAttributes.SerializeToXml());
            }

            if (Bounding != null)
            {
                var boundingElem = rootElem.AddElement("Bounding");
                boundingElem.Add(Bounding.SerializeToXml("AABB"));
            }

            if (GeometryBounding != null)
            {
                var boundingElem = rootElem.AddElement("GeometryBounding");
                boundingElem.Add(GeometryBounding.SerializeToXml("AABB"));
            }

            if (SubMaterials != null)
            {
                var decorationElem = rootElem.AddElement("Decoration");
                decorationElem.Add(new XAttribute("faces", SubMaterials.Length));
                decorationElem.Add(new XAttribute("subMaterialRedirectLookupTable", string.Join(",", SubMaterials)));
            }

            if (FlexBones.Any())
            {
                rootElem.Add(new XElement("Flex", FlexBones.Select(x => x.SerializeToXml())));
            }

            if (DefaultOrientation != null)
            {
                rootElem.Add(new XElement("DefaultOrientation", DefaultOrientation.ToXmlAttributes()));
            }

            if (DefaultCamera != null)
            {
                rootElem.Add(XmlHelper.DefaultSerialize(DefaultCamera, "DefaultCamera"));
            }

            foreach (var elem in rootElem.Descendants("Custom2DField"))
            {
                int depth = elem.AncestorsAndSelf().Count();
                elem.Value  = elem.Value.Indent(depth, "  ");
                elem.Value += StringExtensions.Tab(depth - 1, "  "); //fixes the closing tag indentation
            }

            if (ExtraElements != null)
            {
                foreach (var elem in ExtraElements)
                {
                    if (elem.Parent != null)
                    {
                        var parentElem = rootElem.Descendants().FirstOrDefault(x => x.Name.LocalName == elem.Parent.Name.LocalName);
                        //if (parentElem != null)
                        //    parentElem.Add(elem.)
                    }
                    else
                    {
                        rootElem.Add(elem);
                    }
                }
            }
            return(rootElem);
        }
Beispiel #7
0
        public static Shape SaveShape(FSHP fshp)
        {
            Shape ShapeU = new Shape();

            ShapeU.VertexSkinCount   = (byte)fshp.VertexSkinCount;
            ShapeU.Flags             = ShapeFlags.HasVertexBuffer;
            ShapeU.BoneIndex         = (ushort)fshp.BoneIndex;
            ShapeU.MaterialIndex     = (ushort)fshp.MaterialIndex;
            ShapeU.VertexBufferIndex = (ushort)fshp.VertexBufferIndex;
            ShapeU.KeyShapes         = new ResDict <KeyShape>();
            ShapeU.Name = fshp.Text;
            ShapeU.TargetAttribCount = (byte)fshp.TargetAttribCount;
            ShapeU.SubMeshBoundings  = new List <Bounding>();
            ShapeU.RadiusArray       = new List <float>();
            ShapeU.Meshes            = new List <Mesh>();

            foreach (ushort index in fshp.BoneIndices)
            {
                ShapeU.SkinBoneIndices.Add(index);
            }

            foreach (float radius in fshp.boundingRadius)
            {
                ShapeU.RadiusArray.Add(radius);
            }

            foreach (FSHP.BoundingBox box in fshp.boundingBoxes)
            {
                Bounding bnd = new Bounding();
                bnd.Center = new Syroot.Maths.Vector3F(box.Center.X, box.Center.Y, box.Center.Z);
                bnd.Extent = new Syroot.Maths.Vector3F(box.Extend.X, box.Extend.Y, box.Extend.Z);
                ShapeU.SubMeshBoundings.Add(bnd);
            }

            foreach (FSHP.LOD_Mesh mesh in fshp.lodMeshes)
            {
                Mesh msh = new Mesh();
                msh.SubMeshes     = new List <SubMesh>();
                msh.PrimitiveType = (GX2PrimitiveType)mesh.PrimitiveType;
                msh.FirstVertex   = mesh.FirstVertex;

                foreach (FSHP.LOD_Mesh.SubMesh sub in mesh.subMeshes)
                {
                    SubMesh subMesh = new SubMesh();
                    subMesh.Offset = sub.offset;
                    subMesh.Count  = (uint)mesh.faces.Count;
                    msh.SubMeshes.Add(subMesh);
                }

                IList <uint> faceList = new List <uint>();
                msh.IndexBuffer = new Syroot.NintenTools.Bfres.Buffer();
                foreach (int f in mesh.faces)
                {
                    faceList.Add((uint)f);
                }
                if (faceList.Count > 65000)
                {
                    MessageBox.Show($"Warning! Your poly count for a single mesh {fshp.Text} is pretty high! ({faceList.Count})." +
                                    $" You may want to split this!");
                    msh.SetIndices(faceList, GX2IndexFormat.UInt32);
                }
                else
                {
                    msh.SetIndices(faceList, GX2IndexFormat.UInt16);
                }

                ShapeU.Meshes.Add(msh);
                break;
            }
            return(ShapeU);
        }
Beispiel #8
0
 public Array2D(Bounding bounds)
     : this(bounds.Width, bounds.Height)
 {
     shift.x = bounds.XMin;
     shift.y = bounds.YMin;
 }
Beispiel #9
0
        internal override bool Cross(Bounding selectBound, Entity entity)
        {
            Arc arc = entity as Arc;

            if (arc == null)
            {
                return(false);
            }

            Bounding arcBounding = arc.Bounding;

            if (selectBound.Contains(arcBounding))
            {
                return(true);
            }

            if (!selectBound.IntersectWith(arcBounding))
            {
                return(false);
            }

            Circle   circle            = new Circle(arc.center, arc.radius);
            CADPoint nearestPntOnBound = new CADPoint(
                System.Math.Max(selectBound.left, System.Math.Min(circle.center.X, selectBound.right)),
                System.Math.Max(selectBound.bottom, System.Math.Min(circle.center.Y, selectBound.top)));

            if (CADPoint.Distance(nearestPntOnBound, circle.center) <= circle.radius)
            {
                double bdLeft   = selectBound.left;
                double bdRight  = selectBound.right;
                double bdTop    = selectBound.top;
                double bdBottom = selectBound.bottom;

                List <CADPoint> pnts = new List <CADPoint>();
                pnts.Add(new CADPoint(bdLeft, bdTop));
                pnts.Add(new CADPoint(bdLeft, bdBottom));
                pnts.Add(new CADPoint(bdRight, bdTop));
                pnts.Add(new CADPoint(bdRight, bdBottom));
                CADVector xp = new CADVector(1, 0);
                foreach (CADPoint pnt in pnts)
                {
                    if (CADPoint.Distance(pnt, circle.center) >= circle.radius)
                    {
                        CADVector v   = pnt - circle.center;
                        double    rad = CADVector.AngleInRadian(xp, v);
                        if (CADVector.Cross(xp, v) < 0)
                        {
                            rad = System.Math.PI * 2 - rad;
                        }

                        if (AngleInRange(rad, arc.startAngle, arc.endAngle))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            else
            {
                return(false);
            }
        }
Beispiel #10
0
        public Sphere3DEnvCubeMap(Vector3 position, float r) : base()
        {
            this.r = r;

            Bounding = new Bounding(this, r * 1.5f);

            if (vid is VertexsIndicesData)
            {
                VertexsIndicesData = vid;
            }
            else
            {
                vid = Tools.DeserializeModel(@"Models\sphere3D64x64x1.xml");
                //vid = Tools.DeserializeModel(@"Models\cube3D1x1.xml");
                VertexsIndicesData = vid;
            }


            Model = @"Models\Sphere3D.xml";

            //RotateU(MathHelper.PiOver2);

            Scale(r);

            Position = position;

            ShapeVersorsUVW = Matrix4.Identity;

            //GL.Disable(EnableCap.Texture2D);

            //GL.Enable(EnableCap.TextureCubeMap);

            // create cubemap

            int cubemapTexture = 0;

            cubemapTexture = GL.GenTexture();
            TextureID      = cubemapTexture;
            GL.BindTexture(TextureTarget.TextureCubeMap, cubemapTexture);
            //GL.TexStorage2D(TextureTarget2d.TextureCubeMap, 0, SizedInternalFormat.Rgba8, textSize, textSize);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            foreach (TextureTarget target in new TextureTarget[] {
                TextureTarget.TextureCubeMapPositiveX,
                TextureTarget.TextureCubeMapNegativeX,
                TextureTarget.TextureCubeMapPositiveY,
                TextureTarget.TextureCubeMapNegativeY,
                TextureTarget.TextureCubeMapPositiveZ,
                TextureTarget.TextureCubeMapNegativeZ,
            })
            {
                GL.TexImage2D(target, 0, PixelInternalFormat.Rgba8, textSize, textSize, 0,
                              PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            }

            // create FBO
            textureCubeFBO = new int[6];

            for (int i = 0; i < 6; i++)
            {
                GL.GenFramebuffers(1, out textureCubeFBO[i]);
            }

            GL.GenRenderbuffers(1, out textureCubeDepth);

            for (int i = 0; i < 6; i++)
            {
                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, textureCubeFBO[i]);
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt,
                                        FramebufferAttachment.ColorAttachment0Ext, TextureTarget.TextureCubeMapPositiveX, cubemapTexture, 0);

                GL.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, textureCubeDepth);
                GL.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, (RenderbufferStorage)All.DepthComponent24, textSize, textSize);
                GL.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt,
                                           RenderbufferTarget.RenderbufferExt, textureCubeDepth);
            }


            GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
            GL.BindTexture(TextureTarget.TextureCubeMap, 0);

            // initialize shaders
            string vs = File.ReadAllText("Shaders\\vShader_UV_Normal_CubeMap.txt");
            string fs = File.ReadAllText("Shaders\\fShader_UV_Normal_CubeMap.txt");

            Shader = new Shader(ref vs, ref fs, this);
            // initialize buffer
            VertexFormat = NRCGL.VertexFormat.XYZ_NORMAL;
            VertexBuffer = new VertexFloatBuffer(VertexFormat, 97920);
        }
Beispiel #11
0
 internal virtual bool Window(Bounding bounding, Entity entity)
 {
     return(bounding.Contains(entity.Bounding));
 }
Beispiel #12
0
 internal abstract bool Cross(Bounding bounding, Entity entity);
Beispiel #13
0
 void Prune()
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, "Prune");
     }
     #endregion
     Bounding bounds = new Bounding();
     foreach (Value2D <GenSpace> g in List)
     {
         bounds.Absorb(g);
     }
     Array2D <int> indexes          = new Array2D <int>(bounds);
     List <Value2D <GenSpace> > tmp = new List <Value2D <GenSpace> >(List);
     int index = 0;
     foreach (Value2D <GenSpace> val in tmp)
     { // For each point on the path
         int           lastDiff = 0;
         Value2D <int> neighbor = null;
         indexes.DrawAround(val.x, val.y, false, (arr2, x, y) =>
         { // Find neighboring point on path with the largest distance from current
             if (arr2[x, y] == 0)
             {
                 return(true);
             }
             int valDiff = Mathf.Abs(index - arr2[x, y]);
             if (valDiff > 1 && // Diff meets requirements
                 (neighbor == null || lastDiff < valDiff))    // Larger than last found diff
             {
                 lastDiff = valDiff;
                 neighbor = new Value2D <int>(x, y, arr2[x, y]);
             }
             return(true);
         });
         #region DEBUG
         if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
         {
             BigBoss.Debug.w(Logs.LevelGen, "Evaluating " + val);
             if (neighbor != null)
             {
                 BigBoss.Debug.w(Logs.LevelGen, "Found Neighbor " + neighbor);
             }
         }
         #endregion
         if (neighbor != null)
         { // If point of interest exists, prune
             int fromIndex = neighbor.val + 1;
             int count     = index - neighbor.val - 1;
             // Set indices to 0
             List <Value2D <GenSpace> > toRemove = List.GetRange(fromIndex, count);
             foreach (Value2D <GenSpace> r in toRemove)
             {
                 indexes[r.x, r.y] = 0;
             }
             // Remove
             List.RemoveRange(fromIndex, count);
             // Set next index to proper number
             index = neighbor.val + 1;
             #region DEBUG
             if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
             {
                 BigBoss.Debug.w(Logs.LevelGen, "Removed index: " + fromIndex + " count: " + count);
                 MultiMap <GridType> map = new MultiMap <GridType>();
                 foreach (var v in List)
                 {
                     map[v] = v.val.Type;
                 }
                 map.ToLog(Logs.LevelGen);
             }
             #endregion
         }
         indexes[val.x, val.y] = index;
         index++;
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
     {
         BigBoss.Debug.printFooter(Logs.LevelGen, "Prune");
     }
     #endregion
 }
Beispiel #14
0
 public void ReadBoundings(byte[] memory)
 {
     Bounding b = new Bounding();
     b.Origin.X = BitConverter.ToSingle(memory, readerpos);
     b.Origin.Y = BitConverter.ToSingle(memory, readerpos + 4);
     b.Origin.Z = BitConverter.ToSingle(memory, readerpos + 8);
     b.Box.X = BitConverter.ToSingle(memory, readerpos + 12);
     b.Box.Y = BitConverter.ToSingle(memory, readerpos + 16);
     b.Box.Z = BitConverter.ToSingle(memory, readerpos + 20);
     b.R = BitConverter.ToSingle(memory, readerpos + 24);
     b.unk = new float[7];
     int pos = readerpos + 28;
     for (int i = 0; i < 7; i++)
     {
         b.unk[i] = BitConverter.ToSingle(memory, pos);
         pos += 4;
     }
     b.raw = new byte[56];
     for (int i = 0; i < 56; i++)
     {
         b.raw[i] = memory[readerpos];
         readerpos++;
     }
     Mesh.Bounds = b;
 }
            public void InjectMesh(Model input, Syroot.BinaryData.ByteOrder BO)
            {
                //Deal With Mesh
                uint[] theFaces = meshes[0].faces.ToArray();
                input.Shapes[0].Meshes[0].SetIndices(theFaces);
                if (input.Shapes[0].Meshes.Count != 1)
                {
                    for (int i = 0; i < input.Shapes[0].Meshes.Count; i++)
                    {
                        input.Shapes[0].Meshes.RemoveAt(1);
                    }
                }
                input.Shapes[0].Radius = 10000000000f;

                input.Shapes[0].Meshes[0].SubMeshes.Clear();
                Bounding LeeT = new Bounding();

                LeeT.Center = new Syroot.Maths.Vector3F(0, 0, 0);
                LeeT.Extent = new Syroot.Maths.Vector3F(10000000000f, 10000000000f, 10000000000f);
                for (int i = 0; i < input.Shapes[0].SubMeshBoundings.Count; i++)
                {
                    input.Shapes[0].SubMeshBoundings[i] = LeeT;
                }

                SubMesh Setup = new SubMesh();

                Setup.Count  = (uint)meshes[0].faces.Count;
                Setup.Offset = 0;
                for (int vvv = 0; vvv < 1; vvv++)
                {
                    input.Shapes[0].Meshes[0].SubMeshes.Add(Setup);
                }
                //input.Shapes[0].Name = meshes[0].Name;
                //Deal with Vertexes
                VertexBufferHelper helper               = new VertexBufferHelper(input.VertexBuffers[0], BO);
                List <VertexBufferHelperAttrib> atrib   = new List <VertexBufferHelperAttrib>();
                VertexBufferHelperAttrib        vertPos = new VertexBufferHelperAttrib();

                vertPos.Name   = "_p0";
                vertPos.Data   = meshes[0].verts.ToArray();
                vertPos.Format = Syroot.NintenTools.Bfres.GX2.GX2AttribFormat.Format_16_16_16_16_Single;
                VertexBufferHelperAttrib vertUV = new VertexBufferHelperAttrib();

                vertUV.Name   = "_u0";
                vertUV.Data   = meshes[0].uvs.ToArray();
                vertUV.Format = Syroot.NintenTools.Bfres.GX2.GX2AttribFormat.Format_16_16_Single;
                VertexBufferHelperAttrib vertUV1 = new VertexBufferHelperAttrib();

                //Add UV Layer 1. Copies UVs from UV0 for now.
                vertUV1.Name   = "_u1";
                vertUV1.Data   = meshes[0].uvs.ToArray();
                vertUV1.Format = Syroot.NintenTools.Bfres.GX2.GX2AttribFormat.Format_16_16_Single;
                VertexBufferHelperAttrib vertNorm = new VertexBufferHelperAttrib();

                vertNorm.Name   = "_n0";
                vertNorm.Data   = meshes[0].norms.ToArray();
                vertNorm.Format = Syroot.NintenTools.Bfres.GX2.GX2AttribFormat.Format_10_10_10_2_SNorm;
                VertexBufferHelperAttrib vertWeight = new VertexBufferHelperAttrib();

                //Adds weights. Becomes Zeroed
                vertWeight.Name   = "_w0";
                vertWeight.Data   = meshes[0].uvs.ToArray();
                vertWeight.Format = Syroot.NintenTools.Bfres.GX2.GX2AttribFormat.Format_8_8_8_8_UNorm;
                VertexBufferHelperAttrib vertIndex = new VertexBufferHelperAttrib();

                //Adds Index attirbute. Becomes Zeroed
                vertIndex.Name   = "_i0";
                vertIndex.Data   = meshes[0].uvs.ToArray();
                vertIndex.Format = Syroot.NintenTools.Bfres.GX2.GX2AttribFormat.Format_8_8_8_8_UInt;
                VertexBufferHelperAttrib vertTan = new VertexBufferHelperAttrib();

                //Adds Tangent attirbute. Becomes Zeroed
                vertTan.Name   = "_t0";
                vertTan.Data   = meshes[0].uvs.ToArray();
                vertTan.Format = Syroot.NintenTools.Bfres.GX2.GX2AttribFormat.Format_8_8_8_8_SNorm;
                atrib.Add(vertPos);
                atrib.Add(vertNorm);
                atrib.Add(vertUV);
                atrib.Add(vertUV1);
                atrib.Add(vertWeight);
                atrib.Add(vertIndex);
                atrib.Add(vertTan);
                helper.Attributes      = atrib;
                input.VertexBuffers[0] = helper.ToVertexBuffer();
            }
Beispiel #16
0
        internal override bool Cross(Bounding selectBound, Entity entity)
        {
            Arc arc = entity as Arc;

            if (arc == null)
            {
                return(false);
            }

            Bounding arcBounding = arc.bounding;

            if (selectBound.Contains(arcBounding))
            {
                return(true);
            }

            if (!selectBound.IntersectWith(arcBounding))
            {
                return(false);
            }

            Circle circle = new Circle(arc.center, arc.radius);

            LitMath.Vector2 nearestPntOnBound = new LitMath.Vector2(
                Math.Max(selectBound.left, Math.Min(circle.center.x, selectBound.right)),
                Math.Max(selectBound.bottom, Math.Min(circle.center.y, selectBound.top)));

            if (LitMath.Vector2.Distance(nearestPntOnBound, circle.center) <= circle.radius)
            {
                double bdLeft   = selectBound.left;
                double bdRight  = selectBound.right;
                double bdTop    = selectBound.top;
                double bdBottom = selectBound.bottom;

                List <LitMath.Vector2> pnts = new List <LitMath.Vector2>();
                pnts.Add(new LitMath.Vector2(bdLeft, bdTop));
                pnts.Add(new LitMath.Vector2(bdLeft, bdBottom));
                pnts.Add(new LitMath.Vector2(bdRight, bdTop));
                pnts.Add(new LitMath.Vector2(bdRight, bdBottom));
                LitMath.Vector2 xp = new LitMath.Vector2(1, 0);
                foreach (LitMath.Vector2 pnt in pnts)
                {
                    if (LitMath.Vector2.Distance(pnt, circle.center) >= circle.radius)
                    {
                        LitMath.Vector2 v   = pnt - circle.center;
                        double          rad = LitMath.Vector2.AngleInRadian(xp, v);
                        if (LitMath.Vector2.Cross(xp, v) < 0)
                        {
                            rad = Math.PI * 2 - rad;
                        }

                        if (AngleInRange(rad, arc.startAngle, arc.endAngle))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            else
            {
                return(false);
            }
        }
Beispiel #17
0
 public Boxing(Bounding rhs, GridLocation front)
     : base(rhs)
 {
     this.Front = front;
 }
Beispiel #18
0
        public void ReadSections(ref BinaryStream s)
        {
            SectionHeader section = new SectionHeader(ref s);

            currentSection = section;

            s.BaseStream.Position -= 8;

            switch (section.signature)
            {
            case "lyt1":
                layoutSettings = new LayoutSettings(ref s);

                System.Windows.Forms.MessageBox.Show($"Read Layout Settings [{section.signature}]");

                layoutSettings.sectionHeader = section;
                break;

            case "txl1":
                textureList = new TextureList(ref s);

                System.Windows.Forms.MessageBox.Show($"Read Texture List [{section.signature}]");

                layoutSettings.sectionHeader = section;
                break;

            case "fnl1":
                fontList = new FontList(ref s);

                System.Windows.Forms.MessageBox.Show($"Read Font List [{section.signature}]");

                layoutSettings.sectionHeader = section;
                break;

            case "mat1":
                materialList = new MaterialList(ref s);

                System.Windows.Forms.MessageBox.Show($"Read Material List [{section.signature}]");

                layoutSettings.sectionHeader = section;
                break;

            case "pan1":
                Pane pane = new Pane(ref s);

                if (rootPane == null)
                {
                    rootPane = pane;
                }

                if (parentPane != null)
                {
                    if (parentPane.children == null)
                    {
                        parentPane.children = new List <dynamic>();
                    }

                    parentPane.children.Add(pane);

                    pane.parent = parentPane;
                }

                lastPane = pane;

                System.Windows.Forms.MessageBox.Show($"Read Pane [{section.signature}]");

                lastPane.sectionHeader = section;
                break;

            case "pic1":
                Picture pic = new Picture(ref s);

                if (parentPane != null)
                {
                    if (parentPane.children == null)
                    {
                        parentPane.children = new List <dynamic>();
                    }

                    parentPane.children.Add(pic);

                    pic.parent = parentPane;
                }

                lastPane = pic;

                System.Windows.Forms.MessageBox.Show($"Read Picture Pane [{section.signature}]");

                lastPane.sectionHeader = section;
                break;

            case "txt1":
                TextBox txt = new TextBox(ref s);

                if (parentPane != null)
                {
                    if (parentPane.children == null)
                    {
                        parentPane.children = new List <dynamic>();
                    }

                    parentPane.children.Add(txt);

                    txt.parent = parentPane;
                }

                lastPane = txt;

                System.Windows.Forms.MessageBox.Show($"Read TextBox Pane [{section.signature}]");

                lastPane.sectionHeader = section;
                break;

            case "wnd1":
                Window wnd = new Window(ref s);

                if (parentPane != null)
                {
                    if (parentPane.children == null)
                    {
                        parentPane.children = new List <dynamic>();
                    }

                    parentPane.children.Add(wnd);

                    wnd.parent = parentPane;
                }

                lastPane = wnd;

                System.Windows.Forms.MessageBox.Show($"Read Window Pane [{section.signature}]");

                lastPane.sectionHeader = section;
                break;

            case "bnd1":
                Bounding bnd = new Bounding(ref s);

                if (parentPane != null)
                {
                    if (parentPane.children == null)
                    {
                        parentPane.children = new List <dynamic>();
                    }

                    parentPane.children.Add(bnd);

                    bnd.parent = parentPane;
                }

                lastPane = bnd;

                System.Windows.Forms.MessageBox.Show($"Read Bounding Pane [{section.signature}]");

                lastPane.sectionHeader = section;
                break;

            case "cpt1":
                Capture cpt = new Capture(ref s);

                if (parentPane != null)
                {
                    if (parentPane.children == null)
                    {
                        parentPane.children = new List <dynamic>();
                    }

                    parentPane.children.Add(cpt);

                    cpt.parent = parentPane;
                }

                lastPane = cpt;

                System.Windows.Forms.MessageBox.Show($"Read Capture Pane [{section.signature}]");

                lastPane.sectionHeader = section;
                break;

            case "prt1":
                s.ReadBytes(section.size);
                break;

            case "ali1":
                Alignment ali = new Alignment(ref s);     // Read Alignment Pane later

                if (parentPane != null)
                {
                    if (parentPane.children == null)
                    {
                        parentPane.children = new List <dynamic>();
                    }

                    parentPane.children.Add(ali);

                    ali.parent = parentPane;
                }

                lastPane = ali;

                System.Windows.Forms.MessageBox.Show($"Read Alignment Pane [{section.signature}]");

                lastPane.sectionHeader = section;
                break;

            case "scr1":
                Scissor scr = new Scissor(ref s);

                if (parentPane != null)
                {
                    if (parentPane.children == null)
                    {
                        parentPane.children = new List <dynamic>();
                    }

                    parentPane.children.Add(scr);

                    scr.parent = parentPane;
                }

                lastPane = scr;

                System.Windows.Forms.MessageBox.Show($"Read Scissor Pane [{section.signature}]");

                lastPane.sectionHeader = section;
                break;

            case "pas1":
                if (lastPane != null)
                {
                    parentPane = lastPane;
                }

                s.ReadBytes(8);
                break;

            case "pae1":
                lastPane   = parentPane;
                parentPane = lastPane != null ? lastPane.parent : null;

                s.ReadBytes(8);
                break;

            case "grp1":
                Group group = new Group(ref s);

                if (rootGroup == null)
                {
                    rootGroup = group;
                }

                if (parentGroup != null)
                {
                    if (parentGroup.children == null)
                    {
                        parentGroup.children = new List <Group>();
                    }

                    parentGroup.children.Add(group);

                    group.parent = parentGroup;
                }

                lastGroup = group;

                System.Windows.Forms.MessageBox.Show($"Read Group [{section.signature}]");

                lastGroup.sectionHeader = section;
                break;

            case "grs1":
                if (lastGroup != null)
                {
                    parentGroup = lastGroup;
                }

                s.ReadBytes(8);
                break;

            case "gre1":
                lastGroup   = parentGroup;
                parentGroup = lastGroup != null ? lastGroup.parent : null;

                s.ReadBytes(8);
                break;

            case "usd1":     // Temporary
                s.ReadBytes(section.size);
                break;

            case "cnt1":     // Temporary
                s.ReadBytes(section.size);
                break;
            }
        }
Beispiel #19
0
 public static extern BoolType IsROIMatch(ref ImageInfo frame, Bounding roi, [InAttribute()][MarshalAsAttribute(UnmanagedType.LPStr)] string objFileName);
Beispiel #20
0
 public UStaticMesh(byte[] mem,string[] Names)
 {
     memory = mem;
     memsize = memory.Length;
     names = Names;
     OProps = new List<Property>();
     RawFaces = new List<RawFace>();
     Materials = new List<Material>();
     Vertices = new List<Vector>();
     UVSets = new List<UVSet>();
     bound = new Bounding();
     Deserialize();
 }
Beispiel #21
0
        public static Shape SaveShape(FSHP fshp)
        {
            Shape ShapeU = new Shape();

            ShapeU.VertexSkinCount   = (byte)fshp.VertexSkinCount;
            ShapeU.Flags             = ShapeFlags.HasVertexBuffer;
            ShapeU.BoneIndex         = (ushort)fshp.BoneIndex;
            ShapeU.MaterialIndex     = (ushort)fshp.MaterialIndex;
            ShapeU.VertexBufferIndex = (ushort)fshp.VertexBufferIndex;
            ShapeU.KeyShapes         = new ResDict <KeyShape>();
            ShapeU.Name = fshp.Text;
            ShapeU.TargetAttribCount = (byte)fshp.TargetAttribCount;
            ShapeU.SubMeshBoundings  = new List <Bounding>();
            ShapeU.RadiusArray       = new List <float>();
            ShapeU.Meshes            = new List <Mesh>();

            foreach (ushort index in fshp.BoneIndices)
            {
                ShapeU.SkinBoneIndices.Add(index);
            }

            foreach (float radius in fshp.boundingRadius)
            {
                ShapeU.RadiusArray.Add(radius);
            }

            foreach (FSHP.BoundingBox box in fshp.boundingBoxes)
            {
                Bounding bnd = new Bounding();
                bnd.Center = new Syroot.Maths.Vector3F(box.Center.X, box.Center.Y, box.Center.Z);
                bnd.Extent = new Syroot.Maths.Vector3F(box.Extend.X, box.Extend.Y, box.Extend.Z);
                ShapeU.SubMeshBoundings.Add(bnd);
            }

            foreach (FSHP.LOD_Mesh mesh in fshp.lodMeshes)
            {
                Mesh msh = new Mesh();
                msh.SubMeshes = new List <SubMesh>();
                switch (mesh.PrimativeType)
                {
                case STPrimitiveType.Triangles:
                    msh.PrimitiveType = GX2PrimitiveType.Triangles;
                    break;

                case STPrimitiveType.TrangleStrips:
                    msh.PrimitiveType = GX2PrimitiveType.TriangleStrip;
                    break;

                case STPrimitiveType.Quads:
                    msh.PrimitiveType = GX2PrimitiveType.Quads;
                    break;

                case STPrimitiveType.Lines:
                    msh.PrimitiveType = GX2PrimitiveType.Lines;
                    break;

                case STPrimitiveType.LineStrips:
                    msh.PrimitiveType = GX2PrimitiveType.LineStrip;
                    break;

                case STPrimitiveType.Points:
                    msh.PrimitiveType = GX2PrimitiveType.Points;
                    break;
                }
                msh.FirstVertex = mesh.FirstVertex;

                foreach (FSHP.LOD_Mesh.SubMesh sub in mesh.subMeshes)
                {
                    SubMesh subMesh = new SubMesh();
                    subMesh.Offset = sub.offset;
                    subMesh.Count  = (uint)mesh.faces.Count;
                    msh.SubMeshes.Add(subMesh);
                }

                IList <uint> faceList = new List <uint>();
                msh.IndexBuffer = new Syroot.NintenTools.Bfres.Buffer();
                foreach (int f in mesh.faces)
                {
                    faceList.Add((uint)f);
                }
                if (faceList.Count > 65000)
                {
                    msh.SetIndices(faceList, GX2IndexFormat.UInt32);
                }
                else
                {
                    msh.SetIndices(faceList, GX2IndexFormat.UInt16);
                }

                ShapeU.Meshes.Add(msh);
            }
            return(ShapeU);
        }
Beispiel #22
0
 public SquareFinder(Container2D <T> arr, int width, int height, bool tryFlipped, StrokedAction <T> tester, Bounding scope = null)
 {
     _arr        = arr;
     _width      = width;
     _height     = height;
     _tryFlipped = tryFlipped && width != height;
     _tester     = tester;
     _scope      = scope;
     if (scope == null)
     {
         _scope = arr.Bounding;
     }
 }
Beispiel #23
0
 public void ReadBoundings(byte[] memory)
 {
     TreeNode res = new TreeNode("Bounding pos: 0x" + readerpos.ToString("X4"));
     Bounding b = new Bounding();
     b.Origin.X = BitConverter.ToSingle(memory, readerpos);
     b.Origin.Y = BitConverter.ToSingle(memory, readerpos + 4);
     b.Origin.Z = BitConverter.ToSingle(memory, readerpos + 8);
     b.Box.X = BitConverter.ToSingle(memory, readerpos + 12);
     b.Box.Y = BitConverter.ToSingle(memory, readerpos + 16);
     b.Box.Z = BitConverter.ToSingle(memory, readerpos + 20);            
     Meshplorer.Preview3D.Cubes = new List<Meshplorer.Preview3D.DXCube>();
     Meshplorer.Preview3D.DXCube c = Meshplorer.Preview3D.NewCubeByOrigSize(b.Origin - b.Box, b.Box * 2.0f, 0);
     Meshplorer.Preview3D.CamDistance = (float)Math.Sqrt(b.Box.X * b.Box.X + b.Box.Y * b.Box.Y + b.Box.Z * b.Box.Z) * 2;
     Meshplorer.Preview3D.Cubes.Add(c);
     b.R = BitConverter.ToSingle(memory, readerpos + 24);
     b.unk = new float[7];
     int pos = readerpos + 28;
     string unk = "Unknown{";
     for (int i = 0; i < 7; i++)
     {
         b.unk[i] = BitConverter.ToSingle(memory, pos);
         unk += b.unk[i].ToString() + " ";
         pos += 4;
     }
     unk += "}";
     b.raw = new byte[56];
     for (int i = 0; i < 56; i++)
     {
         b.raw[i] = memory[readerpos];
         readerpos++;
     }
     res.Nodes.Add(new TreeNode("Origin: {" + b.Origin.X.ToString() + " ; " + b.Origin.Y.ToString() + " ; " + b.Origin.Z.ToString() + "}"));
     res.Nodes.Add(new TreeNode("Box: {" + b.Box.X.ToString() + " ; " + b.Box.Y.ToString() + " ; " + b.Box.Z.ToString() + "}"));
     res.Nodes.Add(new TreeNode("Radius: {" + b.R.ToString() + "}"));
     res.Nodes.Add(unk);
     b.t = res;
     Mesh.Bounds = b;
 }
Beispiel #24
0
 /// <summary>
 /// AddHitbox Method, adds the provided hitbox to the list.
 /// </summary>
 /// <param name="hitbox">Hitbox to add.</param>
 public void AddHitbox(Bounding hitbox)
 {
     _hitboxes.Add(hitbox);
 }