public void Attach(SceneNode parent)
        {
            localParent = parent;
            localRoot = parent = new SceneNode(parent);
            var physicsComponent = Record.GetComponent<PhysicsComponent>();
            if (physicsComponent != null) new DebugDrawNode(parent, physicsComponent.Body);

            var transformComponent = Record.GetComponent<TransformComponent>();
            if (meshData == null) return;
            parent = new TransformNode(parent, transformComponent ?? new TransformComponent());
            var animationComponent = Record.GetComponent(default(AnimationComponent), true);
            if (animationComponent != null) parent = new AnimationNode(parent, animationComponent);
            var tri = meshData.Submeshes[0].Triangles;
            var vert = meshData.Submeshes[0].Vertices;
            var vbo = new VertexBuffer(vert.Length * SkinnedVertex.Size, BufferTarget.ArrayBuffer,
                                       BufferUsageHint.StaticDraw);
            var ibo = new VertexBuffer(tri.Length * Vector3i.Size, BufferTarget.ElementArrayBuffer,
                                       BufferUsageHint.StaticDraw);
            vbo.Write(0, vert);
            ibo.Write(0, tri);
            var vboNode = new VBONode(parent, vbo, ibo);
            foreach (var matGroup in from g in meshData.Submeshes group g by g.Material)
            {
                foreach (var geometry in matGroup)
                {
                    var mat = matGroup.Key;
                    new SubmeshNode(new MaterialNode(vboNode, mat), geometry);
                }
            }
        }
Exemple #2
0
		public override void Visit(VBONode node)
		{
			int vPos = this.shader.GetAttribLocation("inVertex");
			int nPos = this.shader.GetAttribLocation("inNormal");
			int tcPos = this.shader.GetAttribLocation("inTexCoord");
			int weightPos = this.shader.GetAttribLocation("inWeights");
			int bonesPos = this.shader.GetAttribLocation("inBones");
			GL.EnableVertexAttribArray(vPos);
			GL.EnableVertexAttribArray(nPos);
			GL.EnableVertexAttribArray(tcPos);
			GL.EnableVertexAttribArray(weightPos);
			GL.EnableVertexAttribArray(bonesPos);
			node.BeginRender();
			GL.VertexAttribPointer(vPos, 3, VertexAttribPointerType.Float, false, SkinnedVertex.Size, 0);
			GL.VertexAttribPointer(nPos, 3, VertexAttribPointerType.Float, true, SkinnedVertex.Size, (IntPtr)12);
			GL.VertexAttribPointer(tcPos, 2, VertexAttribPointerType.Float, false, SkinnedVertex.Size, (IntPtr)24);
			GL.VertexAttribPointer(weightPos, 4, VertexAttribPointerType.Float, false, SkinnedVertex.Size, (IntPtr)32);
			GL.VertexAttribPointer(bonesPos, 4, VertexAttribPointerType.Float, false, SkinnedVertex.Size, (IntPtr)48);
			node.VisitChildren(this);
			node.EndRender();
			GL.DisableVertexAttribArray(vPos);
			GL.DisableVertexAttribArray(nPos);
			GL.DisableVertexAttribArray(tcPos);
			GL.DisableVertexAttribArray(weightPos);
			GL.DisableVertexAttribArray(bonesPos);
		}
Exemple #3
0
 public virtual void Visit(VBONode node)
 {
     this.Visit((SceneNode)node);
 }