Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nobuyuki83 committed Jun 17, 2024
1 parent abe5a6b commit 905e92c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ Look at the following document.
| [task07](task07) | **Monte Carlo integration2**<br/>Multiple importance sampling | <img src="task07/preview.png" width=100px> |
| task08 | **Skeletal Character Animation**<br>Linear blend skinning, articulated rigid body | <img src="task08/preview.png" width=100px> |
| task09 | TBD | |
| task10 | TBD | |

### Policy

Expand Down
16 changes: 8 additions & 8 deletions task08/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, **kwargs):
self.prog, [(self.vbo_def, '3f', 'in_vert')],
ebo, 4, mode=moderngl.LINES) # tell gpu about the mesh information and how to draw it

# cylinder mesh
# cylinder mesh for frame visualization
(tri2vtx_cyl, vtx2xyz_cyl) = util_for_task08.cylinder_mesh_zup(0.01, 0.05, 16)
ebo = self.ctx.buffer(tri2vtx_cyl) # send triangle index data to GPU (element buffer object)
vbo_cyl = self.ctx.buffer(vtx2xyz_cyl) # send deformed vertex coordinates data to GPU
Expand Down Expand Up @@ -103,8 +103,8 @@ def render(self, time, frame_time):
for idx in range(4): # in gltf each vertex is associated with four bones
w = self.vtx2weights[i_vtx][idx] # rig weight
i_bone = self.vtx2bones[i_vtx][idx] # bone index
inverseBindingMatrix = self.bone2invBindingMatrix[i_bone]
globalTransformation = bone2globalTransformation[i_bone]
inverseBindingMatrix = self.bone2invBindingMatrix[i_bone] # 4x4 inverse binding matrix
globalTransformation = bone2globalTransformation[i_bone] # 4x4 transformation matrix to deformed bone
# write a few lines of codes to compute p1 using the linear blend skinning
# hint: use np.matmul for matrix multiplication
# hint: assume that rig weights w add up to one
Expand All @@ -123,7 +123,7 @@ def render(self, time, frame_time):
view_transf = view_rot_y * view_rot_x * transform_to_center

# draw undeformed mesh in red
self.prog['matrix'].value = tuple(view_transf.flatten())
self.prog['matrix'].value = tuple(view_transf.flatten()) # column major
self.prog['color'].value = (1., 0., 0.)
self.vao_ini.render()

Expand All @@ -138,22 +138,22 @@ def render(self, time, frame_time):
transf = bone2globalTransformation[i_bone]
transf = np.matmul(transf.transpose(), view_transf)
# z_axis
self.prog['matrix'].value = tuple(transf.flatten())
self.prog['matrix'].value = tuple(transf.flatten()) # column-major
self.prog['color'].value = (0., 0.0, 0.8)
self.vao_cyl.render()
# x_axis
x_rot = pyrr.Matrix44.from_y_rotation(math.pi*0.5)
self.prog['matrix'].value = tuple((np.matmul(x_rot.transpose(), transf)).flatten())
self.prog['matrix'].value = tuple((np.matmul(x_rot.transpose(), transf)).flatten()) # column major
self.prog['color'].value = (0.8, 0., 0.)
self.vao_cyl.render()
# y_axis
y_rot = pyrr.Matrix44.from_x_rotation(-math.pi*0.5)
self.prog['matrix'].value = tuple((np.matmul(y_rot.transpose(), transf)).flatten())
self.prog['matrix'].value = tuple((np.matmul(y_rot.transpose(), transf)).flatten()) # column major
self.prog['color'].value = (0.0, 0.8, 0.)
self.vao_cyl.render()

# draw deformed mesh in black
self.prog['matrix'].value = tuple(view_transf.flatten())
self.prog['matrix'].value = tuple(view_transf.flatten()) # column major
self.prog['color'].value = (0., 0., 0.)
self.vao_def.render()

Expand Down

0 comments on commit 905e92c

Please sign in to comment.