コード例 #1
0
ファイル: InternalModel.cs プロジェクト: sibeansa/Components
        /// <summary>
        /// Loads this class with data from a primitive.
        /// </summary>
        /// <param name="graphicsDevice">The graphicsDevice device.</param>
        /// <param name="primitive">The primitive to load.</param>
        public void FromPrimitive(GraphicsDevice graphicsDevice, Geometric primitive)
        {
            List <Mesh> meshes = new List <Mesh>();

            // Get Initial BoundingBox
            var min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            var max = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            var primitiveVertices = primitive.Vertices;

            for (int i = 0; i < primitiveVertices.Length; i++)
            {
                Vector3 vertex = primitiveVertices[i].Position;

                Vector3.Min(ref vertex, ref min, out min);
                Vector3.Max(ref vertex, ref max, out max);
            }

            BoundingBox bbox = new Common.Math.BoundingBox(min, max);

            // Load Primitive
            int vertexCount    = primitive.Vertices.Length;
            int indexCount     = primitive.Indices.Length;
            int primitiveCount = indexCount / 3;

            var meshVBuffer = new VertexBuffer(VertexPositionNormalTangentColorDualTexture.VertexFormat);

            meshVBuffer.SetData(primitive.ByteVertices, vertexCount);
            var meshIBuffer = new IndexBuffer(primitive.Indices);

            var baseMesh = new Mesh(0, vertexCount, 0, primitiveCount, meshVBuffer, meshIBuffer, PrimitiveType.TriangleList);

            baseMesh.Name        = "Primitive";
            baseMesh.BoundingBox = bbox;
            meshes.Add(baseMesh);

            primitive.Dispose();

            this.BoundingBox = bbox;

            this.FromMeshes(graphicsDevice, meshes, bbox);
        }
コード例 #2
0
        /// <inheritdoc />
        protected override void RefreshBoundingBox()
        {
            var rect   = this.Transform2D.Rectangle;
            var origin = this.Transform2D.Origin;

            rect.X = -origin.X * rect.Width;
            rect.Y = -origin.Y * rect.Height;

            BoundingBox boundingBox = new Common.Math.BoundingBox();

            boundingBox.Min.X = rect.Left;
            boundingBox.Min.Y = rect.Top;
            boundingBox.Max.X = rect.Right;
            boundingBox.Max.Y = rect.Bottom;

            if (!this.lineMesh.UseWorldSpace)
            {
                var world = this.Transform2D.WorldTransform;
                boundingBox.Transform(ref world);
            }

            this.BoundingBox = boundingBox;
        }