forked from bartvdbraak/blender
Scripts: Campbell (ideasman) updated his obj wavefront scripts.
This commit is contained in:
parent
61bb158291
commit
a15b430d71
@ -1,7 +1,7 @@
|
|||||||
#!BPY
|
#!BPY
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Name: 'OBJ Wavefront'
|
Name: 'Wavefront (*.obj)'
|
||||||
Blender: 232
|
Blender: 232
|
||||||
Group: 'Export'
|
Group: 'Export'
|
||||||
Tooltip: 'Save a Wavefront OBJ File'
|
Tooltip: 'Save a Wavefront OBJ File'
|
||||||
@ -46,26 +46,8 @@ def getWorldMat(ob):
|
|||||||
# Apply Transform #
|
# Apply Transform #
|
||||||
#==================#
|
#==================#
|
||||||
def apply_transform(verts, matrix):
|
def apply_transform(verts, matrix):
|
||||||
|
verts.resize4D()
|
||||||
x, y, z = verts
|
return Mathutils.VecMultMat(verts, matrix)
|
||||||
xloc, yloc, zloc = matrix[3][0], matrix[3][1], matrix[3][2]
|
|
||||||
xcomponent = x*matrix[0][0] + y*matrix[1][0] + z*matrix[2][0] + xloc
|
|
||||||
ycomponent = x*matrix[0][1] + y*matrix[1][1] + z*matrix[2][1] + yloc
|
|
||||||
zcomponent = x*matrix[0][2] + y*matrix[1][2] + z*matrix[2][2] + zloc
|
|
||||||
|
|
||||||
return [xcomponent, ycomponent, zcomponent]
|
|
||||||
|
|
||||||
|
|
||||||
#=====================================#
|
|
||||||
# Apply Transform for vertex normals #
|
|
||||||
# ignore the translation #
|
|
||||||
#=====================================#
|
|
||||||
def apply_normal_transform(verts, matrix):
|
|
||||||
x, y, z = verts
|
|
||||||
xcomponent = x*matrix[0][0] + y*matrix[1][0] + z*matrix[2][0]
|
|
||||||
ycomponent = x*matrix[0][1] + y*matrix[1][1] + z*matrix[2][1]
|
|
||||||
zcomponent = x*matrix[0][2] + y*matrix[1][2] + z*matrix[2][2]
|
|
||||||
return Mathutils.Vector([xcomponent, ycomponent, zcomponent])
|
|
||||||
|
|
||||||
#====================================================#
|
#====================================================#
|
||||||
# Return a 6 deciaml point floating point value #
|
# Return a 6 deciaml point floating point value #
|
||||||
@ -129,7 +111,7 @@ def save_obj(filename):
|
|||||||
for f in m.faces:
|
for f in m.faces:
|
||||||
for v in f.v:
|
for v in f.v:
|
||||||
# Transform the normal
|
# Transform the normal
|
||||||
noTx = apply_normal_transform(v.no, matrix)
|
noTx = apply_transform(v.no, matrix)
|
||||||
noTx.normalize()
|
noTx.normalize()
|
||||||
file.write('vn ')
|
file.write('vn ')
|
||||||
file.write(saneFloat(noTx[0]))
|
file.write(saneFloat(noTx[0]))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!BPY
|
#!BPY
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Name: 'OBJ Wavefront'
|
Name: 'Wavefront (*.obj)'
|
||||||
Blender: 232
|
Blender: 232
|
||||||
Group: 'Import'
|
Group: 'Import'
|
||||||
Tooltip: 'Load a Wavefront OBJ File'
|
Tooltip: 'Load a Wavefront OBJ File'
|
||||||
@ -231,7 +231,7 @@ def load_obj(file):
|
|||||||
|
|
||||||
elif l[0] == 'usemtl':
|
elif l[0] == 'usemtl':
|
||||||
if l[1] == '(null)':
|
if l[1] == '(null)':
|
||||||
currentMat = NULL_MAT
|
currentMat = getMat(NULL_MAT)
|
||||||
else:
|
else:
|
||||||
currentMat = getMat(join(l[1:])) # Use join in case of spaces
|
currentMat = getMat(join(l[1:])) # Use join in case of spaces
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user