请问MeshTaichi中如何对顶点x求导

image

代码附上,能量函数是我乱写的关于顶点x的矩阵,运行会报错,不知道如何使能量对顶点x求导

import taichi as ti 
import meshtaichi_patcher as Patcher

ti.init(arch=ti.cuda)

model = Patcher.load_mesh_rawdata("./models/armadillo0/armadillo0.1.node")
mesh = Patcher.load_mesh(model, relations=["CV","VV"])
mesh.verts.place({'x' :ti.math.vec3},
                  needs_grad=True)
mesh.verts.x.from_numpy(mesh.get_position_as_numpy())
total_energy = ti.field(ti.f32, (), needs_grad=True)

@ti.kernel
def compute_energy():
    for e in mesh.cells:
        a = mesh.verts.x[e.verts[0].id]
        b = mesh.verts.x[e.verts[1].id]
        c = mesh.verts.x[e.verts[2].id]
        d = mesh.verts.x[e.verts[3].id]
        Dm= ti.Matrix.cols([b - a, c - a,d-a])
        element_energy_density = 2.0*(Dm.transpose()@Dm).trace()
        total_energy[None] +=element_energy_density
        
with ti.ad.Tape(total_energy):
    compute_energy()
1 个赞

autodiff现在目前还没有对meshtaichi做完全的支持