示例#1
0
文件: Scene.cs 项目: Michizev/ACG
        private static VertexArray MeshInstances(MyCameraShaderProgram shaderProgram)
        {
            var mesh        = MeshTools.LoadFromResource("content.suzanne.obj");
            var vertexArray = new VertexArray(PrimitiveType.Triangles);

            vertexArray.AddIndices(mesh.ID.ToArray());

            const int count = 100;
            var       rnd   = new Random();

            float RndRange(float min, float max) => min + (max - min) * (float)rnd.NextDouble();

            var position = new Vector3[count];

            for (int i = 0; i < count; ++i)
            {
                position[i] = new Vector3(RndRange(-8f, 8f), RndRange(-.5f, .5f), RndRange(-40f, -0f));
            }
            vertexArray.AddAttribute(shaderProgram.LocationInstancePosition, position, 3, VertexAttribPointerType.Float, true);

            vertexArray.AddAttribute(shaderProgram.LocationPosition, mesh.Position.ToArray(), 3, VertexAttribPointerType.Float);
            if (mesh.Normal.Count > 0 && -1 != shaderProgram.LocationNormal)
            {
                vertexArray.AddAttribute(shaderProgram.LocationNormal, mesh.Normal.ToArray(), 3, VertexAttribPointerType.Float);
            }
            if (mesh.TextureCoordinate.Count > 0 && -1 != shaderProgram.LocationTexCoord)
            {
                vertexArray.AddAttribute(shaderProgram.LocationTexCoord, mesh.TextureCoordinate.ToArray(), 2, VertexAttribPointerType.Float);
            }
            return(vertexArray);
        }
示例#2
0
文件: Scene.cs 项目: Michizev/ACG
 public Scene()
 {
     shaderProgram = new MyCameraShaderProgram();
     axis          = CoordinateSystemAxis();
     vertexArray   = MeshInstances(shaderProgram);
 }