예제 #1
0
        protected override void OnLoad(EventArgs e)
        {
            ColladaXML daeReader = new ColladaXML("collada_schema_1_4.xsd");
            Console.WriteLine("Parsing File...");
            daeReader.Parse(Paths.ModelPath + "face.dae");
            mesh = daeReader.Mesh.Elements[2];
            mesh.CreateGPUBuffers();
            GL.ClearColor(Color4.Wheat);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.CullFace(CullFaceMode.Back);
            shader = new Shader("hello-gl.v.glsl", "hello-gl.f.glsl");

            GL.GenBuffers(1, out buf);
            GL.BindBuffer(BufferTarget.ArrayBuffer, buf);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(mesh.VertexBuffer.Length * sizeof(float)), mesh.VertexBuffer, BufferUsageHint.StaticDraw);
            GL.GenBuffers(2, out buf2);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, buf2);
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(mesh.IndexBuffer.Length * sizeof(ushort)), mesh.IndexBuffer, BufferUsageHint.StaticDraw);

            CreateShaders();
            mouseX = X + (Width / 2);
            mouseY = Y + (Height / 2);

            CursorVisible = false;

            OpenTK.Input.Mouse.SetPosition((double)mouseX, (double)mouseY);
            lastState = OpenTK.Input.Mouse.GetState();

            CursorVisible = false;
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            base.OnLoad (e);
        }
예제 #2
0
        protected override void OnLoad(EventArgs e)
        {
            ColladaXML daeReader = new ColladaXML("collada_schema_1_4.xsd");
            Console.WriteLine("Parsing File...");
            daeReader.Parse(Paths.ModelPath + "texobj.dae");
            mesh = daeReader.Mesh.Elements[0];
            mesh.Optimise(new NormalSmoother());
            mesh.CreateGPUBuffers();
            GL.ClearColor(OpenTK.Graphics.Color4.Wheat);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.CullFace(CullFaceMode.Back);
            shader = new Shader("test.v.glsl", "test.f.glsl");
            lineDrawer = new Shader("linedrawer.v.glsl", "linedrawer.f.glsl");

            /*
            GL.GenBuffers(1, out buf);
            GL.BindBuffer(BufferTarget.ArrayBuffer, buf);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(mesh.VertexBuffer.Length * sizeof(float)), mesh.VertexBuffer, BufferUsageHint.StaticDraw);
            GL.GenBuffers(2, out buf2);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, buf2);
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(mesh.IndexBuffer.Length * sizeof(ushort)), mesh.IndexBuffer, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            */
            CreateShaders();
            mouseX = X + (Width / 2);
            mouseY = Y + (Height / 2);

            CursorVisible = false;

            OpenTK.Input.Mouse.SetPosition((double)mouseX, (double)mouseY);
            lastState = OpenTK.Input.Mouse.GetState();

            CursorVisible = false;
            GenerateDebugBuffer("NORMAL");
            cubetex = new Texture("test.png");
            cubenorm = new Texture("testN.png");
            megamanTex = new Texture("megamansheet.png");
            animator = new Animator();
            Animation animation = new Animation();
            animation.speed = 10.0d;

            animation.Add(20, 60, 40, 50);
            animation.Add(60, 60, 40, 50);
            animation.Add(100, 60, 40, 50);
            animation.Add(140, 60, 40, 50);
            animation.Add(180, 60, 40, 50);
            animation.Add(220, 60, 40, 50);

            animator.AddAnimation("default", animation);

            base.OnLoad (e);
        }
예제 #3
0
        void IMeshOptimiser.Apply(float[] originalVertexBuffer, ushort[] originalIndexBuffer, MeshElement meshElement)
        {
            _vertexDeclaration = meshElement.VertexDeclaration;
            _meshElement = meshElement;
            _originalIndexBuffer = originalIndexBuffer;
            unsmoothedChannels = new List<VertexChannel>();
            Dictionary<int, List<int>> smoothingCandidates = new Dictionary<int, List<int>>();

            foreach (VertexChannel channel in _vertexDeclaration.channels)
            {
                if (channel.Name != "NORMAL" && channel.Name != "TANGENT" && channel.Name != "BITANGENT")
                    unsmoothedChannels.Add(channel);
            }

            List<int> uniqueVertices = new List<int>(meshElement.VertexCount);

            for (int i = 0; i < meshElement.VertexCount; ++i)
            {
                int matching = -1;
                foreach (int j in uniqueVertices)
                {
                    if (ChannelsMatch(i, j))
                    {
                        matching = j;
                        break;
                    }
                }
                if (matching >= 0)
                {
                    if (smoothingCandidates.ContainsKey(matching))
                    {
                        smoothingCandidates[matching].Add(i);
                    }
                    else
                    {
                        smoothingCandidates.Add(matching, new List<int>());
                        smoothingCandidates[matching].Add(i);
                    }
                }
                else
                {
                    uniqueVertices.Add(i);
                }
            }

            _optimisedVertexBuffer = new float[uniqueVertices.Count * _vertexDeclaration.Stride];
            _optimisedIndexBuffer = new ushort[originalIndexBuffer.Length];

            for (int i = 0; i < uniqueVertices.Count; ++i)
            {
                MeshHelper.CopyFloatArray(originalVertexBuffer, uniqueVertices[i] * _vertexDeclaration.Stride, _optimisedVertexBuffer, i * _vertexDeclaration.Stride, _vertexDeclaration.Stride);
                ChangeIndices(uniqueVertices[i], i);

                if (smoothingCandidates.ContainsKey(uniqueVertices[i]))
                {
                    foreach (int j in smoothingCandidates[uniqueVertices[i]])
                    {
                        if (meshElement.VertexDeclaration.ContainsChannel("TANGENT"))
                        {
                            float[] tangent = meshElement.ReadAttribute("TANGENT", j);
                            MeshHelper.AddFloatArray(tangent, 0, _optimisedVertexBuffer, i * _vertexDeclaration.Stride + _vertexDeclaration.GetChannel("TANGENT").Offset, 3);
                            float[] bitangent = meshElement.ReadAttribute("BITANGENT", j);
                            MeshHelper.AddFloatArray(bitangent, 0, _optimisedVertexBuffer, i * _vertexDeclaration.Stride + _vertexDeclaration.GetChannel("BITANGENT").Offset, 3);
                        }
                        float[] normal = meshElement.ReadAttribute("NORMAL", j);
                        MeshHelper.AddFloatArray(normal, 0, _optimisedVertexBuffer, i * _vertexDeclaration.Stride + _vertexDeclaration.GetChannel("NORMAL").Offset, 3);
                        ChangeIndices(j, i);
                    }
                }
                MeshHelper.Normalize(_optimisedVertexBuffer, i * _vertexDeclaration.Stride + _vertexDeclaration.GetChannel("NORMAL").Offset, 3);
                if (meshElement.VertexDeclaration.ContainsChannel("TANGENT"))
                {
                    MeshHelper.Normalize(_optimisedVertexBuffer, i * _vertexDeclaration.Stride + _vertexDeclaration.GetChannel("TANGENT").Offset, 3);
                    MeshHelper.Normalize(_optimisedVertexBuffer, i * _vertexDeclaration.Stride + _vertexDeclaration.GetChannel("BITANGENT").Offset, 3);
                }
            }
        }
예제 #4
0
        public MeshElement Parse(XPathNavigator nav, string geomName, bool generateTangents = false)
        {
            Name = geomName;
            nsName = nav.GetNamespace("c");

            var mesh = nav.SelectSingleNode("c:mesh", nsManager);
            if (mesh == null)
                throw new GeometryParserException("Geometry does not contain mesh!");

            ParseMesh(mesh);

            CreateArrays(generateTangents);

            MeshElement retMesh = new MeshElement(_vertexDeclaration, vertexData, indexData);
            return retMesh;
        }