Пример #1
0
def newSetupJoints(obj, joints):
    the.Locations = {}
    for (key, typ, data) in joints:
        #print(key)
        if typ == 'j':
            loc = mh2proxy.calcJointPos(obj, data)
            the.Locations[key] = loc
            the.Locations[data] = loc
        elif typ == 'v':
            v = int(data)
            the.Locations[key] = obj.verts[v].co
        elif typ == 'x':
            the.Locations[key] = [
                float(data[0]),
                float(data[2]), -float(data[1])
            ]
        elif typ == 'vo':
            v = int(data[0])
            loc = obj.verts[v].co
            the.Locations[key] = [
                loc[0] + float(data[1]), loc[1] + float(data[3]),
                loc[2] - float(data[2])
            ]
        elif typ == 'vl':
            ((k1, v1), (k2, v2)) = data
            loc1 = obj.verts[int(v1)].co
            loc2 = obj.verts[int(v2)].co
            the.Locations[key] = vadd(vmul(loc1, k1), vmul(loc2, k2))
        elif typ == 'f':
            (raw, head, tail, offs) = data
            rloc = the.Locations[raw]
            hloc = the.Locations[head]
            tloc = the.Locations[tail]
            #print(raw, rloc)
            vec = aljabr.vsub(tloc, hloc)
            vec2 = aljabr.vdot(vec, vec)
            vraw = aljabr.vsub(rloc, hloc)
            x = aljabr.vdot(vec, vraw) / vec2
            rvec = aljabr.vmul(vec, x)
            nloc = aljabr.vadd(hloc, rvec, offs)
            #print(key, nloc)
            the.Locations[key] = nloc
        elif typ == 'b':
            the.Locations[key] = the.Locations[data]
        elif typ == 'p':
            x = the.Locations[data[0]]
            y = the.Locations[data[1]]
            z = the.Locations[data[2]]
            the.Locations[key] = [x[0], y[1], z[2]]
        elif typ == 'vz':
            v = int(data[0])
            z = obj.verts[v].co[2]
            loc = the.Locations[data[1]]
            the.Locations[key] = [loc[0], loc[1], z]
        elif typ == 'X':
            r = the.Locations[data[0]]
            (x, y, z) = data[1]
            r1 = [float(x), float(y), float(z)]
            the.Locations[key] = aljabr.vcross(r, r1)
        elif typ == 'l':
            ((k1, joint1), (k2, joint2)) = data
            the.Locations[key] = vadd(vmul(the.Locations[joint1], k1),
                                      vmul(the.Locations[joint2], k2))
        elif typ == 'o':
            (joint, offsSym) = data
            if type(offsSym) == str:
                offs = the.Locations[offsSym]
            else:
                offs = offsSym
            the.Locations[key] = vadd(the.Locations[joint], offs)
        else:
            raise NameError("Unknown %s" % typ)
    return
Пример #2
0
    def direction(self):

        direction = vnorm(self.offset)
        axis = vnorm(vcross([0.0, 0.0, 1.0], direction))
        angle = acos(vdot([0.0, 0.0, 1.0], direction))
        return axisAngleToQuaternion(axis, angle)
Пример #3
0
 def direction(self):
     direction = vnorm(self.offset)
     axis = vnorm(vcross([0.0, 0.0, 1.0], direction))
     angle = acos(vdot([0.0, 0.0, 1.0], direction))
     return axisAngleToQuaternion(axis, angle)
Пример #4
0
 def onShow(self, event):
 
     gui3d.TaskView.onShow(self, event)
     
     human = gui3d.app.selectedHuman
     human.hide()
     
     if not self.mesh:
     
         self.mesh = module3d.Object3D('texture_tool')
     
         self.mesh.uvValues = []
         self.mesh.indexBuffer = []
         
         # create group
         fg = self.mesh.createFaceGroup('texture_tool')
        
         self.mesh.area = 0.0
         for f in human.mesh.faces:
             verts = [self.mesh.createVertex(v.co) for v in f.verts]
             uv = [human.mesh.uvValues[i] for i in f.uv]
             face = fg.createFace(verts, uv)
             face.area = vlen(vcross(vsub(verts[2].co, verts[0].co), vsub(verts[3].co, verts[1].co))) / 2.0
             face.uvArea = vlen(vcross(vsub(uv[2] + [0.0], uv[0] + [0.0]), vsub(uv[3] + [0.0], uv[1] + [0.0]))) / 2.0
             self.mesh.area += face.area
             
         for f in self.mesh.faces:
             index = min(510, max(0, int(f.uvArea*510.0/(f.area/self.mesh.area))))
             if index > 255:
                 f.setColor([255 - (index - 255), 255 - (index - 255), 255, 255])
             else:
                 f.setColor([255, index, index, 255])
             
                 
         self.mesh.texture = human.mesh.texture
         self.mesh.setCameraProjection(0)
         self.mesh.setShadeless(1)
         self.mesh.updateIndexBuffer()
         
         self.object = self.addObject(gui3d.Object([0, 0, 0], self.mesh, True))
         
     else:
     
         self.mesh.area = 0.0
         for f in self.mesh.faces:
             for i, v in enumerate(f.verts):
                 v.co = human.mesh.faces[f.idx].verts[i].co[:]
             verts = f.verts
             f.area = vlen(vcross(vsub(verts[2].co, verts[0].co), vsub(verts[3].co, verts[1].co))) / 2.0
             self.mesh.area += f.area
     
         for f in self.mesh.faces:
             index = min(510, max(0, int(f.uvArea*510.0/(f.area/self.mesh.area))))
             if index > 255:
                 f.setColor([255 - (index - 255), 255 - (index - 255), 255, 255])
             else:
                 f.setColor([255, index, index, 255])
     
         self.mesh.update()
         if self.textured.selected:
             self.object.setTexture(human.mesh.texture)
Пример #5
0
def newSetupJoints (obj, joints):
    the.Locations = {}
    for (key, typ, data) in joints:
        #print(key)
        if typ == 'j':
            loc = mh2proxy.calcJointPos(obj, data)
            the.Locations[key] = loc
            the.Locations[data] = loc
        elif typ == 'v':
            v = int(data)
            the.Locations[key] = obj.verts[v].co
        elif typ == 'x':
            the.Locations[key] = [float(data[0]), float(data[2]), -float(data[1])]
        elif typ == 'vo':
            v = int(data[0])
            loc = obj.verts[v].co
            the.Locations[key] = [loc[0]+float(data[1]), loc[1]+float(data[3]), loc[2]-float(data[2])]
        elif typ == 'vl':
            ((k1, v1), (k2, v2)) = data
            loc1 = obj.verts[int(v1)].co
            loc2 = obj.verts[int(v2)].co
            the.Locations[key] = vadd(vmul(loc1, k1), vmul(loc2, k2))
        elif typ == 'f':
            (raw, head, tail, offs) = data
            rloc = the.Locations[raw]
            hloc = the.Locations[head]
            tloc = the.Locations[tail]
            #print(raw, rloc)
            vec = aljabr.vsub(tloc, hloc)
            vec2 = aljabr.vdot(vec, vec)
            vraw = aljabr.vsub(rloc, hloc)
            x = aljabr.vdot(vec, vraw) / vec2
            rvec = aljabr.vmul(vec, x)
            nloc = aljabr.vadd(hloc, rvec, offs)
            #print(key, nloc)
            the.Locations[key] = nloc
        elif typ == 'b':
            the.Locations[key] = the.Locations[data]
        elif typ == 'p':
            x = the.Locations[data[0]]
            y = the.Locations[data[1]]
            z = the.Locations[data[2]]
            the.Locations[key] = [x[0],y[1],z[2]]
        elif typ == 'vz':
            v = int(data[0])
            z = obj.verts[v].co[2]
            loc = the.Locations[data[1]]
            the.Locations[key] = [loc[0],loc[1],z]
        elif typ == 'X':
            r = the.Locations[data[0]]
            (x,y,z) = data[1]
            r1 = [float(x), float(y), float(z)]
            the.Locations[key] = aljabr.vcross(r, r1)
        elif typ == 'l':
            ((k1, joint1), (k2, joint2)) = data
            the.Locations[key] = vadd(vmul(the.Locations[joint1], k1), vmul(the.Locations[joint2], k2))
        elif typ == 'o':
            (joint, offsSym) = data
            if type(offsSym) == str:
                offs = the.Locations[offsSym]
            else:
                offs = offsSym
            the.Locations[key] = vadd(the.Locations[joint], offs)
        else:
            raise NameError("Unknown %s" % typ)
    return