def NewObject(flag): global ob, me, sc if flag == 1: DumpData() DeselectAllObjects() sc = Scene.GetCurrent() cursorpos = Window.GetCursorPos() ob = Object.New('Mesh', 'Cyl_') me = NMesh.New('MyCylMesh') ob.setLocation(cursorpos) ob.link(me) sc.link(ob)
def loadgeomnode(file, words, pdata): def objprop(file, words, data): data['nwnprops'].write('%s.%s=%s\n'%(data['object'].name, words[0], words[1])) def parent(file, words, data): if words[1]=='NULL': data['nwnprops'].write('SCENE.baseobjectname=%s\n'%data['object'].name) else: p=Object.Get(words[1]) p.makeParent([data['object']]) def position(file, words, data): data['object'].setLocation(map(float, words[1:4])) def orientation(file, words, data): data['object'].setEuler(nwn2euler(map(float, words[1:5]))) def bitmap(file, words, data): global filename imagefname=os.path.dirname(filename) + '\\' + words[1]+'.tga' try: image=Image.Get(imagefname) except NameError: try: image=Image.Load(imagefname) except IOError: print '**************ERROR********************' print 'file : ' + filename print 'texture : ' + words[1]+'.tga unknown in directory : ' print os.path.dirname(filename) print 'check if the bitmap exists with an other extension => translate in tga format' print 'or move it in the directory of the .mdl model' print 'null.tga could be used instead of the current one' print '**************ERROR********************' imagefname=os.path.dirname(filename) + '\\null.tga' image=Image.Load(imagefname) pass data['nwnprops'].write('%s.texture=%s\n'%(data['object'].name, words[1])) data['texture']=image def verts(file, words, data): vertexcount=int(words[1]) while vertexcount>0: data['mesh'].verts.append(apply(NMesh.Vert, map(float, file.readline().split()))) vertexcount-=1 # Well, Torlack's NWN model decompiler puts faces after tverts. # NWN's sample file had it the other way around, so we support both. def fixuvs(data): mesh=data['mesh'] uvi=data['uvi'] uvc=data['uvc'] for fi in range(len(uvi)): face=mesh.faces[fi] face.uv=map(lambda x: uvc[x], uvi[fi]) face.mode=NMesh.FaceModes.TEX # TODO: recalculate the normals. They're all random, and PutRaw cancels transforms. #NMesh.PutRaw(mesh, data['object'].name) mesh.update() def faces(file, words, data): uvi=[] mesh=data['mesh'] facecount=int(words[1]) while facecount>0: f=NMesh.Face() line=map(int, file.readline().split()) f.image=data['texture'] for v in line[0:3]: f.v.append(mesh.verts[v]) f.smooth=line[3] mesh.faces.append(f) uvi.append(line[4:7]) facecount-=1 data['uvi']=uvi if data.has_key('uvc'): fixuvs(data) def tverts(file, words, data): mesh=data['mesh'] uvc=[] uvcount=int(words[1]) while uvcount>0: uvc.append(tuple(map(float, file.readline().split()[0:2]))) uvcount-=1 data['uvc']=uvc if data.has_key('uvi'): fixuvs(data) nodedict={'parent': parent, 'position': position, 'bitmap': bitmap, 'verts': verts, 'faces': faces, 'endnode': linereaderbreak, 'tverts': tverts, 'orientation': orientation, 'tilefade': objprop} data=None if words[1]=='dummy': data={'object': Object.New('Empty')} elif words[1]=='trimesh': data={'object': Object.New('Mesh'), 'mesh': NMesh.New(words[2])} data['object'].link(data['mesh']) else: return # unsupported node type # Note: Blender 2.27, New(type, name) didn't work. object.name worked. data['object'].name=words[2] data['nwnprops']=pdata['nwnprops'] linereader(file, nodedict, data) pdata['scene'].link(data['object'])
#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, #OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #============================================================================= # This script must run from a editor window in Blender. It take a mesh from a .vtk file and # import it to the scene in Blender import vtk import Blender from Blender import NMesh import Tex_VTKBlender reload(Tex_VTKBlender) #Cargamos ahora la malla de vtk empleada en ESQUI reader = vtk.vtkPolyDataReader() reader.SetFileName("Poner aqui el nombre del archivo .vtk a importar a Blender") mapper = vtk.vtkPolyDataMapper() mapper.SetInput(reader.GetOutput()) me = NMesh.New() me = Tex_VTKBlender.PolyDataMapperToBlender(mapper) try: # Si estamos con la API BPython 2.42 NMesh.PutRaw(me) else: # Si estamos con la API BPython 2.36 Blender.Scene.AddMesh(me)