Scripts:
Final (?) updates for 2.40 :) : - Bob Holcomb sent a better version of his 3ds importer - Added doc info to bvh2arm: links to doc and mocap tute from author Jean-Baptiste Perin - Alessandro Pirovano improved the Lightwave importer. - Mikael Lagre updated the collada scripts (fixed a bug with camera lens value) - Adam Saltsman improved the wings importer (ongoing work with his pal Toastie). - Anthony D'Agostino GPL'd his scripts (used Blender's BAL license previously) Thanks to all script authors for their work, interest and kindness. Again, Tom (LetterRip) has played an important part in this, thanks and welcome :).
This commit is contained in:
@@ -4,21 +4,30 @@
|
||||
Name: '3D Studio (.3ds)...'
|
||||
Blender: 237
|
||||
Group: 'Import'
|
||||
Tooltip: 'Import from 3DS file format (.3ds).'
|
||||
Tooltip: 'Import from 3DS file format. (.3ds)'
|
||||
"""
|
||||
|
||||
__author__ = ["Bob Holcomb", "Richard L<>rk<72>ng", "Damien McGinnes", "Campbell Barton"]
|
||||
__url__ = ("blender", "elysiun", "http://www.gametutorials.com")
|
||||
__version__ = "0.82"
|
||||
__version__ = "0.92"
|
||||
__bpydoc__ = """\
|
||||
|
||||
3ds Importer
|
||||
|
||||
This script imports a 3ds file and the materials into blender for editing.
|
||||
This script imports a 3ds file and the materials into Blender for editing.
|
||||
|
||||
Loader is based on 3ds loader from www.gametutorials.com(Thanks DigiBen).
|
||||
Loader is based on 3ds loader from www.gametutorials.com (Thanks DigiBen).
|
||||
|
||||
Changes:
|
||||
|
||||
0.92<br>
|
||||
- Added support for diffuse, alpha, spec, bump maps in a single material
|
||||
|
||||
0.9<br>
|
||||
- Reorganized code into object/material block functions<br>
|
||||
- Use of Matrix() to copy matrix data<br>
|
||||
- added support for material transparency<br>
|
||||
|
||||
Changes:<br>
|
||||
0.81a (fork- not 0.9) Campbell Barton 2005-06-08<br>
|
||||
- Simplified import code<br>
|
||||
- Never overwrite data<br>
|
||||
@@ -35,6 +44,8 @@ Changes:<br>
|
||||
|
||||
"""
|
||||
|
||||
# $Id$
|
||||
#
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# Script copyright (C) Bob Holcomb
|
||||
@@ -56,23 +67,130 @@ Changes:<br>
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Importing modules
|
||||
|
||||
import Blender
|
||||
from Blender import NMesh, Scene, Object, Material, Image
|
||||
from Blender import NMesh, Scene, Object, Material, Image, Texture
|
||||
|
||||
import sys, struct, string
|
||||
|
||||
import os
|
||||
|
||||
#this script imports uvcoords as sticky vertex coords
|
||||
#this parameter enables copying these to face uv coords
|
||||
#which shold be more useful.
|
||||
######################################################
|
||||
# Data Structures
|
||||
######################################################
|
||||
#----- Primary Chunk,
|
||||
PRIMARY = long("0x4D4D",16) # should be aat the beginning of each file
|
||||
VERSION = long("0x0002",16) #This gives the version of the .3ds file
|
||||
EDITOR_BLOCK = long("0x3D3D",16) #this is the Editor Data block, contains objects, materials
|
||||
KEYFRAME_BLOCK = long("0xB000",16) #This is the header for all of the key frame info
|
||||
|
||||
#------ sub defines of EDITOR_BLOCK
|
||||
MATERIAL_BLOCK = long("0xAFFF",16) #This stores the Material info
|
||||
OBJECT_BLOCK = long("0x4000",16) #This stores the Object,Camera,Light
|
||||
|
||||
#------ sub defines of OBJECT_BLOCK
|
||||
OBJECT_MESH = long("0x4100",16) # This lets us know that we are reading a new object
|
||||
OBJECT_LIGHT = long("0x4600",16) # This lets un know we are reading a light object
|
||||
OBJECT_CAMERA = long("0x4700",16) # This lets un know we are reading a camera object
|
||||
|
||||
#------ sub defines of OBJECT_MESH
|
||||
MESH_VERTICES = long("0x4110",16) # The objects vertices
|
||||
MESH_FACES = long("0x4120",16) # The objects faces
|
||||
MESH_MATERIAL = long("0x4130",16) # This is found if the object has a material, either texture map or color
|
||||
MESH_UV = long("0x4140",16) # The UV texture coordinates
|
||||
MESH_TRANS_MATRIX = long("0x4160",16) # The Object Matrix
|
||||
MESH_COLOR = long("0x4165",16) # The color of the object
|
||||
MESH_TEXTURE_INFO = long("0x470",16) # Info about the Object Texture
|
||||
|
||||
#------ sub defines of OBJECT_CAMERA
|
||||
CAMERA_CONE = long("0x4710",16) # The camera see cone
|
||||
CAMERA_RANGES = long("0x4720",16) # The camera range values
|
||||
|
||||
#------ sub defines of OBJECT_LIGHT
|
||||
LIGHT_SPOTLIGHT = long("0x4610",16) # A spotlight
|
||||
LIGHT_ATTENUATE = long("0x4625",16) # Light attenuation values
|
||||
|
||||
|
||||
#===========================================================================#
|
||||
# Returns unique name of object/mesh (stops overwriting existing meshes) #
|
||||
#===========================================================================#
|
||||
#------ sub defines of MATERIAL_BLOCK
|
||||
MAT_NAME = long("0xA000",16) # This holds the material name
|
||||
MAT_AMBIENT = long("0xA010",16) # Ambient color of the object/material
|
||||
MAT_DIFFUSE = long("0xA020",16) # This holds the color of the object/material
|
||||
MAT_SPECULAR = long("0xA030",16) # SPecular color of the object/material
|
||||
MAT_SHINESS = long("0xA040",16) # ??
|
||||
MAT_TRANSPARENCY= long("0xA050",16) # Transparency value of material
|
||||
MAT_SELF_ILLUM = long("0xA080",16) # Self Illumination value of material
|
||||
MAT_WIRE = long("0xA085",16) # Only render's wireframe
|
||||
|
||||
MAT_TEXTURE_MAP = long("0xA200",16) # This is a header for a new texture map
|
||||
MAT_SPECULAR_MAP= long("0xA204",16) # This is a header for a new specular map
|
||||
MAT_OPACITY_MAP = long("0xA210",16) # This is a header for a new opacity map
|
||||
MAT_REFLECTION_MAP= long("0xA220",16) # This is a header for a new reflection map
|
||||
MAT_BUMP_MAP = long("0xA230",16) # This is a header for a new bump map
|
||||
MAT_MAP_FILENAME= long("0xA300",16) # This holds the file name of the texture
|
||||
#lots more to add here for maps
|
||||
|
||||
######################################################
|
||||
# Globals
|
||||
######################################################
|
||||
TEXTURE_DICT={}
|
||||
MATERIAL_DICT={}
|
||||
|
||||
|
||||
######################################################
|
||||
# Chunk Class
|
||||
######################################################
|
||||
class chunk:
|
||||
ID=0
|
||||
length=0
|
||||
bytes_read=0
|
||||
|
||||
binary_format="<HI"
|
||||
|
||||
def __init__(self):
|
||||
self.ID=0
|
||||
self.length=0
|
||||
self.bytes_read=0
|
||||
|
||||
def dump(self):
|
||||
print "ID in hex: ", hex(self.ID)
|
||||
print "length: ", self.length
|
||||
print "bytes_read: ", self.bytes_read
|
||||
|
||||
|
||||
######################################################
|
||||
# Helper functions
|
||||
######################################################
|
||||
def read_chunk(file, chunk):
|
||||
temp_data=file.read(struct.calcsize(chunk.binary_format))
|
||||
data=struct.unpack(chunk.binary_format, temp_data)
|
||||
chunk.ID=data[0]
|
||||
chunk.length=data[1]
|
||||
chunk.bytes_read=6
|
||||
|
||||
def skip_to_end(file, skip_chunk):
|
||||
buffer_size=skip_chunk.length-skip_chunk.bytes_read
|
||||
binary_format=str(buffer_size)+"c"
|
||||
temp_data=file.read(struct.calcsize(binary_format))
|
||||
skip_chunk.bytes_read+=buffer_size
|
||||
|
||||
def read_string(file):
|
||||
s=""
|
||||
index=0
|
||||
#read the first character
|
||||
temp_data=file.read(1)
|
||||
data=struct.unpack("c", temp_data)
|
||||
s=s+(data[0])
|
||||
#read in the characters till we get a null character
|
||||
while(ord(s[index])!=0):
|
||||
index+=1
|
||||
temp_data=file.read(1)
|
||||
data=struct.unpack("c", temp_data)
|
||||
s=s+(data[0])
|
||||
the_string=s[:-1] #remove the null character from the string
|
||||
return str(the_string)
|
||||
|
||||
def getUniqueName(name):
|
||||
newName = name
|
||||
uniqueInt = 0
|
||||
@@ -89,435 +207,431 @@ def getUniqueName(name):
|
||||
newName = '%s.%d' % (name, uniqueInt)
|
||||
uniqueInt +=1
|
||||
|
||||
def add_texture_to_material(image, texture, material, mapto):
|
||||
if mapto=="DIFFUSE":
|
||||
map=Texture.MapTo.COL
|
||||
elif mapto=="SPECULAR":
|
||||
map=Texture.MapTo.SPEC
|
||||
elif mapto=="OPACITY":
|
||||
map=Texture.MapTo.ALPHA
|
||||
elif mapto=="BUMP":
|
||||
map=Texture.MapTo.NOR
|
||||
else:
|
||||
print "/tError: Cannot map to ", mapto
|
||||
return
|
||||
|
||||
######################################################
|
||||
# Data Structures
|
||||
######################################################
|
||||
|
||||
#Some of the chunks that we will see
|
||||
#----- Primary Chunk, at the beginning of each file
|
||||
PRIMARY= long("0x4D4D",16)
|
||||
|
||||
#------ Main Chunks
|
||||
OBJECTINFO = long("0x3D3D",16); #This gives the version of the mesh and is found right before the material and object information
|
||||
VERSION = long("0x0002",16); #This gives the version of the .3ds file
|
||||
EDITKEYFRAME= long("0xB000",16); #This is the header for all of the key frame info
|
||||
|
||||
#------ sub defines of OBJECTINFO
|
||||
MATERIAL=45055 #0xAFFF // This stored the texture info
|
||||
OBJECT=16384 #0x4000 // This stores the faces, vertices, etc...
|
||||
|
||||
#>------ sub defines of MATERIAL
|
||||
MATNAME = long("0xA000",16); # This holds the material name
|
||||
MATAMBIENT = long("0xA010",16); # Ambient color of the object/material
|
||||
MATDIFFUSE = long("0xA020",16); # This holds the color of the object/material
|
||||
MATSPECULAR = long("0xA030",16); # SPecular color of the object/material
|
||||
MATSHINESS = long("0xA040",16); # ??
|
||||
MATMAP = long("0xA200",16); # This is a header for a new material
|
||||
MATMAPFILE = long("0xA300",16); # This holds the file name of the texture
|
||||
|
||||
#>------ sub defines of OBJECT
|
||||
OBJECT_MESH = long("0x4100",16); # This lets us know that we are reading a new object
|
||||
OBJECT_LIGHT = long("0x4600",16); # This lets un know we are reading a light object
|
||||
OBJECT_CAMERA= long("0x4700",16); # This lets un know we are reading a camera object
|
||||
|
||||
#>------ sub defines of CAMERA
|
||||
OBJECT_CAM_RANGES= long("0x4720",16); # The camera range values
|
||||
|
||||
#>------ sub defines of OBJECT_MESH
|
||||
OBJECT_VERTICES = long("0x4110",16); # The objects vertices
|
||||
OBJECT_FACES = long("0x4120",16); # The objects faces
|
||||
OBJECT_MATERIAL = long("0x4130",16); # This is found if the object has a material, either texture map or color
|
||||
OBJECT_UV = long("0x4140",16); # The UV texture coordinates
|
||||
OBJECT_TRANS_MATRIX = long("0x4160",16); # The Object Matrix
|
||||
|
||||
#the chunk class
|
||||
class chunk:
|
||||
ID=0
|
||||
length=0
|
||||
bytes_read=0
|
||||
|
||||
#we don't read in the bytes_read, we compute that
|
||||
binary_format="<HI"
|
||||
|
||||
def __init__(self):
|
||||
self.ID=0
|
||||
self.length=0
|
||||
self.bytes_read=0
|
||||
|
||||
def dump(self):
|
||||
print "ID: ", self.ID
|
||||
print "ID in hex: ", hex(self.ID)
|
||||
print "length: ", self.length
|
||||
print "bytes_read: ", self.bytes_read
|
||||
|
||||
|
||||
def read_chunk(file, chunk):
|
||||
temp_data=file.read(struct.calcsize(chunk.binary_format))
|
||||
data=struct.unpack(chunk.binary_format, temp_data)
|
||||
chunk.ID=data[0]
|
||||
chunk.length=data[1]
|
||||
#update the bytes read function
|
||||
chunk.bytes_read=6
|
||||
|
||||
#if debugging
|
||||
#chunk.dump()
|
||||
|
||||
def read_string(file):
|
||||
s=""
|
||||
texture.setImage(image)
|
||||
texture_list=material.getTextures()
|
||||
index=0
|
||||
#print "reading a string"
|
||||
#read in the characters till we get a null character
|
||||
temp_data=file.read(1)
|
||||
data=struct.unpack("c", temp_data)
|
||||
s=s+(data[0])
|
||||
#print "string: ",s
|
||||
while(ord(s[index])!=0):
|
||||
index+=1
|
||||
temp_data=file.read(1)
|
||||
data=struct.unpack("c", temp_data)
|
||||
s=s+(data[0])
|
||||
#print "string: ",s
|
||||
|
||||
#remove the null character from the string
|
||||
the_string=s[:-1]
|
||||
return str(the_string)
|
||||
for tex in texture_list:
|
||||
if tex==None:
|
||||
material.setTexture(index,texture,Texture.TexCo.OBJECT,map)
|
||||
return
|
||||
else:
|
||||
index+=1
|
||||
if index>10:
|
||||
print "/tError: Cannot add diffuse map. Too many textures"
|
||||
|
||||
######################################################
|
||||
# IMPORT
|
||||
# Process an object (tri-mesh, Camera, or Light)
|
||||
######################################################
|
||||
def process_next_object_chunk(file, previous_chunk):
|
||||
new_chunk=chunk()
|
||||
temp_chunk=chunk()
|
||||
|
||||
while (previous_chunk.bytes_read<previous_chunk.length):
|
||||
#read the next chunk
|
||||
read_chunk(file, new_chunk)
|
||||
|
||||
|
||||
def process_next_chunk(file, previous_chunk, new_object_list):
|
||||
contextObName = None
|
||||
#contextLamp = None
|
||||
contextMaterial = None
|
||||
contextMatrix = Blender.Mathutils.Matrix(); contextMatrix.identity()
|
||||
contextMesh = None
|
||||
|
||||
TEXDICT={}
|
||||
MATDICT={}
|
||||
|
||||
objectList = [] # Keep a list of imported objects.
|
||||
|
||||
def process_object_block(file, previous_chunk, object_list):
|
||||
# Localspace variable names, faster.
|
||||
STRUCT_SIZE_1CHAR = struct.calcsize("c")
|
||||
STRUCT_SIZE_2FLOAT = struct.calcsize("2f")
|
||||
STRUCT_SIZE_3FLOAT = struct.calcsize("3f")
|
||||
STRUCT_SIZE_UNSIGNED_SHORT = struct.calcsize("H")
|
||||
STRUCT_SIZE_4UNSIGNED_SHORT = struct.calcsize("4H")
|
||||
STRUCT_SIZE_4x3MAT = struct.calcsize("ffffffffffff")
|
||||
|
||||
|
||||
def putContextMesh(myContextMesh):
|
||||
INV_MAT = Blender.Mathutils.CopyMat(contextMatrix)
|
||||
INV_MAT.invert()
|
||||
contextMesh.transform(INV_MAT)
|
||||
objectList.append(NMesh.PutRaw(contextMesh))
|
||||
objectList[-1].name = contextObName
|
||||
objectList[-1].setMatrix(contextMatrix)
|
||||
|
||||
|
||||
#a spare chunk
|
||||
#spare chunks
|
||||
new_chunk=chunk()
|
||||
temp_chunk=chunk()
|
||||
|
||||
#loop through all the data for this chunk (previous chunk) and see what it is
|
||||
global TEXURE_DICT
|
||||
global MATERIAL_DICT
|
||||
|
||||
#don't know which one we're making, so let's have a place for one of each
|
||||
new_mesh=None
|
||||
new_light=None
|
||||
new_camera=None
|
||||
|
||||
#all objects have a name (first thing)
|
||||
tempName = str(read_string(file))
|
||||
obj_name = getUniqueName( tempName )
|
||||
previous_chunk.bytes_read += (len(tempName)+1)
|
||||
|
||||
while (previous_chunk.bytes_read<previous_chunk.length):
|
||||
read_chunk(file, new_chunk)
|
||||
|
||||
if (new_chunk.ID==OBJECT_MESH):
|
||||
new_mesh=Blender.NMesh.New(obj_name)
|
||||
while (new_chunk.bytes_read<new_chunk.length):
|
||||
read_chunk(file, temp_chunk)
|
||||
|
||||
if (temp_chunk.ID==MESH_VERTICES):
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
data=struct.unpack("H", temp_data)
|
||||
temp_chunk.bytes_read+=2
|
||||
num_verts=data[0]
|
||||
for counter in range (num_verts):
|
||||
temp_data=file.read(STRUCT_SIZE_3FLOAT)
|
||||
temp_chunk.bytes_read += STRUCT_SIZE_3FLOAT
|
||||
data=struct.unpack("3f", temp_data)
|
||||
v=NMesh.Vert(data[0],data[1],data[2])
|
||||
new_mesh.verts.append(v)
|
||||
|
||||
elif (temp_chunk.ID==MESH_FACES):
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
data=struct.unpack("H", temp_data)
|
||||
temp_chunk.bytes_read+=2
|
||||
num_faces=data[0]
|
||||
for counter in range(num_faces):
|
||||
temp_data=file.read(STRUCT_SIZE_4UNSIGNED_SHORT)
|
||||
temp_chunk.bytes_read += STRUCT_SIZE_4UNSIGNED_SHORT #4 short ints x 2 bytes each
|
||||
data=struct.unpack("4H", temp_data)
|
||||
#insert the mesh info into the faces, don't worry about data[3] it is a 3D studio thing
|
||||
f = NMesh.Face( [new_mesh.verts[data[i]] for i in xrange(3)] )
|
||||
f.uv = [ tuple(new_mesh.verts[data[i]].uvco[:2]) for i in xrange(3) ]
|
||||
new_mesh.faces.append(f)
|
||||
|
||||
elif (temp_chunk.ID==MESH_MATERIAL):
|
||||
material_name=""
|
||||
material_name=str(read_string(file))
|
||||
temp_chunk.bytes_read += len(material_name)+1 # remove 1 null character.
|
||||
material_found=0
|
||||
for mat in Material.Get():
|
||||
if(mat.name==material_name):
|
||||
if len(new_mesh.materials) >= 15:
|
||||
print "\tCant assign more than 16 materials per mesh, keep going..."
|
||||
break
|
||||
else:
|
||||
meshHasMat = 0
|
||||
for myMat in new_mesh.materials:
|
||||
if myMat.name == mat.name:
|
||||
meshHasMat = 1
|
||||
if meshHasMat == 0:
|
||||
new_mesh.addMaterial(mat)
|
||||
material_found=1
|
||||
#figure out what material index this is for the mesh
|
||||
for mat_counter in range(len(new_mesh.materials)):
|
||||
if new_mesh.materials[mat_counter].name == material_name:
|
||||
mat_index=mat_counter
|
||||
break # get out of this for loop so we don't accidentally set material_found back to 0
|
||||
else:
|
||||
material_found=0
|
||||
|
||||
if material_found == 1:
|
||||
#read the number of faces using this material
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
data=struct.unpack("H", temp_data)
|
||||
temp_chunk.bytes_read += STRUCT_SIZE_UNSIGNED_SHORT
|
||||
num_faces_using_mat=data[0]
|
||||
#list of faces using mat
|
||||
for face_counter in range(num_faces_using_mat):
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
temp_chunk.bytes_read += STRUCT_SIZE_UNSIGNED_SHORT
|
||||
data=struct.unpack("H", temp_data)
|
||||
new_mesh.faces[data[0]].materialIndex = mat_index
|
||||
try:
|
||||
mname = MATERIAL_DICT[mat.name]
|
||||
new_mesh.faces[data[0]].image = TEXTURE_DICT[mname]
|
||||
except:
|
||||
continue
|
||||
else:
|
||||
#read past the information about the material you couldn't find
|
||||
skip_to_end(file,temp_chunk)
|
||||
|
||||
elif (new_chunk.ID == MESH_UV):
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
data=struct.unpack("H", temp_data)
|
||||
temp_chunk.bytes_read+=2
|
||||
num_uv=data[0]
|
||||
|
||||
for counter in range(num_uv):
|
||||
temp_data=file.read(STRUCT_SIZE_2FLOAT)
|
||||
temp_chunk.bytes_read += STRUCT_SIZE_2FLOAT #2 float x 4 bytes each
|
||||
data=struct.unpack("2f", temp_data)
|
||||
#insert the insert the UV coords in the vertex data
|
||||
new_mesh.verts[counter].uvco = data
|
||||
|
||||
elif (new_chunk.ID == MESH_TRANS_MATRIX):
|
||||
temp_data=file.read(STRUCT_SIZE_4x3MAT)
|
||||
data = list( struct.unpack("ffffffffffff", temp_data) )
|
||||
temp_chunk.bytes_read += STRUCT_SIZE_4x3MAT
|
||||
new_matrix = Blender.Mathutils.Matrix(\
|
||||
data[:3] + [0],\
|
||||
data[3:6] + [0],\
|
||||
data[6:9] + [0],\
|
||||
data[9:] + [1])
|
||||
new_mesh.setMatrix(new_matrix)
|
||||
else:
|
||||
skip_to_end(file, temp_chunk)
|
||||
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
elif (new_chunk.ID==OBJECT_LIGHT):
|
||||
skip_to_end(file,new_chunk)
|
||||
|
||||
elif (new_chunk.ID==OBJECT_CAMERA):
|
||||
skip_to_end(file,new_chunk)
|
||||
|
||||
else: #don't know what kind of object it is
|
||||
skip_to_end(file,new_chunk)
|
||||
|
||||
if new_mesh!=None:
|
||||
object_list.append(NMesh.PutRaw(new_mesh))
|
||||
if new_light!=None:
|
||||
object_list.append(new_light)
|
||||
if new_camera!=None:
|
||||
object_list.append(new_camera)
|
||||
|
||||
previous_chunk.bytes_read+=new_chunk.bytes_read
|
||||
|
||||
######################################################
|
||||
# Process a Material
|
||||
######################################################
|
||||
def process_material_block(file, previous_chunk):
|
||||
# Localspace variable names, faster.
|
||||
STRUCT_SIZE_3BYTE = struct.calcsize("3B")
|
||||
STRUCT_SIZE_UNSIGNED_SHORT = struct.calcsize("H")
|
||||
|
||||
#spare chunks
|
||||
new_chunk=chunk()
|
||||
temp_chunk=chunk()
|
||||
|
||||
global TEXURE_DICT
|
||||
global MATERIAL_DICT
|
||||
|
||||
new_material=Blender.Material.New()
|
||||
|
||||
while (previous_chunk.bytes_read<previous_chunk.length):
|
||||
#read the next chunk
|
||||
read_chunk(file, new_chunk)
|
||||
|
||||
if (new_chunk.ID==MAT_NAME):
|
||||
material_name=""
|
||||
material_name=str(read_string(file))
|
||||
new_chunk.bytes_read+=(len(material_name)+1) #plus one for the null character that ended the string
|
||||
new_material.setName(material_name)
|
||||
MATERIAL_DICT[material_name] = new_material.name
|
||||
|
||||
elif (new_chunk.ID==MAT_AMBIENT):
|
||||
read_chunk(file, temp_chunk)
|
||||
temp_data=file.read(STRUCT_SIZE_3BYTE)
|
||||
data=struct.unpack("3B", temp_data)
|
||||
temp_chunk.bytes_read+=3
|
||||
new_material.mirCol = [float(col)/255 for col in data] # data [0,1,2] == rgb
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
elif (new_chunk.ID==MAT_DIFFUSE):
|
||||
read_chunk(file, temp_chunk)
|
||||
temp_data=file.read(STRUCT_SIZE_3BYTE)
|
||||
data=struct.unpack("3B", temp_data)
|
||||
temp_chunk.bytes_read+=3
|
||||
new_material.rgbCol = [float(col)/255 for col in data] # data [0,1,2] == rgb
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
elif (new_chunk.ID==MAT_SPECULAR):
|
||||
read_chunk(file, temp_chunk)
|
||||
temp_data=file.read(STRUCT_SIZE_3BYTE)
|
||||
data=struct.unpack("3B", temp_data)
|
||||
temp_chunk.bytes_read+=3
|
||||
new_material.specCol = [float(col)/255 for col in data] # data [0,1,2] == rgb
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
elif (new_chunk.ID==MAT_TEXTURE_MAP):
|
||||
new_texture=Blender.Texture.New('Diffuse')
|
||||
new_texture.setType('Image')
|
||||
while (new_chunk.bytes_read<new_chunk.length):
|
||||
read_chunk(file, temp_chunk)
|
||||
|
||||
if (temp_chunk.ID==MAT_MAP_FILENAME):
|
||||
texture_name=""
|
||||
texture_name=str(read_string(file))
|
||||
try:
|
||||
img = Image.Load(texture_name)
|
||||
TEXTURE_DICT[new_material.name]=img
|
||||
except IOError:
|
||||
fname = os.path.join( os.path.dirname(FILENAME), texture_name)
|
||||
try:
|
||||
img = Image.Load(fname)
|
||||
TEXTURE_DICT[new_material.name]=img
|
||||
except IOError:
|
||||
print "\tERROR: failed to load image ",texture_name
|
||||
TEXTURE_DICT[new_material.name] = None # Dummy
|
||||
img=Blender.Image.New(fname,1,1,24) #blank image
|
||||
new_chunk.bytes_read += (len(texture_name)+1) #plus one for the null character that gets removed
|
||||
|
||||
else:
|
||||
skip_to_end(file, temp_chunk)
|
||||
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
#add the map to the material in the right channel
|
||||
add_texture_to_material(img, new_texture, new_material, "DIFFUSE")
|
||||
|
||||
elif (new_chunk.ID==MAT_SPECULAR_MAP):
|
||||
new_texture=Blender.Texture.New('Specular')
|
||||
new_texture.setType('Image')
|
||||
while (new_chunk.bytes_read<new_chunk.length):
|
||||
read_chunk(file, temp_chunk)
|
||||
|
||||
if (temp_chunk.ID==MAT_MAP_FILENAME):
|
||||
texture_name=""
|
||||
texture_name=str(read_string(file))
|
||||
try:
|
||||
img = Image.Load(texture_name)
|
||||
TEXTURE_DICT[new_material.name]=img
|
||||
except IOError:
|
||||
fname = os.path.join( os.path.dirname(FILENAME), texture_name)
|
||||
try:
|
||||
img = Image.Load(fname)
|
||||
TEXTURE_DICT[new_material.name]=img
|
||||
except IOError:
|
||||
print "\tERROR: failed to load image ",texture_name
|
||||
TEXTURE_DICT[new_material.name] = None # Dummy
|
||||
img=Blender.Image.New(fname,1,1,24) #blank image
|
||||
new_chunk.bytes_read += (len(texture_name)+1) #plus one for the null character that gets removed
|
||||
else:
|
||||
skip_to_end(file, temp_chunk)
|
||||
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
#add the map to the material in the right channel
|
||||
add_texture_to_material(img, new_texture, new_material, "SPECULAR")
|
||||
|
||||
elif (new_chunk.ID==MAT_OPACITY_MAP):
|
||||
new_texture=Blender.Texture.New('Opacity')
|
||||
new_texture.setType('Image')
|
||||
while (new_chunk.bytes_read<new_chunk.length):
|
||||
read_chunk(file, temp_chunk)
|
||||
|
||||
if (temp_chunk.ID==MAT_MAP_FILENAME):
|
||||
texture_name=""
|
||||
texture_name=str(read_string(file))
|
||||
try:
|
||||
img = Image.Load(texture_name)
|
||||
TEXTURE_DICT[new_material.name]=img
|
||||
except IOError:
|
||||
fname = os.path.join( os.path.dirname(FILENAME), texture_name)
|
||||
try:
|
||||
img = Image.Load(fname)
|
||||
TEXTURE_DICT[new_material.name]=img
|
||||
except IOError:
|
||||
print "\tERROR: failed to load image ",texture_name
|
||||
TEXTURE_DICT[new_material.name] = None # Dummy
|
||||
img=Blender.Image.New(fname,1,1,24) #blank image
|
||||
new_chunk.bytes_read += (len(texture_name)+1) #plus one for the null character that gets removed
|
||||
else:
|
||||
skip_to_end(file, temp_chunk)
|
||||
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
#add the map to the material in the right channel
|
||||
add_texture_to_material(img, new_texture, new_material, "OPACITY")
|
||||
|
||||
elif (new_chunk.ID==MAT_BUMP_MAP):
|
||||
new_texture=Blender.Texture.New('Bump')
|
||||
new_texture.setType('Image')
|
||||
while (new_chunk.bytes_read<new_chunk.length):
|
||||
read_chunk(file, temp_chunk)
|
||||
|
||||
if (temp_chunk.ID==MAT_MAP_FILENAME):
|
||||
texture_name=""
|
||||
texture_name=str(read_string(file))
|
||||
try:
|
||||
img = Image.Load(texture_name)
|
||||
TEXTURE_DICT[new_material.name]=img
|
||||
except IOError:
|
||||
fname = os.path.join( os.path.dirname(FILENAME), texture_name)
|
||||
try:
|
||||
img = Image.Load(fname)
|
||||
TEXTURE_DICT[new_material.name]=img
|
||||
except IOError:
|
||||
print "\tERROR: failed to load image ",texture_name
|
||||
TEXTURE_DICT[new_material.name] = None # Dummy
|
||||
img=Blender.Image.New(fname,1,1,24) #blank image
|
||||
new_chunk.bytes_read += (len(texture_name)+1) #plus one for the null character that gets removed
|
||||
else:
|
||||
skip_to_end(file, temp_chunk)
|
||||
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
#add the map to the material in the right channel
|
||||
add_texture_to_material(img, new_texture, new_material, "BUMP")
|
||||
|
||||
elif (new_chunk.ID==MAT_TRANSPARENCY):
|
||||
read_chunk(file, temp_chunk)
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
data=struct.unpack("H", temp_data)
|
||||
temp_chunk.bytes_read+=2
|
||||
new_material.setAlpha(1-(float(data[0])/100))
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
else:
|
||||
skip_to_end(file,new_chunk)
|
||||
|
||||
previous_chunk.bytes_read+=new_chunk.bytes_read
|
||||
|
||||
######################################################
|
||||
# process a main chunk
|
||||
######################################################
|
||||
def process_main_chunk(file,previous_chunk,new_object_list):
|
||||
|
||||
#spare chunks
|
||||
new_chunk=chunk()
|
||||
temp_chunk=chunk()
|
||||
|
||||
#Go through the main chunk
|
||||
while (previous_chunk.bytes_read<previous_chunk.length):
|
||||
#read the next chunk
|
||||
#print "reading a chunk"
|
||||
read_chunk(file, new_chunk)
|
||||
|
||||
#is it a Version chunk?
|
||||
if (new_chunk.ID==VERSION):
|
||||
#print "found a VERSION chunk"
|
||||
#read in the version of the file
|
||||
#it's an unsigned short (H)
|
||||
temp_data=file.read(struct.calcsize("I"))
|
||||
data=struct.unpack("I", temp_data)
|
||||
version=data[0]
|
||||
new_chunk.bytes_read+=4 #read the 4 bytes for the version number
|
||||
#this loader works with version 3 and below, but may not with 4 and above
|
||||
if (version>3):
|
||||
if (version>3): #this loader works with version 3 and below, but may not with 4 and above
|
||||
print "\tNon-Fatal Error: Version greater than 3, may not load correctly: ", version
|
||||
|
||||
#is it an object info chunk?
|
||||
elif (new_chunk.ID==OBJECTINFO):
|
||||
# print "found an OBJECTINFO chunk"
|
||||
process_next_chunk(file, new_chunk, new_object_list)
|
||||
|
||||
#keep track of how much we read in the main chunk
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
#is it an object chunk?
|
||||
elif (new_chunk.ID==OBJECT):
|
||||
# print "found an OBJECT chunk"
|
||||
tempName = str(read_string(file))
|
||||
contextObName = getUniqueName( tempName )
|
||||
new_chunk.bytes_read += (len(tempName)+1)
|
||||
|
||||
#is it a material chunk?
|
||||
elif (new_chunk.ID==MATERIAL):
|
||||
# print "found a MATERIAL chunk"
|
||||
contextMaterial = Material.New()
|
||||
|
||||
elif (new_chunk.ID==MATNAME):
|
||||
# print "Found a MATNAME chunk"
|
||||
material_name=""
|
||||
material_name=str(read_string(file))
|
||||
|
||||
#plus one for the null character that ended the string
|
||||
new_chunk.bytes_read+=(len(material_name)+1)
|
||||
|
||||
contextMaterial.setName(material_name)
|
||||
MATDICT[material_name] = contextMaterial.name
|
||||
|
||||
elif (new_chunk.ID==MATAMBIENT):
|
||||
# print "Found a MATAMBIENT chunk"
|
||||
|
||||
read_chunk(file, temp_chunk)
|
||||
temp_data=file.read(struct.calcsize("3B"))
|
||||
data=struct.unpack("3B", temp_data)
|
||||
temp_chunk.bytes_read+=3
|
||||
contextMaterial.mirCol = [float(col)/255 for col in data] # data [0,1,2] == rgb
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
elif (new_chunk.ID==MATDIFFUSE):
|
||||
# print "Found a MATDIFFUSE chunk"
|
||||
|
||||
read_chunk(file, temp_chunk)
|
||||
temp_data=file.read(struct.calcsize("3B"))
|
||||
data=struct.unpack("3B", temp_data)
|
||||
temp_chunk.bytes_read+=3
|
||||
contextMaterial.rgbCol = [float(col)/255 for col in data] # data [0,1,2] == rgb
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
elif (new_chunk.ID==MATSPECULAR):
|
||||
# print "Found a MATSPECULAR chunk"
|
||||
|
||||
read_chunk(file, temp_chunk)
|
||||
temp_data=file.read(struct.calcsize("3B"))
|
||||
data=struct.unpack("3B", temp_data)
|
||||
temp_chunk.bytes_read+=3
|
||||
|
||||
contextMaterial.specCol = [float(col)/255 for col in data] # data [0,1,2] == rgb
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
|
||||
elif (new_chunk.ID==MATMAP):
|
||||
# print "Found a MATMAP chunk"
|
||||
pass # This chunk has no data
|
||||
|
||||
elif (new_chunk.ID==MATMAPFILE):
|
||||
# print "Found a MATMAPFILE chunk"
|
||||
texture_name=""
|
||||
texture_name=str(read_string(file))
|
||||
try:
|
||||
img = Image.Load(texture_name)
|
||||
TEXDICT[contextMaterial.name]=img
|
||||
except IOError:
|
||||
fname = os.path.join( os.path.dirname(FILENAME), texture_name)
|
||||
try:
|
||||
img = Image.Load(fname)
|
||||
TEXDICT[contextMaterial.name]=img
|
||||
except IOError:
|
||||
print "\tERROR: failed to load image ",texture_name
|
||||
TEXDICT[contextMaterial.name] = None # Dummy
|
||||
|
||||
#plus one for the null character that gets removed
|
||||
new_chunk.bytes_read += (len(texture_name)+1)
|
||||
|
||||
|
||||
elif (new_chunk.ID==OBJECT_MESH):
|
||||
# print "Found an OBJECT_MESH chunk"
|
||||
if contextMesh != None: # Write context mesh if we have one.
|
||||
putContextMesh(contextMesh)
|
||||
|
||||
contextMesh = NMesh.New()
|
||||
|
||||
# Reset matrix
|
||||
contextMatrix = Blender.Mathutils.Matrix(); contextMatrix.identity()
|
||||
|
||||
elif (new_chunk.ID==OBJECT_VERTICES):
|
||||
# print "Found an OBJECT_VERTICES chunk"
|
||||
#print "object_verts: length: ", new_chunk.length
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
data=struct.unpack("H", temp_data)
|
||||
new_chunk.bytes_read+=2
|
||||
num_verts=data[0]
|
||||
# print "number of verts: ", num_verts
|
||||
for counter in range (num_verts):
|
||||
temp_data=file.read(STRUCT_SIZE_3FLOAT)
|
||||
new_chunk.bytes_read += STRUCT_SIZE_3FLOAT #12: 3 floats x 4 bytes each
|
||||
data=struct.unpack("3f", temp_data)
|
||||
v=NMesh.Vert(data[0],data[1],data[2])
|
||||
contextMesh.verts.append(v)
|
||||
#print "object verts: bytes read: ", new_chunk.bytes_read
|
||||
|
||||
elif (new_chunk.ID==OBJECT_FACES):
|
||||
# print "Found an OBJECT_FACES chunk"
|
||||
#print "object faces: length: ", new_chunk.length
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
data=struct.unpack("H", temp_data)
|
||||
new_chunk.bytes_read+=2
|
||||
num_faces=data[0]
|
||||
#print "number of faces: ", num_faces
|
||||
|
||||
for counter in range(num_faces):
|
||||
temp_data=file.read(STRUCT_SIZE_4UNSIGNED_SHORT)
|
||||
new_chunk.bytes_read += STRUCT_SIZE_4UNSIGNED_SHORT #4 short ints x 2 bytes each
|
||||
data=struct.unpack("4H", temp_data)
|
||||
|
||||
#insert the mesh info into the faces, don't worry about data[3] it is a 3D studio thing
|
||||
f = NMesh.Face( [contextMesh.verts[data[i]] for i in xrange(3) ] )
|
||||
f.uv = [ tuple(contextMesh.verts[data[i]].uvco[:2]) for i in xrange(3) ]
|
||||
contextMesh.faces.append(f)
|
||||
#print "object faces: bytes read: ", new_chunk.bytes_read
|
||||
|
||||
elif (new_chunk.ID==OBJECT_MATERIAL):
|
||||
# print "Found an OBJECT_MATERIAL chunk"
|
||||
material_name=""
|
||||
material_name=str(read_string(file))
|
||||
new_chunk.bytes_read += len(material_name)+1 # remove 1 null character.
|
||||
|
||||
#look up the material in all the materials
|
||||
material_found=0
|
||||
for mat in Material.Get():
|
||||
|
||||
#found it, add it to the mesh
|
||||
if(mat.name==material_name):
|
||||
if len(contextMesh.materials) >= 15:
|
||||
print "\tCant assign more than 16 materials per mesh, keep going..."
|
||||
break
|
||||
else:
|
||||
meshHasMat = 0
|
||||
for myMat in contextMesh.materials:
|
||||
if myMat.name == mat.name:
|
||||
meshHasMat = 1
|
||||
|
||||
if meshHasMat == 0:
|
||||
contextMesh.addMaterial(mat)
|
||||
material_found=1
|
||||
|
||||
#figure out what material index this is for the mesh
|
||||
for mat_counter in range(len(contextMesh.materials)):
|
||||
if contextMesh.materials[mat_counter].name == material_name:
|
||||
mat_index=mat_counter
|
||||
#print "material index: ",mat_index
|
||||
|
||||
|
||||
break # get out of this for loop so we don't accidentally set material_found back to 0
|
||||
elif (new_chunk.ID==EDITOR_BLOCK):
|
||||
while(new_chunk.bytes_read<new_chunk.length):
|
||||
read_chunk(file, temp_chunk)
|
||||
if (temp_chunk.ID==MATERIAL_BLOCK):
|
||||
process_material_block(file, temp_chunk)
|
||||
elif (temp_chunk.ID==OBJECT_BLOCK):
|
||||
process_object_block(file, temp_chunk,new_object_list)
|
||||
else:
|
||||
material_found=0
|
||||
# print "Not matching: ", mat.name, " and ", material_name
|
||||
skip_to_end(file,temp_chunk)
|
||||
|
||||
if material_found == 1:
|
||||
contextMaterial = mat
|
||||
#read the number of faces using this material
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
data=struct.unpack("H", temp_data)
|
||||
new_chunk.bytes_read += STRUCT_SIZE_UNSIGNED_SHORT
|
||||
num_faces_using_mat=data[0]
|
||||
new_chunk.bytes_read+=temp_chunk.bytes_read
|
||||
else:
|
||||
skip_to_end(file,new_chunk)
|
||||
|
||||
#list of faces using mat
|
||||
for face_counter in range(num_faces_using_mat):
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
new_chunk.bytes_read += STRUCT_SIZE_UNSIGNED_SHORT
|
||||
data=struct.unpack("H", temp_data)
|
||||
contextMesh.faces[data[0]].materialIndex = mat_index
|
||||
|
||||
try:
|
||||
mname = MATDICT[contextMaterial.name]
|
||||
contextMesh.faces[data[0]].image = TEXDICT[mname]
|
||||
except:
|
||||
continue
|
||||
else:
|
||||
#read past the information about the material you couldn't find
|
||||
#print "Couldn't find material. Reading past face material info"
|
||||
buffer_size=new_chunk.length-new_chunk.bytes_read
|
||||
binary_format=str(buffer_size)+"c"
|
||||
temp_data=file.read(struct.calcsize(binary_format))
|
||||
new_chunk.bytes_read+=buffer_size
|
||||
|
||||
#print "object mat: bytes read: ", new_chunk.bytes_read
|
||||
|
||||
elif (new_chunk.ID == OBJECT_UV):
|
||||
# print "Found an OBJECT_UV chunk"
|
||||
temp_data=file.read(STRUCT_SIZE_UNSIGNED_SHORT)
|
||||
data=struct.unpack("H", temp_data)
|
||||
new_chunk.bytes_read+=2
|
||||
num_uv=data[0]
|
||||
|
||||
for counter in range(num_uv):
|
||||
temp_data=file.read(STRUCT_SIZE_2FLOAT)
|
||||
new_chunk.bytes_read += STRUCT_SIZE_2FLOAT #2 float x 4 bytes each
|
||||
data=struct.unpack("2f", temp_data)
|
||||
|
||||
#insert the insert the UV coords in the vertex data
|
||||
contextMesh.verts[counter].uvco = data
|
||||
|
||||
elif (new_chunk.ID == OBJECT_TRANS_MATRIX):
|
||||
# print "Found an OBJECT_TRANS_MATRIX chunk"
|
||||
|
||||
temp_data=file.read(STRUCT_SIZE_4x3MAT)
|
||||
data = list( struct.unpack("ffffffffffff", temp_data) )
|
||||
new_chunk.bytes_read += STRUCT_SIZE_4x3MAT
|
||||
|
||||
contextMatrix = Blender.Mathutils.Matrix(\
|
||||
data[:3] + [0],\
|
||||
data[3:6] + [0],\
|
||||
data[6:9] + [0],\
|
||||
data[9:] + [1])
|
||||
|
||||
|
||||
|
||||
else: #(new_chunk.ID!=VERSION or new_chunk.ID!=OBJECTINFO or new_chunk.ID!=OBJECT or new_chunk.ID!=MATERIAL):
|
||||
# print "skipping to end of this chunk"
|
||||
buffer_size=new_chunk.length-new_chunk.bytes_read
|
||||
binary_format=str(buffer_size)+"c"
|
||||
temp_data=file.read(struct.calcsize(binary_format))
|
||||
new_chunk.bytes_read+=buffer_size
|
||||
|
||||
|
||||
#update the previous chunk bytes read
|
||||
previous_chunk.bytes_read += new_chunk.bytes_read
|
||||
#print "Bytes left in this chunk: ", previous_chunk.length-previous_chunk.bytes_read
|
||||
|
||||
# FINISHED LOOP
|
||||
# There will be a number of objects still not added
|
||||
if contextMesh != None:
|
||||
putContextMesh(contextMesh)
|
||||
|
||||
for ob in objectList:
|
||||
ob.sel = 1
|
||||
previous_chunk.bytes_read+=new_chunk.bytes_read
|
||||
|
||||
#***********************************************
|
||||
# main entry point for loading 3ds files
|
||||
#***********************************************
|
||||
def load_3ds (filename):
|
||||
current_chunk=chunk()
|
||||
print "--------------------------------"
|
||||
print 'Importing "%s"' % filename
|
||||
|
||||
time1 = Blender.sys.time()
|
||||
time1 = Blender.sys.time() #for timing purposes
|
||||
file=open(filename,"rb")
|
||||
new_object_list = []
|
||||
|
||||
global FILENAME
|
||||
FILENAME=filename
|
||||
current_chunk=chunk()
|
||||
|
||||
file=open(filename,"rb")
|
||||
|
||||
#here we go!
|
||||
# print "reading the first chunk"
|
||||
new_object_list = []
|
||||
read_chunk(file, current_chunk)
|
||||
|
||||
if (current_chunk.ID!=PRIMARY):
|
||||
print "\tFatal Error: Not a valid 3ds file: ", filename
|
||||
file.close()
|
||||
return
|
||||
|
||||
process_next_chunk(file, current_chunk, new_object_list)
|
||||
process_main_chunk(file, current_chunk, new_object_list)
|
||||
|
||||
# Select all new objects.
|
||||
for ob in new_object_list: ob.sel = 1
|
||||
|
||||
@@ -5,12 +5,28 @@
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | September 28, 2002 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Common Functions & Global Variables For All IO Modules |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender
|
||||
import sys
|
||||
|
||||
@@ -35,7 +51,16 @@ def append_faces(mesh, faces, facesuv, uvcoords):
|
||||
for i in range(len(faces)):
|
||||
if not i%100 and show_progress: Blender.Window.DrawProgressBar(float(i)/len(faces), "Generating Faces")
|
||||
numfaceverts=len(faces[i])
|
||||
if numfaceverts <= 4: # This face is a triangle or quad
|
||||
if numfaceverts == 2: #This is not a face is an edge
|
||||
if mesh.edges == None: #first run
|
||||
mesh.addEdgeData()
|
||||
#rev_face = revert(cur_face)
|
||||
i1 = faces[i][0]
|
||||
i2 = faces[i][1]
|
||||
ee = mesh.addEdge(mesh.verts[i1],mesh.verts[i2])
|
||||
ee.flag |= Blender.NMesh.EdgeFlags.EDGEDRAW
|
||||
ee.flag |= Blender.NMesh.EdgeFlags.EDGERENDER
|
||||
elif numfaceverts in [3,4]: # This face is a triangle or quad
|
||||
face = Blender.NMesh.Face()
|
||||
for j in range(numfaceverts):
|
||||
index = faces[i][j]
|
||||
|
||||
@@ -5,9 +5,11 @@ Blender: 239
|
||||
Group: 'Animation'
|
||||
Tooltip: 'Create Armature from a parented-empties chain'
|
||||
"""
|
||||
__author__ = " Jean-Baptiste PERIN (jb_perin(at)yahoo.fr)"
|
||||
__author__ = "Jean-Baptiste PERIN (jb_perin(at)yahoo.fr)"
|
||||
__url__ = ("blender", "elysiun",
|
||||
"BVH 2 ARMATURE, http://perso.wanadoo.fr/jb.perin/",
|
||||
"Author's homepage, http://perso.wanadoo.fr/jb.perin/",
|
||||
"Documentation, http://perso.wanadoo.fr/jb.perin/BVH2ARM/doc/bvh2arm.html",
|
||||
"Mocap tutorial, http://perso.wanadoo.fr/jb.perin/Mocap/MocapAnimation.html",
|
||||
"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
|
||||
|
||||
__version__ = "2.4"
|
||||
|
||||
@@ -46,12 +46,27 @@ v5.5 format.
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | April 21, 2002 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write LightWave Object File Format (*.lwo) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
import struct, chunk, os, cStringIO, time, operator
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -53,12 +53,27 @@ field.
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | September 25, 2001 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write Nendo File Format (*.nendo) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
import struct, time, sys, os
|
||||
|
||||
|
||||
@@ -48,12 +48,27 @@ edges during the course of modeling.
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | September 25, 2001 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write Nendo File Format (*.nendo) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
import struct, time, sys, os
|
||||
|
||||
|
||||
@@ -28,17 +28,34 @@ Notes:<br>
|
||||
Only exports a single selected mesh.
|
||||
"""
|
||||
|
||||
# $Id:
|
||||
#
|
||||
# +---------------------------------------------------------+
|
||||
# | Copyright (c) 2002 Anthony D'Agostino |
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | February 3, 2001 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write Object File Format (*.off) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
#import time
|
||||
|
||||
|
||||
@@ -29,18 +29,34 @@ Notes:<br>
|
||||
UV Coordinate support has been added.
|
||||
"""
|
||||
|
||||
|
||||
# $Id:
|
||||
#
|
||||
# +---------------------------------------------------------+
|
||||
# | Copyright (c) 2002 Anthony D'Agostino |
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | February 3, 2001 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write Object File Format (*.off) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
#import time
|
||||
|
||||
|
||||
@@ -46,12 +46,27 @@ specular highlights to the vertex colors.
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | April 11, 2002 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write Radiosity File Format (*.radio) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
#import time
|
||||
|
||||
|
||||
@@ -31,12 +31,27 @@ file to open.
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | April 11, 2002 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write Radiosity File Format (*.radio) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
#import time
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ Usage:<br>
|
||||
Select meshes to be exported and run this script from "File->Export" menu.
|
||||
"""
|
||||
|
||||
|
||||
# $Id$
|
||||
#
|
||||
# +---------------------------------------------------------+
|
||||
@@ -33,12 +32,27 @@ Usage:<br>
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | April 28, 2002 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write RAW Triangle File Format (*.raw) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
import sys
|
||||
#import time
|
||||
|
||||
@@ -38,12 +38,27 @@ tolerance.
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | April 28, 2002 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write RAW Triangle File Format (*.raw) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
#import time
|
||||
|
||||
|
||||
@@ -39,15 +39,34 @@ some information on it before sharing it with others.
|
||||
# $Id$
|
||||
#
|
||||
# --------------------------------------------------------------------------
|
||||
# Copyright (C) 2004: Willian P. Germano, wgermano _at_ ig.com.br
|
||||
# Copyright (C) 2004: Willian P. Germano, wgermano _at_ ig com br
|
||||
# --------------------------------------------------------------------------
|
||||
# Released under the Blender Artistic License (BAL):
|
||||
# http://download.blender.org/documentation/html/x21254.html
|
||||
#
|
||||
# The scripts generated by this script are put under Public Domain by
|
||||
# default, but you are free to edit the ones you generate with this script
|
||||
# and change their license to another one of your choice.
|
||||
# --------------------------------------------------------------------------
|
||||
#
|
||||
# --------------------------------------------------------------------------
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# Copyright (C) 2005: Willian P. Germano, wgermano _at_ ig.com.br
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
import Blender
|
||||
from Blender.Window import Theme, FileSelector
|
||||
|
||||
@@ -36,12 +36,27 @@ tolerance.
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | May 3, 2004 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write SLP Triangle File Format (*.slp) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
#import time
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ For Cameras: The matrix here gets a little confusing, and I'm not sure of
|
||||
how to handle it.
|
||||
"""
|
||||
|
||||
|
||||
# $Id$
|
||||
#
|
||||
# +---------------------------------------------------------+
|
||||
@@ -57,12 +56,27 @@ how to handle it.
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | June 12, 2001 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write Caligari trueSpace File Format (*.cob) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
import struct, os, cStringIO, time
|
||||
|
||||
|
||||
@@ -62,12 +62,27 @@ how to handle it.
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | June 12, 2001 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write Caligari trueSpace File Format (*.cob) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
import struct, chunk, os, cStringIO, time
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ specular highlights to the vertex colors.
|
||||
5. The Videoscape format also allows vertex colors to be specified.
|
||||
"""
|
||||
|
||||
|
||||
# $Id$
|
||||
#
|
||||
# +---------------------------------------------------------+
|
||||
@@ -51,12 +50,27 @@ specular highlights to the vertex colors.
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | June 5, 2001 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Write Videoscape File Format (*.obj NOT WAVEFRONT OBJ) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
#import time
|
||||
|
||||
|
||||
@@ -50,12 +50,27 @@ Notes:<br>
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | Feb 19, 2002 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write Wings3D File Format (*.wings) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import Blender, meshtools
|
||||
import struct, time, sys, os, zlib, cStringIO
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ __author__ = "Anthony D'Agostino (Scorpius)"
|
||||
__url__ = ("blender", "elysiun",
|
||||
"Author's homepage, http://www.redrival.com/scorpius",
|
||||
"Wings 3D, http://www.wings3d.com")
|
||||
__version__ = "Part of IOSuite 0.5"
|
||||
__version__ = "Update on version from IOSuite 0.5"
|
||||
|
||||
__bpydoc__ = """\
|
||||
This script imports Wings3D files to Blender.
|
||||
@@ -37,7 +37,8 @@ fanning algorithm. Convex polygons (i.e., shaped like the letter "U")
|
||||
require a different algorithm, and will be triagulated incorrectly.
|
||||
|
||||
Notes:<br>
|
||||
Last tested with Wings 3D 0.98.25 & Blender 2.35a.
|
||||
Last tested with Wings 3D 0.98.25 & Blender 2.35a.<br>
|
||||
This version has improvements made by Adam Saltsman (AdamAtomic) and Toastie.
|
||||
"""
|
||||
|
||||
# $Id$
|
||||
@@ -47,11 +48,25 @@ Notes:<br>
|
||||
# | http://www.redrival.com/scorpius |
|
||||
# | scorpius@netzero.com |
|
||||
# | Feb 19, 2002 |
|
||||
# | Released under the Blender Artistic Licence (BAL) |
|
||||
# | Import Export Suite v0.5 |
|
||||
# +---------------------------------------------------------+
|
||||
# | Read and write Wings3D File Format (*.wings) |
|
||||
# +---------------------------------------------------------+
|
||||
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
|
||||
import Blender, meshtools
|
||||
import struct, time, sys, os, zlib, cStringIO
|
||||
@@ -79,26 +94,28 @@ def read_mode(data):
|
||||
# === Read Hard Edges ===
|
||||
# =======================
|
||||
def read_hardedges(data):
|
||||
hardedge_table = {} # hard edges table
|
||||
tag = data.read(1)
|
||||
if tag == '\x6A':
|
||||
return # There are no hard edges
|
||||
return hardedge_table # There are no hard edges
|
||||
elif tag == '\x6B':
|
||||
numhardedges, = struct.unpack(">H", data.read(2))
|
||||
print "numhardedges:", numhardedges
|
||||
#print "numhardedges:", numhardedges
|
||||
for i in range(numhardedges):
|
||||
data.read(1)
|
||||
hardedge_table[i] = struct.unpack(">B", data.read(1))[0]
|
||||
elif tag == '\x6C':
|
||||
numhardedges, = struct.unpack(">L", data.read(4))
|
||||
print "numhardedges:", numhardedges
|
||||
#print "numhardedges:", numhardedges
|
||||
for i in range(numhardedges):
|
||||
misc = data.read(1)
|
||||
if misc == '\x61': # next value is stored as a byte
|
||||
data.read(1)
|
||||
hardedge_table[i] = struct.unpack(">B", data.read(1))[0]
|
||||
elif misc == '\x62': # next value is stored as a long
|
||||
data.read(4)
|
||||
hardedge_table[i] = struct.unpack(">L", data.read(4))[0]
|
||||
data.read(1) # 6A
|
||||
else:
|
||||
print tag
|
||||
return hardedge_table
|
||||
|
||||
# ==================
|
||||
# === Read Edges ===
|
||||
@@ -134,6 +151,7 @@ def read_edges(data):
|
||||
# === Read Faces ===
|
||||
# ==================
|
||||
def read_faces(data):
|
||||
mat_table = {} #list of faces and material names
|
||||
misc, numfaces = struct.unpack(">BL", data.read(5))
|
||||
for i in range(numfaces):
|
||||
if not i%100 and meshtools.show_progress: Blender.Window.DrawProgressBar(float(i)/numfaces, "Reading Faces")
|
||||
@@ -141,10 +159,10 @@ def read_faces(data):
|
||||
data.read(4)
|
||||
read_chunkheader(data)
|
||||
misc, namelen = struct.unpack(">BH", data.read(3))
|
||||
materialname = data.read(namelen)
|
||||
data.read(1)
|
||||
mat_table[i] = data.read(namelen)
|
||||
data.read(1) # 6A?
|
||||
data.read(1) # 6A
|
||||
return numfaces
|
||||
return mat_table
|
||||
|
||||
# ==================
|
||||
# === Read Verts ===
|
||||
@@ -169,8 +187,10 @@ def make_face_table(edge_table): # For Wings
|
||||
for i in range(len(edge_table)):
|
||||
Lf = edge_table[i][2]
|
||||
Rf = edge_table[i][3]
|
||||
face_table[Lf] = i
|
||||
face_table[Rf] = i
|
||||
if Lf >= 0:
|
||||
face_table[Lf] = i
|
||||
if Rf >= 0:
|
||||
face_table[Rf] = i
|
||||
return face_table
|
||||
|
||||
# =======================
|
||||
@@ -198,14 +218,17 @@ def make_faces(edge_table): # For Wings
|
||||
if i == edge_table[current_edge][3]:
|
||||
next_edge = edge_table[current_edge][7] # Right successor edge
|
||||
next_vert = edge_table[current_edge][0]
|
||||
else:
|
||||
elif i == edge_table[current_edge][2]:
|
||||
next_edge = edge_table[current_edge][5] # Left successor edge
|
||||
next_vert = edge_table[current_edge][1]
|
||||
else:
|
||||
break
|
||||
face_verts.append(next_vert)
|
||||
current_edge = next_edge
|
||||
if current_edge == face_table[i]: break
|
||||
face_verts.reverse()
|
||||
faces.append(face_verts)
|
||||
if len(face_verts) > 0:
|
||||
face_verts.reverse()
|
||||
faces.append(face_verts)
|
||||
return faces
|
||||
|
||||
# =======================
|
||||
@@ -236,9 +259,10 @@ def dump_wings(filename):
|
||||
objname = data.read(namelen)
|
||||
print read_chunkheader(data) # === winged chunk ===
|
||||
edge_table = read_edges(data)
|
||||
numfaces = read_faces(data)
|
||||
mat_table = read_faces(data)
|
||||
numfaces = len(mat_table)
|
||||
verts = read_verts(data)
|
||||
read_hardedges(data)
|
||||
hardedge_table = read_hardedges(data)
|
||||
|
||||
face_table = {} # contains an incident edge
|
||||
vert_table = {} # contains an incident edge
|
||||
@@ -255,25 +279,26 @@ def dump_wings(filename):
|
||||
print
|
||||
print "<EFBFBD>"*79
|
||||
print "edge_table:"
|
||||
pprint.pprint(edge_table)
|
||||
#pprint.pprint(edge_table)
|
||||
#for i in range(len(edge_table)): print "%2d" % (i), edge_table[i]
|
||||
print
|
||||
print "face_table:"
|
||||
pprint.pprint(face_table)
|
||||
#pprint.pprint(face_table)
|
||||
#for i in range(len(face_table)): print "%2d %2d" % (i, face_table[i])
|
||||
print
|
||||
print "vert_table:"
|
||||
pprint.pprint(vert_table)
|
||||
#pprint.pprint(vert_table)
|
||||
#for i in range(len(vert_table)): print "%2d %2d" % (i, vert_table[i])
|
||||
file.close()
|
||||
end = time.clock()
|
||||
print '\a\r',
|
||||
sys.stderr.write("\nDone in %.2f %s" % (end-start, "seconds"))
|
||||
sys.stderr.write("\nDone in %.2f %s\a\r" % (end-start, "seconds"))
|
||||
|
||||
# =========================
|
||||
# === Read Wings Format ===
|
||||
# =========================
|
||||
def read(filename):
|
||||
|
||||
start = time.clock()
|
||||
file = open(filename, "rb")
|
||||
header = file.read(15)
|
||||
@@ -299,9 +324,113 @@ def read(filename):
|
||||
objname = data.read(namelen)
|
||||
read_chunkheader(data) # winged chunk
|
||||
edge_table = read_edges(data)
|
||||
numfaces = read_faces(data)
|
||||
mat_table = read_faces(data)
|
||||
numfaces = len(mat_table)
|
||||
verts = read_verts(data)
|
||||
read_hardedges(data)
|
||||
hardedge_table = read_hardedges(data)
|
||||
|
||||
# Manually split hard edges
|
||||
# TODO: Handle the case where there are 2+ edges on a face
|
||||
duped = {}
|
||||
processed = []
|
||||
cleanup = []
|
||||
oldedgecount = len(edge_table)
|
||||
for i in range(len(verts)):
|
||||
duped[i] = -1
|
||||
for j in range(len(hardedge_table)):
|
||||
hardedge = hardedge_table[j]
|
||||
oldedge = edge_table[hardedge]
|
||||
newedge = [] # Copy old edge into a new list
|
||||
for k in range(len(oldedge)):
|
||||
newedge.append(oldedge[k])
|
||||
|
||||
# Duplicate start vert if not duped already
|
||||
sv = newedge[0]
|
||||
if duped[sv] == -1:
|
||||
verts.append(verts[sv])
|
||||
duped[sv] = len(verts)-1
|
||||
newedge[0] = duped[sv]
|
||||
|
||||
# Duplicate end vert if not duped already
|
||||
ev = newedge[1]
|
||||
if duped[ev] == -1:
|
||||
verts.append(verts[ev])
|
||||
duped[ev] = len(verts)-1
|
||||
newedge[1] = duped[ev]
|
||||
|
||||
# Decide which way to cut the edge
|
||||
flip = 0
|
||||
for v in range(len(processed)):
|
||||
if processed[v][0] == oldedge[0]:
|
||||
flip = 1
|
||||
elif processed[v][1] == oldedge[1]:
|
||||
flip = 1
|
||||
if flip == 0:
|
||||
of = 3
|
||||
oe1 = 6
|
||||
oe2 = 7
|
||||
nf = 2
|
||||
ne1 = 4
|
||||
ne2 = 5
|
||||
else:
|
||||
of = 2
|
||||
oe1 = 4
|
||||
oe2 = 5
|
||||
nf = 3
|
||||
ne1 = 6
|
||||
ne2 = 7
|
||||
|
||||
# Fix up side-specific edge fields
|
||||
oldedge[of] = -1
|
||||
oldedge[oe1] = -1
|
||||
oldedge[oe2] = -1
|
||||
newedge[nf] = -1
|
||||
newedge[ne1] = -1
|
||||
newedge[ne2] = -1
|
||||
|
||||
# Store new edge's neighbors for cleanup later
|
||||
cleanup.append(edge_table[newedge[oe1]])
|
||||
cleanup.append(edge_table[newedge[oe2]])
|
||||
|
||||
#DEBUG
|
||||
# Sv Ev | Lf Rf | Lp Ls | Rp Rs
|
||||
#print "Old Edge:",hardedge,oldedge
|
||||
#print "New Edge:",len(edge_table),newedge
|
||||
|
||||
# Add this new edge to the edge table
|
||||
edge_table[len(edge_table)] = newedge
|
||||
if flip == 0:
|
||||
processed.append(oldedge) # mark it off as processed
|
||||
|
||||
# Cycle through cleanup list and fix it up
|
||||
for c in range(len(cleanup)):
|
||||
cleanupedge = cleanup[c]
|
||||
|
||||
# Fix up their verts in case they were duped
|
||||
sv = cleanupedge[0]
|
||||
if sv < len(duped):
|
||||
if duped[sv] >= 0:
|
||||
cleanupedge[0] = duped[sv]
|
||||
ev = cleanupedge[1]
|
||||
if ev < len(duped):
|
||||
if duped[ev] >= 0:
|
||||
cleanupedge[1] = duped[ev]
|
||||
|
||||
# Fix up edge info (in case a hard edge was replaced with a new one)
|
||||
edgecount = c/2
|
||||
hardedge = hardedge_table[edgecount] # look up what edge we were replacing
|
||||
newedgenum = oldedgecount+edgecount # calculate new edge's index
|
||||
if cleanupedge[4] == hardedge:
|
||||
cleanupedge[4] = newedgenum
|
||||
if cleanupedge[5] == hardedge:
|
||||
cleanupedge[5] = newedgenum
|
||||
if cleanupedge[6] == hardedge:
|
||||
cleanupedge[6] = newedgenum
|
||||
if cleanupedge[7] == hardedge:
|
||||
cleanupedge[7] = newedgenum
|
||||
|
||||
#for i in range(len(edge_table)): print "%2d" % (i), edge_table[i]
|
||||
|
||||
read_mode(data)
|
||||
faces = make_faces(edge_table)
|
||||
message += "%s %8s %8s %8s\n" % (objname.ljust(15), len(faces), len(edge_table), len(verts))
|
||||
|
||||
Reference in New Issue
Block a user