Hello everyone,
I’m new to this forum, and new to python/blender in general, so go easy on me
Basically I play this dead online game that the source to was released to public in my free time, and I was able to get the header files of their 3D model extensions.
So I wrote a script that exports and imports these 3D model extensions into blender successfully, and I was able to create my own custom models and etc.
However… I recently stepped upon a problem that I cannot seem to figure out.
The UV of the model that I work on is fine… but once I export it to the new extension for some reason it completely messes it up. This only happens with SOME models… not all.
Here’s a picture to help understand more:
BEFORE EXPORTING
AFTER EXPORTING
NOTE: Again… this only happens with some models… not all.
Maybe a new set of fresh eyes can see what I can’t seem to be seeing.
export.py
bl_info = { “name”: “OBJ format”,
“blender”: (2, 5, 8),
“api”: 35622,
“location”: “File > Export”,
“description”: (“Export models with vertgroups.”),
“warning”: “”,
“wiki_url”: “”,
“tracker_url”: “”,
“category”: “Import-Export”}import bpy
import mathutils
import math
from string import *
from struct import *
from math import *
from bpy.props import *def objexport(path):
obj = bpy.context.scene.objects.active
if obj.type != ‘MESH’:
raise(IOError, ‘You must select the mesh’)
else:
meshname = ‘’
groupnames =
vertgroups =
verts =
normals =
uv =
faces =meshname = obj.name mesh = obj.data tex = mesh.uv_layers.active for vert in obj.data.vertices: verts.append(vert.co.xzy) uv.append([]) groups = [] for group in vert.groups: groups.append(group.group) vertgroups.append(groups) for face in mesh.polygons: faces.append(face.vertices) normals.append(mesh.vertices[face.vertices[0]].normal) for i, texface in enumerate(tex.data): uv[faces[math.floor(i/3)][i%3]] = texface for group in obj.vertex_groups: groupnames.append(group.name) lines = [] lines.append('#SROBJ Blender plugin.'+'
')
lines.append('o ‘+meshname+’
')for groupname in groupnames: lines.append('gn '+groupname+'
')
for groups in vertgroups: if len(groups) == 1: groups.append(255) lines.append('vg '+str(groups[0])+'/'+str(groups[1])+'
')
for vert in verts: lines.append('v '+str(vert[0])+' '+str(vert[1])+' '+str(vert[2]*-1)+'
')
for norm in normals: lines.append('vn '+str(norm[0])+' '+str(norm[2])+' '+str(norm[1])+'
')
for coords in uv: lines.append('vt '+str(coords.uv[0])+' '+str(coords.uv[1])+'
')
for i, face in enumerate(faces): lines.append('f '+str(face[0]+1)+'/'+str(face[0]+1)+'/'+str(i+1)+' '+str(face[1]+1)+'/'+str(face[1]+1)+'/'+str(i+1)+' '+str(face[2]+1)+'/'+str(face[2]+1)+'/'+str(i+1)+'
')
f = open(path, 'w') f.writelines(lines) f.close()
def getInputFilename(self,filename):
checktype = filename.split(‘\’)[-1][-6:]
print (“------------”,filename)
if checktype.lower() != ‘.srobj’:
objexport(filename+‘.srobj’)
#self.report({‘INFO’}, (“Selected file:”+ filename))
else:
objexport(filename)class EXPORT_OT_psk(bpy.types.Operator):
‘’‘Load a skeleton mesh psk File’‘’
bl_idname = “export_scene.srobj”
bl_label = “Export SROBJ”
bl_space_type = “PROPERTIES”
bl_region_type = “WINDOW”# List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. filepath = StringProperty( name="File Path", description="Filepath used for importing the srobj file", maxlen= 1024, subtype='FILE_PATH', ) def execute(self, context): getInputFilename(self,self.filepath) return {'FINISHED'} def invoke(self, context, event): wm = context.window_manager wm.fileselect_add(self) return {'RUNNING_MODAL'}
def menu_func(self, context):
self.layout.operator(EXPORT_OT_psk.bl_idname, text=“Object (.srobj)”)def register():
bpy.utils.register_module(name)
bpy.types.INFO_MT_file_export.append(menu_func)def unregister():
bpy.utils.unregister_module(name)
bpy.types.INFO_MT_file_export.remove(menu_func)if name == “main”:
register()
Any help is appreciated