Esempio n. 1
0
        public static void DrawSimpleQuad3D()
        {
            // We create a 3d quad, so we need a camera.
            BaseCamera cam = new LookAtCamera(new Vector(4, -4, 4));

            // Create a geometry data instance which will hold the actual data.
            GeometryData geometryData = new GeometryData("<SimpleQuad3D>", 4,
                                                         VertexFormat.Position3DTextured, 6, true, false);

            // Fill the geometry with actual data.
            geometryData.SetVertexData(0, new Vector(1, 0, 0), Point.One);
            geometryData.SetVertexData(1, new Vector(-1, 0, 0), Point.UnitY);
            geometryData.SetVertexData(2, new Vector(-1.25f, 0, 1), Point.Zero);
            geometryData.SetVertexData(3, new Vector(1.25f, 0, 1), Point.UnitX);

            geometryData.Indices = new ushort[]
            {
                0, 2, 1,
                0, 3, 2,
            };
            // Now create a geometry from the data.
            Geometry geometry = Geometry.Create(geometryData);

            // We need a material to draw the geometry. Simply use the default.
            MaterialColored material = MaterialColored.Default;

            // Now start the application...
            Application.Start(delegate
            {
                // ...and draw the geometry.
                material.Draw(geometry);
            });
        }
Esempio n. 2
0
        public static IEnumerable <GeometryData> Load(PointFile source)
        {
            var fact = new GeometryFactory();

            using StreamReader reader = File.OpenText(source.Filename);

            var options = new CsvOptions {
                HeaderMode = source.HeaderMode,
                RowsToSkip = source.RowsToSkip,
                Separator  = source.Separator[0]
            };

            CoordinateSystem f = ProjectionUtils.Transforms[source.Srid];
            CoordinateSystem t = ProjectionUtils.EPSG_4326();

            foreach (var row in CsvReader.Read(reader, options).Take(source.MaxRecords ?? int.MaxValue))
            {
                double.TryParse(row[source.Latitude], out double latitude);
                double.TryParse(row[source.Longitude], out double longitude);
                var geom = new Coordinate(longitude, latitude);

                geom = geom.Transform(f, t);

                var data = new GeometryData
                {
                    DataType  = source.DataType,
                    Geom      = fact.CreatePoint(geom),
                    Name      = row[source.Name],
                    Reference = source.Reference != null ? row[(int)source.Reference] : null,
                };
                yield return(data);
            }
        }
Esempio n. 3
0
        private static void AddFaceWater(BlockClass[][][] blocks, GeometryData geo, byte dir, Vector3Int center)
        {
            for (var i = 0; i < 4; i++)
            {
                var blk = center + BlockProperties.FacePts[BlockProperties.BlockFaces[dir, i]];
                geo.Vertices.Add(blk + blocks[blk.x + 1][blk.y + 1][blk.z + 1].Data.ControlPoint);
                geo.Normals.Add(BlockProperties.DirectionVector[dir]);
            }

            var sc = geo.Vertices.Count - 4; // squareCount << 2;//Multiply by 4

            geo.Triangles.Add(sc);
            geo.Triangles.Add(sc + 1);
            geo.Triangles.Add(sc + 3);
            geo.Triangles.Add(sc + 1);
            geo.Triangles.Add(sc + 2);
            geo.Triangles.Add(sc + 3);
            var v = blocks[center.x + 1][center.y + 1][center.z + 1].GetTex();

            var uv = new Vector2(0, 0);

            geo.UV.Add(uv);
            geo.UV.Add(new Vector2(1, 0));
            geo.UV.Add(new Vector2(1, 1));
            geo.UV.Add(new Vector2(0, 1));
        }
        public static IEnumerable <GeometryData> Load(PolygonFile source)
        {
            var geomFact = new GeometryFactory();

            using var reader = new ShapefileDataReader(source.Filename, geomFact);

            CoordinateSystem f = ProjectionUtils.Transforms[source.Srid];
            CoordinateSystem t = ProjectionUtils.EPSG_4326();
            var transformer    = ProjectionUtils.GetTransformer(f, t);

            while (reader.Read())
            {
                var    name      = reader.GetString(source.Name);
                string reference = null;

                if (source.Reference != null)
                {
                    reference = reader.GetString((int)source.Reference);
                }

                if (reference == null)
                {
                    reference = Guid.NewGuid().ToString();
                }

                var geom = ProjectionUtils.Transform(reader.Geometry, transformer);

                var data = new GeometryData {
                    Name = name, DataType = source.DataType, Reference = reference, Geom = geom
                };

                yield return(data);
            }
        }
        /// <summary>
        /// Generate the common Rectangle geometry. (Only one Rectangle)
        /// </summary>
        private void GenerateCommonGeometry()
        {
            GeometryData[] _vertices = new GeometryData[4];


            #region filling vertices
            _vertices[0].World           = new Color((byte)0, (byte)0, (byte)0, (byte)0);   //float3
            _vertices[0].AtlasCoordinate = new Color((byte)0, (byte)0, (byte)0, (byte)0);   //flaot2
            _vertices[1].World           = new Color((byte)255, (byte)0, (byte)0, (byte)0);
            _vertices[1].AtlasCoordinate = new Color((byte)255, (byte)0, (byte)0, (byte)0);
            _vertices[2].World           = new Color((byte)0, (byte)255, (byte)0, (byte)0);
            _vertices[2].AtlasCoordinate = new Color((byte)0, (byte)255, (byte)0, (byte)0);
            _vertices[3].World           = new Color((byte)255, (byte)255, (byte)0, (byte)0);
            _vertices[3].AtlasCoordinate = new Color((byte)255, (byte)255, (byte)0, (byte)0);


            #endregion

            this.geometryBuffer = new VertexBuffer(this.GraphicsDevice, GeometryData.VertexDeclaration,
                                                   4, BufferUsage.WriteOnly);
            this.geometryBuffer.SetData(_vertices);

            #region filling indices

            short[] _indices = new short[6];
            _indices[0] = 0; _indices[1] = 1; _indices[2] = 2;
            _indices[3] = 1; _indices[4] = 3; _indices[5] = 2;



            #endregion

            this.indexBuffer = new IndexBuffer(this.GraphicsDevice, typeof(short), _indices.Length, BufferUsage.WriteOnly);
            this.indexBuffer.SetData(_indices);
        }
Esempio n. 6
0
        private static void RegisterCircle()
        {
            GeometryData shapeData = CreateRegularPolygon(90);

            shapeData.Managed = true;
            RegisterShapeData("Relatus_Circle", shapeData);
        }
Esempio n. 7
0
        public static GeometryData GetGeometryData(SvgMeshData data, bool instanced)
        {
            var result = new GeometryData()
            {
                VertexCount = data.Vertices.Count,
                Indices     = data.Indices.ToArray(),
                Attribs     = instanced ? MeshHelper.PositionColorInstancedVertex.VertexAttribs : MeshHelper.PositionColorVertex.VertexAttribs
            };

            using (var stream = new System.IO.MemoryStream())
                using (var writer = new System.IO.BinaryWriter(stream))
                {
                    for (int i = 0; i < data.Vertices.Count; i++)
                    {
                        writer.Write(data.Vertices[i].PosX);
                        writer.Write(data.Vertices[i].PosY);
                        writer.Write(data.Vertices[i].PosZ);
                        writer.Write(data.Vertices[i].R);
                        writer.Write(data.Vertices[i].G);
                        writer.Write(data.Vertices[i].B);
                        writer.Write(data.Vertices[i].A);
                    }

                    result.Data = stream.ToArray();
                }

            return(result);
        }
Esempio n. 8
0
        public TaskService(IFileHelper fileHelper, IJsonSerialize jsonSerialize)
        {
            _fileHelper    = fileHelper;
            _jsonSerialize = jsonSerialize;

            _geometryData = App.Provider.GetRequiredService <GeometryData>();
        }
Esempio n. 9
0
        private static GeometryData GenerateGeometryDataFromAssimpMesh(Assimp.Mesh mesh)
        {
            var geometryData = new GeometryData
            {
                Vertices = new VertexPositionNormalTexture[mesh.VertexCount],
                Indices  = new ushort[mesh.FaceCount * 3]
            };

            geometryData.Vertices = new VertexPositionNormalTexture[mesh.VertexCount];

            for (var i = 0; i < mesh.VertexCount; i++)
            {
                var vertex = mesh.Vertices[i];
                geometryData.Vertices[i].Position = new Vector3(vertex.X, vertex.Y, vertex.Z);

                var normal = mesh.HasNormals ? mesh.Normals[i] : new Vector3D();
                geometryData.Vertices[i].Normal = new Vector3(normal.X, normal.Y, normal.Z);

                var texcoord = mesh.HasTextureCoords(0) ? mesh.TextureCoordinateChannels[0][i] : new Vector3D();
                geometryData.Vertices[i].TextureCoordinate = new Vector2(texcoord.X, texcoord.Y);
            }

            for (var i = 0; i < mesh.FaceCount; i++)
            {
                geometryData.Indices[i * 3 + 0] = (ushort)mesh.Faces[i].Indices[0];
                geometryData.Indices[i * 3 + 1] = (ushort)mesh.Faces[i].Indices[1];
                geometryData.Indices[i * 3 + 2] = (ushort)mesh.Faces[i].Indices[2];
            }

            return(geometryData);
        }
Esempio n. 10
0
 public SmokeData(int _index, string _name, type _type, bool _deletable, GeometryData _geometryData, PhysicalData _physicalData, SmokeType _smokeType, Color _color) : base(_index, _name, _type, _deletable)
 {
     geometryData = _geometryData;
     physicalData = _physicalData;
     smokeType    = _smokeType;
     color        = _color;
 }
Esempio n. 11
0
        /// <summary>
        /// Create a <see cref="HybridSystem"/> that helps process, manipulate, and draw <see cref="GeometryData"/>.
        /// By default, this system will handle any entity that includes the following components: <see cref="CPosition"/>, <see cref="CDimension"/>, <see cref="CTransform"/>, <see cref="CColor"/>,
        /// and a custom <see cref="IComponent"/> that acts as a tag specifically for this system.
        /// </summary>
        /// <param name="scene">The scene this system will exist in.</param>
        /// <param name="geometry">The shape data that this system will focus on and draw.</param>
        /// <param name="shapeTag">The type of the custom <see cref="IComponent"/> that acts as a tag specifically for this system.</param>
        /// <param name="tasks">The total amount of tasks to divide the update cycle into. Assigning more than one task allows entities to be updated asynchronously.</param>
        public SimpleShapeSystem(Scene scene, GeometryData geometry, Type shapeTag, uint tasks) : base(scene, tasks)
        {
            Require(typeof(CPosition), typeof(CDimension), typeof(CTransform), typeof(CColor), shapeTag);

            this.geometry = geometry;
            vertexBuffer  = new VertexTransformColor[scene.EntityCapacity];
        }
Esempio n. 12
0
    private void addUpdateArray(int index)
    {
        GeometryData geometryData = windObjectsData[index].geometryData;
        Vector3      position     = geometryData.position;

        Vector3[,,] objectArray = windArrayData[index];
        switch (geometryData.geometryType)
        {
        case GeometryData.GeometryType.CUBE: {
            CubeGeometryData cubeGeometryData = (CubeGeometryData)geometryData;
            int sizeX  = (int)(cubeGeometryData.size.x / 0.1f);
            int sizeY  = (int)(cubeGeometryData.size.y / 0.1f);
            int sizeZ  = (int)(cubeGeometryData.size.z / 0.1f);
            int beginX = (int)((position.x + 2f) / 0.1f) - sizeX / 2;
            int beginY = (int)((position.y + 2f) / 0.1f) - sizeY / 2;
            int beginZ = (int)((position.z + 2f) / 0.1f) - sizeZ / 2;
            for (int i = 0; i < sizeX; i++)
            {
                for (int j = 0; j < sizeZ; j++)
                {
                    for (int k = 0; k < sizeY; k++)
                    {
                        windArray[i + beginX, j + beginY, k + beginZ] = objectArray[i, j, k];
                    }
                }
            }
            break;
        }
        }
    }
Esempio n. 13
0
            }             //ncrunch: no coverage

            public void LoadValidData()
            {
                var d = new GeometryData {
                    Format = VertexFormat.Position3DColor, Indices = new short[6]
                };

                LoadData(new MemoryStream(BinaryDataExtensions.ToByteArrayWithTypeInformation(d)));
            }
Esempio n. 14
0
 private void InitializeGeometry()
 {
     GeoData = new GeometryData
     {
         Width  = (int)ActualWidth - 17,
         Height = (int)ActualHeight - 63
     };
 }
Esempio n. 15
0
        private GeometryData CreateTilemapData()
        {
            var tilesX           = GetData <int>("tilesX");
            var tilesY           = GetData <int>("tilesY");
            var tileElementSize  = GetData <int>("tileElementSize");
            var diffuseTexture   = _drawableElement.Material.DiffuseTexture;
            var tilesetElementsX = diffuseTexture.Width / tileElementSize;

            var geometryData = new GeometryData
            {
                Vertices = new VertexPositionNormalTexture[tilesX * tilesY * 4],
                Indices  = new ushort[tilesX * tilesY * 6]
            };

            var tiles = GetData <string>("map")
                        .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(int.Parse).ToArray();

            var texturePartSize = diffuseTexture.GetTexcoordsFromPixelCoords(tileElementSize, tileElementSize);

            var vertexBaseIndex = 0;
            var indexBaseIndex  = 0;

            for (var i = 0; i < Math.Min(tiles.Length, tilesX * tilesY); i++)
            {
                var element = tiles[i];
                if (element == 0)
                {
                    continue;
                }
                var tilesetX = (element - 1) % tilesetElementsX;
                var tilesetY = (element - 1) / tilesetElementsX;

                var mapX = i % tilesX;
                var mapY = i / tilesX;

                var position  = new Vector3(mapX, 0.0f, mapY);
                var texcoords = diffuseTexture.GetTexcoordsFromPixelCoords(tilesetX * tileElementSize, tilesetY * tileElementSize);
                var normal    = Vector3.UnitY;

                geometryData.Vertices[vertexBaseIndex + 0] = new VertexPositionNormalTexture(position + new Vector3(0, 0, -1), normal, texcoords + new Vector2(0, texturePartSize.Y));
                geometryData.Vertices[vertexBaseIndex + 1] = new VertexPositionNormalTexture(position + new Vector3(0, 0, 0), normal, texcoords + new Vector2(0, 0));
                geometryData.Vertices[vertexBaseIndex + 2] = new VertexPositionNormalTexture(position + new Vector3(1, 0, -1), normal, texcoords + new Vector2(texturePartSize.X, texturePartSize.Y));
                geometryData.Vertices[vertexBaseIndex + 3] = new VertexPositionNormalTexture(position + new Vector3(1, 0, 0), normal, texcoords + new Vector2(texturePartSize.X, 0));

                geometryData.Indices[indexBaseIndex + 0] = (ushort)vertexBaseIndex;
                geometryData.Indices[indexBaseIndex + 1] = (ushort)(vertexBaseIndex + 2);
                geometryData.Indices[indexBaseIndex + 2] = (ushort)(vertexBaseIndex + 1);
                geometryData.Indices[indexBaseIndex + 3] = (ushort)(vertexBaseIndex + 1);
                geometryData.Indices[indexBaseIndex + 4] = (ushort)(vertexBaseIndex + 2);
                geometryData.Indices[indexBaseIndex + 5] = (ushort)(vertexBaseIndex + 3);

                vertexBaseIndex += 4;
                indexBaseIndex  += 6;
            }

            return(geometryData);
        }
Esempio n. 16
0
 public InfoTaskViewModel(ITaskService taskService)
 {
     _taskService  = taskService;
     _geometryData = App.GetRequiredService <GeometryData>();
     TodoTasks     = new ObservableCollection <TodoTask>();
     ToDoTask      = new TodoTask {
         CanBeFinished = true
     };
 }
Esempio n. 17
0
        /// <summary>
        /// Create a <see cref="HybridSystem"/> that helps process, manipulate, and draw <see cref="GeometryData"/>.
        /// By default, this system will handle any entity that includes the following components: <see cref="CPosition"/>, <see cref="CDimension"/>, <see cref="CTransform"/>, <see cref="CColor"/>,
        /// and a custom <see cref="IComponent"/> that acts as a tag specifically for this system.
        /// </summary>
        /// <param name="factory">The scene this system will exist in.</param>
        /// <param name="geometry">The shape data that this system will focus on and draw.</param>
        /// <param name="renderOptions">The render options that should be used to draw the geometry.</param>
        /// <param name="shapeTag">The type of a custom <see cref="IComponent"/> that acts as a tag specifically for this system.</param>
        public SimpleShapeSystem(MorroFactory factory, GeometryData geometry, RenderOptions renderOptions, Type shapeTag) : base(factory)
        {
            Require(typeof(CPosition), typeof(CDimension), typeof(CTransform), typeof(CColor), shapeTag);

            this.geometry      = geometry;
            this.renderOptions = renderOptions;

            transformData = new VertexTransform[factory.EntityCapacity];
            colorData     = new VertexColor[factory.EntityCapacity];
        }
Esempio n. 18
0
        public async Task SaveAsync(string path, GeometryData data)
        {
            using (var fileContent = new StreamWriter(path))
            {
                await fileContent.WriteLineAsync("# Generated by XenkoTerrain " + DateTime.Now.ToLongDateString());

                await fileContent.WriteLineAsync("# Vertices: " + data.Vertices.Length);

                await fileContent.WriteLineAsync("# Size: " + data.Size);

                await fileContent.WriteLineAsync("usemtl Terrain");

                for (var row = 0; row < data.TessellationY - 1; row++)
                {
                    for (var col = 0; col < data.TessellationX - 1; col++)
                    {
                        var topLeft          = col + row * (int)data.TessellationX;
                        var topRight         = topLeft + 1;
                        var bottomLeft       = topLeft + (int)data.TessellationX;
                        var bottomRight      = bottomLeft + 1;
                        var topLeftVertex    = data.Vertices[topLeft];
                        var topRightVertex   = data.Vertices[topRight];
                        var bottomLeftVertex = data.Vertices[bottomLeft];
                        var botomRightVertex = data.Vertices[bottomRight];

                        await fileContent.WriteLineAsync(topRightVertex.Position.PrintObj(ObjLineType.Position));

                        await fileContent.WriteLineAsync(topLeftVertex.Position.PrintObj(ObjLineType.Position));

                        await fileContent.WriteLineAsync(bottomLeftVertex.Position.PrintObj(ObjLineType.Position));

                        await fileContent.WriteLineAsync(botomRightVertex.Position.PrintObj(ObjLineType.Position));

                        await fileContent.WriteLineAsync(topRightVertex.Normal.PrintObj(ObjLineType.Normal));

                        await fileContent.WriteLineAsync(topLeftVertex.Normal.PrintObj(ObjLineType.Normal));

                        await fileContent.WriteLineAsync(bottomLeftVertex.Normal.PrintObj(ObjLineType.Normal));

                        await fileContent.WriteLineAsync(botomRightVertex.Normal.PrintObj(ObjLineType.Normal));

                        await fileContent.WriteLineAsync((data.Size *topRightVertex.TextureCoordinate).PrintObj(ObjLineType.TextureCoordinate));

                        await fileContent.WriteLineAsync((data.Size *topLeftVertex.TextureCoordinate).PrintObj(ObjLineType.TextureCoordinate));

                        await fileContent.WriteLineAsync((data.Size *bottomLeftVertex.TextureCoordinate).PrintObj(ObjLineType.TextureCoordinate));

                        await fileContent.WriteLineAsync((data.Size *botomRightVertex.TextureCoordinate).PrintObj(ObjLineType.TextureCoordinate));

                        await fileContent.WriteLineAsync($"f -4/-4/-4 -3/-3/-3 -2/-2/-2 -1/-1/-1 ");
                    }
                }
            }
        }
Esempio n. 19
0
        private void CreateSphere(GeometryData geometry, Material material, Vector3 position, Vector3 scale)
        {
            var mesh  = new GeometryMesh(geometry, material, Matrix.Identity);
            var model = new GeometryModel();

            model.Add(mesh);

            (var sphereGeometry, var sphereTransform, var sphereBounds) = this.Geometry.Create(model);
            sphereTransform.MoveTo(position);
            sphereTransform.SetScale(scale);
        }
Esempio n. 20
0
        private static void AddFace(BlockClass[][][] blocks, GeometryData geo, byte dir, Vector3Int center)
        {
            for (var i = 0; i < 4; i++)
            {
                var blk = center + BlockProperties.FacePts[BlockProperties.BlockFaces[dir, i]];
                geo.Vertices.Add(blk + blocks[blk.x + 1][blk.y + 1][blk.z + 1].Data.ControlPoint);
                geo.Normals.Add(BlockProperties.DirectionVector[dir]);
            }

            var v1 = geo.Vertices[geo.Vertices.Count - 1] -
                     geo.Vertices[geo.Vertices.Count - 2];
            var v2 = geo.Vertices[geo.Vertices.Count - 3] -
                     geo.Vertices[geo.Vertices.Count - 2];

            var N = Vector3.Cross(v1, v2).normalized;

            if (N.y > .3)
            {
                dir = (byte)BlockClass.Direction.Up; //Up
            }
            var sc = geo.Vertices.Count - 4;         // squareCount << 2;//Multiply by 4

            if ((geo.Vertices[geo.Vertices.Count - 3] - geo.Vertices[geo.Vertices.Count - 1]).sqrMagnitude <
                (geo.Vertices[geo.Vertices.Count - 4] - geo.Vertices[geo.Vertices.Count - 2]).sqrMagnitude)
            {
                geo.Triangles.Add(sc);
                geo.Triangles.Add(sc + 1);
                geo.Triangles.Add(sc + 3);
                geo.Triangles.Add(sc + 1);
                geo.Triangles.Add(sc + 2);
                geo.Triangles.Add(sc + 3);
            }
            else
            {
                geo.Triangles.Add(sc);
                geo.Triangles.Add(sc + 1);
                geo.Triangles.Add(sc + 2);
                geo.Triangles.Add(sc);
                geo.Triangles.Add(sc + 2);
                geo.Triangles.Add(sc + 3);
            }

            var v = blocks[center.x + 1][center.y + 1][center.z + 1].GetTex();

            var uv = new Vector2(v[dir].x / 16f, (15 - v[dir].y) / 16f);

            geo.UV.Add(uv);
            geo.UV.Add(new Vector2(uv.x + BlockProperties.TUnit, uv.y));
            geo.UV.Add(new Vector2(uv.x + BlockProperties.TUnit, uv.y + BlockProperties.TUnit));
            geo.UV.Add(new Vector2(uv.x, uv.y + BlockProperties.TUnit));
            //squareCount++;
        }
Esempio n. 21
0
        public async Task SaveAsync(GeometryData data)
        {
            var saveDialog = new SaveFileDialog()
            {
                Title  = "Save Terrain to File",
                Filter = "OBJ Files|*.obj"
            };

            if (saveDialog.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(saveDialog.FileName))
            {
                await new GeometryExporerObj().SaveAsync(saveDialog.FileName, data);
            }
        }
Esempio n. 22
0
 public virtual void Update(BaseObject newObject)
 {
     Description = newObject.Description;
     Height      = newObject.Height;
     Id          = newObject.Id;
     Left        = newObject.Left;
     Name        = newObject.Name;
     ParentId    = newObject.ParentId;
     Path        = newObject.Path;
     Top         = newObject.Top;
     Type        = newObject.Type;
     TypeId      = newObject.TypeId;
     Width       = newObject.Width;
 }
Esempio n. 23
0
        //param constructor for when declared in main
        public RMI(IList <SeisData> src, GeometryData geoSrc)
        {
            fileNames = new List <string>();
            ampData   = new List <RMIAmpData>();
            pickData  = new List <RMIPickData>();

            fileDescription = new RMIFileDescription(src);
            geoData         = new RMIGeoData(geoSrc);
            foreach (var file in src)
            {
                ampData.Add(new RMIAmpData(file));
                pickData.Add(new RMIPickData(file));
            }
        }
Esempio n. 24
0
        internal static SchemaShape2D CreateShapeSchema(GeometryData shapeData, CPosition position, CDimension dimension, CTransform transform)
        {
            Matrix vertexTransform = CreateVertexTransform();

            Vector2[]     vertices     = CreateVertices();
            LineSegment[] lineSegments = CreateLineSegments();

            return(new SchemaShape2D(vertices, lineSegments));

            Matrix CreateVertexTransform()
            {
                return
                    (Matrix.CreateScale(dimension.Width * transform.Scale.X, dimension.Height * transform.Scale.Y, 1 * transform.Scale.Z) *

                     Matrix.CreateTranslation(-new Vector3(transform.RotationOffset.X, transform.RotationOffset.Y, 0)) *
                     Matrix.CreateRotationZ(transform.Rotation) *

                     Matrix.CreateTranslation(position.X + transform.Translation.X + transform.RotationOffset.X, position.Y + transform.Translation.Y + transform.RotationOffset.Y, transform.Translation.Z) *

                     Matrix.Identity);
            }

            Vector2[] CreateVertices()
            {
                Vector2[] result = new Vector2[shapeData.TotalVertices];

                for (int i = 0; i < shapeData.TotalVertices; i++)
                {
                    result[i] = Vector2.Transform(new Vector2(shapeData.Vertices[i].X, shapeData.Vertices[i].Y), vertexTransform);
                }

                return(result);
            }

            LineSegment[] CreateLineSegments()
            {
                int totalVertices = shapeData.TotalVertices;

                LineSegment[] result = new LineSegment[totalVertices];

                result[0] = new LineSegment(vertices[totalVertices - 1].X, vertices[totalVertices - 1].Y, vertices[0].X, vertices[0].Y);

                for (int i = 1; i < totalVertices; i++)
                {
                    result[i] = new LineSegment(vertices[i - 1].X, vertices[i - 1].Y, vertices[i].X, vertices[i].Y);
                }

                return(result);
            }
        }
Esempio n. 25
0
        public void OnOpening()
        {
            _scene = new Scene(Game, new WindowsSceneEffect(Game.Content))
            {
                EnableShadows = false,
                LightDirection = new Vector3(0, -1, 0)
            };

            _camera = _scene.CreateCamera();
            _camera.Position = new Vector3(0.0f, 12.0f, 13.0f);
            _camera.RotateX(-MathHelper.PiOver4);
            
            var billboardSceneNode = _scene.CreateSceneNode();
            billboardSceneNode.IsBillboard = true;
            billboardSceneNode.Mesh = new Mesh(Game.GraphicsDevice, Primitives.GenerateQuadForYBillboard());
            billboardSceneNode.Material = new Material(Game.Content.Load<Texture2D>(ResourceNames.Textures.tileset1))
            {
                CastShadow = false,
                UseTransparency = true
            };
            billboardSceneNode.Position = new Vector3(-5, 0, -5);
            billboardSceneNode.Scale = new Vector3(2, 4, 1);

            for (var x = 0; x < 5; x++)
            {
                for(var z = 0; z < 5; z++)
                {
                    if (x == 0 && z == 0) continue;
                    var cloned = _scene.CloneNode(billboardSceneNode);
                    cloned.Position = new Vector3(x*2-5, 0, z * 2-5);
                }
            }

            var quads = new GeometryData[32*32];

            //2,1
            var tsize = 1.0f / 16.0f;
            for(var x = 0; x < 32; x++)
            {
                for(var z = 0; z < 32; z++)
                {
                    quads[z*32+x] = Primitives.GenerateQuadXZ(new Vector3(-16.0f + x, 0.0f, -16.0f + z), texCoordStart: new Vector2(tsize * 2.0f, tsize), texCoordScale: new Vector2(tsize, tsize));
                }
            }

            var sceneNode = _scene.CreateSceneNode();
            sceneNode.Mesh = new Mesh(Game.GraphicsDevice, Primitives.Merge(quads));
            sceneNode.Material = new Material(Game.Content.Load<Texture2D>(ResourceNames.Textures.tileset1));
        }
Esempio n. 26
0
 public Path2D()
 {
     // can i get rid of draw call list and use object data instead?
     this.geometry                = GeometryData.Create();
     this.drawCallList            = new StructList <SVGXDrawCall>(4);
     this.transforms              = new StructList <Matrix4x4>(4);
     this.objectDataList          = new StructList <ObjectData>(4);
     this.fillStyles              = null;
     this.strokeStyles            = null;
     this.currentMatrix           = Matrix4x4.identity;
     this.currentFillStyle        = SVGXFillStyle.Default;
     this.currentStrokeStyle      = SVGXStrokeStyle.Default;
     this.currentFixedRenderState = new FixedRenderState(BlendState.Default, DepthState.Default);
     transforms.Add(currentMatrix);
 }
Esempio n. 27
0
        public void Preload()
        {
            var data = FileLoader.GetFiles(new[]
            {
                PrimitivesFilePath,
                NaturesFilePath,
                TypesFilePath,
                PokedexesFilePath
            });

            _primitiveModels = DataModel <PrimitiveModel[]> .FromByteArray(data[0].Data);

            foreach (var primitiveModel in _primitiveModels)
            {
                var geometryData = new GeometryData
                {
                    Vertices = primitiveModel.Vertices.Select(v => new VertexPositionNormalTexture
                    {
                        Position          = v.Position.GetVector3(),
                        TextureCoordinate = v.TexCoord.GetVector2(),
                        Normal            = v.Normal.GetVector3()
                    }).ToArray(),
                    Indices = primitiveModel.Indices.Select(i => (ushort)i).ToArray()
                };

                Mesh mesh = null;
                GameContext.EnsureExecutedInMainThread(() => mesh = new Mesh(GraphicsDevice, geometryData));
                _meshPrimitivesByName.Add(primitiveModel.Id, mesh);
            }

            _natureModels = DataModel <NatureModel[]> .FromByteArray(data[1].Data);

            _typeModels = DataModel <TypeModel[]> .FromByteArray(data[2].Data);

            _pokedexModels = DataModel <PokedexModel[]> .FromByteArray(data[3].Data);

            var movesFilePaths = FileLoader.GetFilesOfFolder(MoveFilesPath);

            _moveModels = movesFilePaths.Select(d => DataModel <MoveModel> .FromByteArray(d.Data)).ToArray();

            var itemsFiles = FileLoader.GetFilesOfFolder(ItemFilesPath);

            _itemModels = itemsFiles.Select(d => DataModel <ItemModel> .FromByteArray(d.Data)).ToArray();

            var abilityFiles = FileLoader.GetFilesOfFolder(AbilityFilesPath);

            _abilityModels = abilityFiles.Select(d => DataModel <AbilityModel> .FromByteArray(d.Data)).ToArray();
        }
Esempio n. 28
0
        //this parameterized constructor takes all data from geoData and transfers it between the two or vice versa
        public RMIGeoData(GeometryData src)
        {
            shotElevation = src.shotElevation;
            shotPosition  = src.shotPosition;
            IList <float> temp = new List <float>();

            for (int i = 0; i < src.numChansGeo; i++)
            {
                temp.Add((float)src.GeophoneDatas[i].Elevation);
            }
            geoElevation       = temp;
            numChannelsGeoData = src.numChansGeo;
            geoSpacing         = src.geophoneSpacing;
            geoOffset          = src.geophoneOffset;
            geoDistance        = src.dtVal;
        }
Esempio n. 29
0
    // Status and states
    public ChunkObject()
    {
        _solidGeometry  = new GeometryData();
        _liquidGeometry = new GeometryData();

        Blocks = new BlockClass[BlockProperties.ChunkSizeP2][][];

        for (var x = 0; x < BlockProperties.ChunkSize + 2; x++)
        {
            Blocks[x] = new BlockClass[BlockProperties.ChunkSizeP2][];
            for (var y = 0; y < BlockProperties.ChunkSizeP2; y++)
            {
                Blocks[x][y] = new BlockClass[BlockProperties.ChunkSizeP2];
            }
        }
    }
 private float[] getColorOfIndex(GeometryData paramGeometryData, int[] paramArrayOfInt, long paramLong)
 {
     foreach (ElementMaterialGeomData elementMaterialGeomData in paramGeometryData.Materials)
     {
         if (elementMaterialGeomData.MaterialVBOffset < paramArrayOfInt.Length && elementMaterialGeomData.MaterialVBOffset >= 0L)
         {
             long l1 = paramArrayOfInt[(int)elementMaterialGeomData.MaterialVBOffset];
             long l2 = l1 + elementMaterialGeomData.MaterialIndexCount;
             if (l1 <= paramLong && l2 > paramLong)
             {
                 return(getColorsFloat(elementMaterialGeomData));
             }
         }
     }
     return((paramGeometryData.Materials.length == 0) ? new float[] { 0.1F, 0.1F, 0.1F, 0.0F } : getColorsFloat(paramGeometryData.Materials[0]));
 }
Esempio n. 31
0
        private static ModelMesh LoadPMesh(GameMode gameMode, string filePath)
        {
            using (var fileStream = new FileStream(filePath, FileMode.Open))
            {
                using (var binaryReader = new BinaryReader(fileStream))
                {
                    var vertexCount  = binaryReader.ReadInt32();
                    var indicesCount = binaryReader.ReadInt32();
                    var textureName  = binaryReader.ReadString();

                    var       textureFilePath = Path.Combine(Path.GetDirectoryName(filePath) ?? "", Path.GetFileName(textureName) ?? "");
                    Texture2D texture         = null;
                    if (File.Exists(textureFilePath))
                    {
                        texture = gameMode.GetTextureFromRawFolder(textureFilePath);
                    }

                    var geometryData = new GeometryData
                    {
                        Vertices = new VertexPositionNormalTexture[vertexCount],
                        Indices  = new ushort[indicesCount]
                    };

                    for (var i = 0; i < vertexCount; i++)
                    {
                        var position = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        var normal   = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        var uv       = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        geometryData.Vertices[i] = new VertexPositionNormalTexture(position, normal, uv);
                    }

                    for (var i = 0; i < indicesCount; i++)
                    {
                        geometryData.Indices[i] = (ushort)binaryReader.ReadInt32();
                    }

                    return(new ModelMesh
                    {
                        Mesh = new Mesh(gameMode.GraphicsDevice, geometryData, PrimitiveType.TriangleList, false),
                        Material = new Material
                        {
                            DiffuseTexture = texture
                        }
                    });
                }
            }
        }
Esempio n. 32
0
			} //ncrunch: no coverage

			public void LoadValidData()
			{
				var d = new GeometryData { Format = VertexFormat.Position3DColor, Indices = new short[6] };
				LoadData(new MemoryStream(BinaryDataExtensions.ToByteArrayWithTypeInformation(d)));
			}
		//return the shader to use:
		public IShader BeginGeometry(DrawState state, GeometryData geometry)
		{	
			//query the draw flag, 
			switch (state.DrawFlags.GetFlag<TutorialRenderMode>())
			{
				case TutorialRenderMode.DrawShadow:
				{
					//return the shader that draws the shadow
					var shader = state.GetShader<Shader.ShadowShader>();
					shader.TextureMap = geometry.MaterialData.Texture;
					
					return shader;
				}

				//return the shader that outpus depth
				case TutorialRenderMode.DepthOutput:
					return state.GetShader<Xen.Ex.Shaders.NonLinearDepthOut>();

				default:	//no flag is set, or it is in it's default state
					return null;	//do not change the shader
			}
		}
Esempio n. 34
0
        //return the shader to use:
        public IShader BeginGeometry(DrawState state, GeometryData geometry)
        {
            //query the draw flag,
            switch (state.DrawFlags.GetFlag<RenderMode>())
            {
                case RenderMode.DrawShadow:
                    {
                        //return the shader shader
                        Shaders.ShadowShader shader = state.GetShader<Shaders.ShadowShader>();

                        shader.TextureMap = geometry.MaterialData.Texture;

                        return shader;
                    }

                case RenderMode.DepthOutput:
                    return state.GetShader<Xen.Ex.Shaders.NonLinearDepthOut>();

                default:
                    return null;	//no change
            }
        }
Esempio n. 35
0
        private static GeometryData GenerateGeometryDataFromAssimpMesh(Assimp.Mesh mesh)
        {
            var geometryData = new GeometryData
            {
                Vertices = new VertexPositionNormalTexture[mesh.VertexCount],
                Indices = new ushort[mesh.FaceCount * 3]
            };

            geometryData.Vertices = new VertexPositionNormalTexture[mesh.VertexCount];

            for (var i = 0; i < mesh.VertexCount; i++)
            {
                var vertex = mesh.Vertices[i];
                geometryData.Vertices[i].Position = new Vector3(vertex.X, vertex.Y, vertex.Z);

                var normal = mesh.Normals[i];
                geometryData.Vertices[i].Normal = new Vector3(normal.X, normal.Y, normal.Z);

                var texcoord = mesh.TextureCoordinateChannels[0][i];
                geometryData.Vertices[i].TextureCoordinate = new Vector2(texcoord.X, texcoord.Y);
            }

            for (var i = 0; i < mesh.FaceCount; i++)
            {
                geometryData.Indices[i * 3 + 0] = (ushort)mesh.Faces[i].Indices[0];
                geometryData.Indices[i * 3 + 1] = (ushort)mesh.Faces[i].Indices[1];
                geometryData.Indices[i * 3 + 2] = (ushort)mesh.Faces[i].Indices[2];
            }

            return geometryData;
        }