diff --git a/README.txt b/README.txt index 4d4146d..1306ad6 100644 --- a/README.txt +++ b/README.txt @@ -1,6 +1,5 @@ -<<<<<<< HEAD NMS Custom Model Importer - alpha -coded by monkeyman192 and gregkwaste +coded by monkeyman192 and gregkwaste with fixes by RaYRoD_TV Custom blender addon to export models from blender into a format that is compatible with No Man's Sky. @@ -12,10 +11,3 @@ Any issues please check the Issues page here and we will attempt to fix them as At the moment this addon is limited to exporting static models with textures and collisions. Support will hopefully come in the future for more features! Enjoy! -======= -NMS Custom Model Importer - experimental branch -coded by monkeyman192 and gregkwaste - -This branch contains experimental builds of the model importer as we work on them. We make absolutely no guarantee that the code contained in this branch will work as it could be updated with test code that we are tyring to get to work. All working updates will be pushed to the master branch for proper release when they are complete. -Please only make Issue requests for problems with the master branch. ->>>>>>> Experimental diff --git a/addon_script.py b/addon_script.py index a0a26bc..4d5f904 100644 --- a/addon_script.py +++ b/addon_script.py @@ -18,7 +18,7 @@ from mathutils import Matrix,Vector from BlenderExtensions import * -BASEPATH = 'CUSTOMMODELS' +BASEPATH = 'CUSTOM/MODELS' customNodes = NMSNodes() @@ -104,7 +104,6 @@ def get_children(obj, curr_children, obj_type, just_names = False): """ Misc. functions for transforming data """ -#Improved Tangent Calculator def calc_tangents(faces, verts, norms, uvs): tangents = [] #Init tangents @@ -168,38 +167,43 @@ def calc_tangents(faces, verts, norms, uvs): def apply_local_transforms(rotmat, verts, norms, tangents, create_tangents = False): """Apply transformation matrices to vertices, normals and tangents""" + # Create proper normal transformation matrix norm_mat = rotmat.inverted().transposed() - print(len(verts), len(norms), len(tangents)) for i in range(len(verts)): - #Load Vertex + # Transform vertex position vert = rotmat * Vector((verts[i][0], verts[i][1], verts[i][2])) - #Store Transformed verts[i] = (vert[0], vert[1], vert[2], 1.0) - #Load Normal and ensure normalization + # Transform normal vector and normalize norm = norm_mat * Vector((norms[i][0], norms[i][1], norms[i][2])) norm.normalize() - #Store Transformed normal norms[i] = (norm[0], norm[1], norm[2], 1.0) - #Load Tangent + # Transform tangent if needed if create_tangents and i < len(tangents): tang = norm_mat * Vector((tangents[i][0], tangents[i][1], tangents[i][2])) tang.normalize() - #Store Transformed tangent tangents[i] = (tang[0], tang[1], tang[2], 1.0) +# FIXED: Fixed coordinate transformation for proper orientation def transform_to_NMS_coords(ob): - # this will return the local transform, rotation and scale of the object in the NMS coordinate system - matrix = ob.matrix_local - yzmat = Matrix() - yzmat[0] = Vector((1.0, 0.0, 0.0, 0.0)) - yzmat[1] = Vector((0.0, 0.0, -1.0, 0.0)) - yzmat[2] = Vector((0.0, 1.0, 0.0, 0.0)) - yzmat[3] = Vector((0.0, 0.0, 0.0, 1.0)) + """ + Properly transform coordinates from Blender (Z-up) to No Man's Sky (Y-up) + Returns the transformed position, rotation and scale + """ + # Create a transformation matrix for Z-up to Y-up conversion + # This is a 90-degree rotation around the X-axis + correction = Matrix.Rotation(radians(-90), 4, 'X') - return (yzmat * ob.matrix_local * yzmat).decompose() + # Get the object's world matrix and apply the correction + matrix = ob.matrix_local.copy() + corrected_matrix = correction * matrix * correction.inverted() + + # Decompose the matrix to get position, rotation and scale + pos, rot, scale = corrected_matrix.decompose() + + return pos, rot, scale """ Main exporter class with all the other functions contained in one place """ @@ -504,7 +508,7 @@ def anim_generator(self): StillFrameData = StillFrameData)) return AnimationFiles - #Main Mesh parser - Fixed to eliminate faceting + # FIXED: Fixed mesh parser for proper orientation and smoothing def mesh_parser(self, ob): #Lists verts = [] @@ -512,12 +516,14 @@ def mesh_parser(self, ob): tangents = [] luvs = [] faces = [] + # Matrices object_matrix_wrld = ob.matrix_world rot_x_mat = Matrix.Rotation(radians(-90), 4, 'X') scale_mat = Matrix.Scale(1, 4) norm_mat = rot_x_mat.inverted().transposed() + # Apply pre-rotation to fix orientation before export data = ob.data # Attempt to set smooth shading on the mesh - this is essential! @@ -593,7 +599,7 @@ def mesh_parser(self, ob): def parse_object(self, ob, parent): newob = None - # get the objects' location and convert to NMS coordinates + # FIXED: Get the objects' location and convert to NMS coordinates using improved func trans, rot_q, scale = transform_to_NMS_coords(ob) rot = rot_q.to_euler() print(trans)