问题描述
动态绘制有问题,无法理解为什么不渲染的原因。这是绑定代码
public void GenerateAttributespolygonDynamic(ref int VBO,ref int VAO,ref int EBO,int ArrayLength,int IndiciesLength)
{
VBO = GL.GenBuffer();
VAO = GL.GenVertexArray();
EBO = GL.GenBuffer();
GL.BindVertexArray(VAO);
GL.BindBuffer(BufferTarget.ArrayBuffer,VBO);
GL.BufferData(BufferTarget.ArrayBuffer,sizeof(float) * ArrayLength,IntPtr.Zero,BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ElementArrayBuffer,EBO);
GL.BufferData(BufferTarget.ElementArrayBuffer,sizeof(uint) * IndiciesLength,BufferUsageHint.DynamicDraw);
GL.VertexAttribPointer(0,2,VertexAttribPointerType.Float,false,6 * sizeof(float),0);
GL.EnabLevertexAttribArray(0);
GL.VertexAttribPointer(1,4,2 * sizeof(float));
GL.EnabLevertexAttribArray(1);
}
VBO 由 2 个浮点型 XY 坐标和 4 个 RGBA 型浮点型组成。在这个绑定之后,我简单地调用了 draw 函数并且在画布中看不到任何东西
public void Draw()
{
float[] Verticies = new float[]
{
-0.5f,0.5f,Color4.Red.R,Color4.Red.G,Color4.Red.B,Color4.Red.A,-0.5f,Color4.Red.A
};
uint[] Indicies = new uint[]
{
0,1,3,3
};
GL.BindBuffer(BufferTarget.ArrayBuffer,VBO);
GL.BufferSubData(BufferTarget.ArrayBuffer,sizeof(float) * Verticies.Length,Verticies);
GL.BindBuffer(BufferTarget.ArrayBuffer,0);
GL.BindBuffer(BufferTarget.ElementArrayBuffer,EBO);
GL.BufferSubData(BufferTarget.ElementArrayBuffer,sizeof(uint) * Indicies.Length,Indicies);
GL.BindBuffer(BufferTarget.ElementArrayBuffer,0);
GL.BindVertexArray(VAO);
GL.UseProgram(ProgramID);
GL.DrawElements(PrimitiveType.Triangles,Indicies.Length,DrawElementsType.UnsignedInt,0);
GL.BindVertexArray(0);
}
希望有人能帮助我。着色器简单且正确,并且在绑定 STATIC_DRAW 类型时工作正常。在动态渲染对象时,我需要使用 Dynamic_Draw 方法和 BufferSubData 解决其他问题,这段代码是我卡住的示例。非常感谢帮助
解决方法
Index buffers 存储在 Vertex Array Object 中。当您调用 GL.BindBuffer(BufferTarget.ElementArrayBuffer,0);
(并且 VAO 已绑定)时,绑定被破坏。
删除
GL.BindBuffer(BufferTarget.ElementArrayBuffer,0);
当缓冲区绑定到目标 BufferTarget.ElementArrayBuffer
时,此缓冲区将关联到当前绑定的顶点数组对象。这与 BufferTarget.ArrayBuffer
的行为不同。
当您初始化索引时,绑定 VAO 就足够了,因为索引缓冲区之前已经分配给了 VAO,在 GenerateAttributesPolygonDynamic
中:
GL.BindVertexArray(VAO);
GL.BufferSubData(BufferTarget.ElementArrayBuffer,IntPtr.Zero,sizeof(uint) * Indicies.Length,Indicies);
,
找到了解决方案。调用方法 // I added 'animation_by_name' dictionary to my character to access animations easily
//
const animation_action_object = this.mixer.animation_by_name['Roundhouse Right Kick']
const animation_duration = animation_action_object._clip.duration
const num_of_frames = animation_action_object._clip.tracks[0].times.length
const curr_time = animation_action_object.time
const curr_frame = Math.round(curr_time / animation_duration * num_of_frames)
const x = animation_action_object._clip.tracks[52].values[curr_frame * 4 + 0]
const y = animation_action_object._clip.tracks[52].values[curr_frame * 4 + 1]
const z = animation_action_object._clip.tracks[52].values[curr_frame * 4 + 2]
const w = animation_action_object._clip.tracks[52].values[curr_frame * 4 + 3]
const quaternion = new THREE.Quaternion(x,y,z,w)
let euler = new THREE.Euler()
euler.setFromQuaternion(quaternion)
console.log(euler);
时,我设置了不正确的 ArrayLength 参数而没有颜色字节。非常感谢你们所有人。话题需要关闭。