def __init__(self, node, filepath, scale3d, offset, name_suffix='', generatedDir=None): r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi global idxVisualModel self.node = node.createChild('visual' + name_suffix) # node self.model = self.node.createObject('VisualModel', name='visual' + str(idxVisualModel), fileMesh=filepath, scale3d=concat(scale3d), translation=concat(offset[:3]), rotation=concat(r)) if generatedDir is None: self.mapping = self.node.createObject( 'LinearMapping', template='Affine,ExtVec3f', name='mapping') else: serialization.importLinearMapping( self.node, generatedDir + "_visualmapping.json") idxVisualModel += 1
def transformToData(scale, offset, timeOffset=0, timeScale=1, isPerspective=0): """ Returns a transform, formatted to sofa data given voxelsize, rigid position (offset), time and camera parameters """ return concat(offset[:3]) + ' ' + concat( quat.to_euler(offset[3:]) * 180. / math.pi) + ' ' + concat( scale) + ' ' + str(timeOffset) + ' ' + str(timeScale) + ' ' + str( int(isPerspective))
def __init__(self, node, filepath, scale3d, offset, name_suffix='', generatedDir=None): r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.node = node.createChild('collision' + name_suffix) # node self.loader = SofaPython.Tools.meshLoader(self.node, filename=filepath, name='loader', scale3d=concat(scale3d), translation=concat( offset[:3]), rotation=concat(r), triangulate=True) self.topology = self.node.createObject('MeshTopology', name='topology', src='@loader') self.dofs = self.node.createObject('MechanicalObject', name='dofs', template='Vec3' + template_suffix) self.triangles = self.node.createObject('TriangleModel', name='model') if generatedDir is None: self.mapping = self.node.createObject('LinearMapping', template='Affine,Vec3' + template_suffix, name='mapping') else: serialization.importLinearMapping( self.node, generatedDir + "_collisionmapping.json") self.normals = None
def __init__(self, node, filepath, scale3d, offset): self.node = node.createChild( "collision" ) # node r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.loader = self.node.createObject("MeshObjLoader", name='loader', filename=filepath, scale3d=concat(scale3d), translation=concat(offset[:3]), rotation=concat(r), triangulate=1 ) self.topology = self.node.createObject('MeshTopology', name='topology', src="@loader" ) self.dofs = self.node.createObject('MechanicalObject', name='dofs') self.triangles = self.node.createObject('TriangleModel', template='Vec3d', name='model') self.mapping = self.node.createObject('RigidMapping', name="mapping")
def __init__(self, node, filepath, scale3d, offset, name_suffix=''): global idxVisualModel self.node = node.createChild( "visual"+name_suffix ) # node r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.model = self.node.createObject('VisualModel', name="visual"+str(idxVisualModel), fileMesh=filepath, scale3d=concat(scale3d), translation=concat(offset[:3]) , rotation=concat(r), useNormals=False, updateNormals=True) self.mapping = self.node.createObject('RigidMapping', name="mapping") idxVisualModel+=1
def __init__(self, node, filepath, scale3d, offset, name_suffix='', generatedDir=None): r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi global idxVisualModel; self.node = node.createChild('visual'+name_suffix) # node self.model = self.node.createObject('VisualModel', name='visual'+str(idxVisualModel), fileMesh=filepath, scale3d=concat(scale3d), translation=concat(offset[:3]), rotation=concat(r)) if generatedDir is None: self.mapping = self.node.createObject('LinearMapping', template='Affine,ExtVec3f', name='mapping') else: serialization.importLinearMapping(self.node, generatedDir+"_visualmapping.json") idxVisualModel+=1
def __init__(self, node, filepath, scale3d, offset, name_suffix=''): self.node = node.createChild( "collision"+name_suffix ) # node r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.loader = SofaPython.Tools.meshLoader(self.node, filename=filepath, name='loader', scale3d=concat(scale3d), translation=concat(offset[:3]) , rotation=concat(r), triangulate=True) self.topology = self.node.createObject('MeshTopology', name='topology', src="@loader" ) self.dofs = self.node.createObject('MechanicalObject', name='dofs', template="Vec3"+template_suffix ) self.triangles = self.node.createObject('TriangleModel', name='model') self.mapping = self.node.createObject('RigidMapping', name="mapping") self.normals = None self.visual = None
def __init__(self, node, filepath, scale3d, offset, name_suffix='', generatedDir=None): r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.node = node.createChild('collision'+name_suffix) # node self.loader = SofaPython.Tools.meshLoader(self.node, filename=filepath, name='loader', scale3d=concat(scale3d), translation=concat(offset[:3]) , rotation=concat(r), triangulate=True) self.topology = self.node.createObject('MeshTopology', name='topology', src='@loader') self.dofs = self.node.createObject('MechanicalObject', name='dofs', template='Vec3'+template_suffix) self.triangles = self.node.createObject('TriangleModel', name='model') if generatedDir is None: self.mapping = self.node.createObject('LinearMapping', template='Affine,Vec3'+template_suffix, name='mapping') else: serialization.importLinearMapping(self.node, generatedDir+"_collisionmapping.json") self.normals = None
def __init__(self, node, filepath, scale3d, offset): self.node = node.createChild("visual") # node r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.model = self.node.createObject('VisualModel', template='ExtVec3f', name='model', fileMesh=filepath, scale3d=concat(scale3d), translation=concat(offset[:3]), rotation=concat(r)) self.mapping = self.node.createObject('RigidMapping', name="mapping")
def loadVisualCylinder(self, meshPath, offset=[0, 0, 0, 0, 0, 0, 1], scale=[1, 1, 1], color=[1, 1, 1, 1], radius=0.01, **kwargs): r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.visual = self.node.createObject("OglCylinderModel", radius=radius, position="@topology.position", edges="@topology.edges") self.normals = self.visual
def __init__(self, node, filepath, scale3d, offset, name_suffix=''): global idxVisualModel self.node = node.createChild("visual" + name_suffix) # node r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.model = self.node.createObject('VisualModel', name="visual" + str(idxVisualModel), fileMesh=filepath, scale3d=concat(scale3d), translation=concat(offset[:3]), rotation=concat(r), useNormals=False, updateNormals=True) self.mapping = self.node.createObject('RigidMapping', name="mapping") idxVisualModel += 1
def loadMesh(self, meshPath, offset=[0, 0, 0, 0, 0, 0, 1], scale=[1, 1, 1], triangulate=False): r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.meshLoader = SofaPython.Tools.meshLoader(self.node, meshPath, translation=concat( offset[:3]), rotation=concat(r), scale3d=concat(scale), triangulate=triangulate) self.topology = self.node.createObject("MeshTopology", name="topology", src="@" + self.meshLoader.name)
def __init__(self, node, filepath, scale3d, offset): self.node = node.createChild("collision") # node r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.loader = self.node.createObject("MeshObjLoader", name='loader', filename=filepath, scale3d=concat(scale3d), translation=concat( offset[:3]), rotation=concat(r), triangulate=1) self.topology = self.node.createObject('MeshTopology', name='topology', src="@loader") self.dofs = self.node.createObject('MechanicalObject', name='dofs') self.triangles = self.node.createObject('TriangleModel', template='Vec3d', name='model') self.mapping = self.node.createObject('RigidMapping', name="mapping")
def loadVisual(self, meshPath, offset=[0, 0, 0, 0, 0, 0, 1], scale=[1, 1, 1], color=[1, 1, 1, 1], **kwargs): r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.visual = self.node.createObject("VisualModel", name="model", filename=meshPath, translation=concat(offset[:3]), rotation=concat(r), scale3d=concat(scale), color=concat(color), putOnlyTexCoords=True, computeTangents=True, **kwargs) # self.visual = self.node.createObject("VisualModel", name="model", filename=meshPath, translation=concat(offset[:3]) , rotation=concat(r), scale3d=concat(scale), color=concat(color), **kwargs) self.visual.setColor( color[0], color[1], color[2], color[3] ) # the previous assignement fails when reloading a scene.. self.normals = self.visual
def __init__(self, node, filepath, scale3d, offset, name_suffix=''): self.node = node.createChild("collision" + name_suffix) # node r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.loader = SofaPython.Tools.meshLoader(self.node, filename=filepath, name='loader', scale3d=concat(scale3d), translation=concat( offset[:3]), rotation=concat(r), triangulate=True) self.topology = self.node.createObject('MeshTopology', name='topology', src="@loader") self.dofs = self.node.createObject('MechanicalObject', name='dofs', template="Vec3" + template_suffix) self.triangles = self.node.createObject('TriangleModel', name='model') self.mapping = self.node.createObject('RigidMapping', name="mapping") self.normals = None self.visual = None
def addMeshLoader( self, meshFile, value, insideValue=None, closingValue=None, roiIndices=list(), roiValue=list(), name=None, offset=[0, 0, 0, 0, 0, 0, 1], scale=[1, 1, 1], ): mesh = Image.Mesh(value, insideValue) _name = name if not name is None else os.path.splitext(os.path.basename(meshFile))[0] mesh.mesh = SofaPython.Tools.meshLoader( self.node, meshFile, name="meshLoader_" + _name, triangulate=True, translation=concat(offset[:3]), rotation=concat(Quaternion.to_euler(offset[3:]) * 180.0 / math.pi), scale3d=concat(scale), ) self.__addMesh(mesh, closingValue, roiIndices, roiValue, _name)
def addMeshLoader(self, meshFile, value, insideValue=None, closingValue=None, roiIndices=list(), roiValue=list(), name=None, offset = [0,0,0,0,0,0,1], scale=[1,1,1]): mesh = Image.Mesh(value, insideValue) _name = name if not name is None else os.path.splitext(os.path.basename(meshFile))[0] mesh.mesh = SofaPython.Tools.meshLoader(self.node, meshFile, name="meshLoader_"+_name, triangulate=True, translation=concat(offset[:3]) , rotation=concat(Quaternion.to_euler(offset[3:]) * 180.0 / math.pi), scale3d=concat(scale)) self.__addMesh(mesh,closingValue,roiIndices,roiValue,_name)
def loadVisual(self, meshPath, offset = [0,0,0,0,0,0,1], scale=[1,1,1], color=[1,1,1,1],**kwargs): r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.visual = self.node.createObject("VisualModel", name="model", filename=meshPath, translation=concat(offset[:3]) , rotation=concat(r), scale3d=concat(scale), color=concat(color), putOnlyTexCoords=True,computeTangents=True,**kwargs) # self.visual = self.node.createObject("VisualModel", name="model", filename=meshPath, translation=concat(offset[:3]) , rotation=concat(r), scale3d=concat(scale), color=concat(color), **kwargs) self.visual.setColor(color[0],color[1],color[2],color[3]) # the previous assignement fails when reloading a scene.. self.normals = self.visual
def loadMesh(self, meshPath, offset = [0,0,0,0,0,0,1], scale=[1,1,1], triangulate=False): r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.meshLoader = SofaPython.Tools.meshLoader(self.node, meshPath, translation=concat(offset[:3]) , rotation=concat(r), scale3d=concat(scale), triangulate=triangulate) self.topology = self.node.createObject("MeshTopology", name="topology", src="@"+self.meshLoader.name )
def transformToData(scale,offset,timeOffset=0,timeScale=1,isPerspective=0): """ Returns a transform, formatted to sofa data given voxelsize, rigid position (offset), time and camera parameters """ return concat(offset[:3])+' '+concat(quat.to_euler(offset[3:])*180./math.pi)+' '+concat(scale)+' '+str(timeOffset)+' '+str(timeScale)+' '+str(int(isPerspective))
def loadVisualCylinder(self, meshPath, offset = [0,0,0,0,0,0,1], scale=[1,1,1], color=[1,1,1,1],radius=0.01,**kwargs): r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.visual = self.node.createObject("OglCylinderModel", radius=radius, position="@topology.position", edges="@topology.edges" ) self.normals = self.visual
def __init__(self, node, filepath, scale3d, offset): self.node = node.createChild( "visual" ) # node r = Quaternion.to_euler(offset[3:]) * 180.0 / math.pi self.model = self.node.createObject('VisualModel', template='ExtVec3f', name='model', fileMesh=filepath, scale3d=concat(scale3d), translation=concat(offset[:3]) , rotation=concat(r) ) self.mapping = self.node.createObject('RigidMapping', name="mapping")