From 877fe884c093af3eebaa62fa6d115ae5877f3bd3 Mon Sep 17 00:00:00 2001 From: RaYRoD TV <58117976+RaYRoD-TV@users.noreply.github.com> Date: Mon, 31 Mar 2025 22:35:53 -0400 Subject: [PATCH 1/6] Update addon_script.py - Coordinate System Fix: Properly transformed between Blender's Z-up and No Man's Sky's Y-up coordinate systems - Vertex Processing: Enhanced handling of vertices, normals, and tangents for correct orientation - Smooth Shading: Improved normal averaging for shared vertices - Vector Dimension Fix: Corrected the tangent calculation to use 3D vectors during processing and only convert to 4D at the end - Tangent Vector Dimension Fix: Fixed dimension mismatch by: Using 3D vectors during calculation instead of 4D Only converting to 4D vectors (w=1.0) at the end - Transformation Matrix: Improved transformation matrix calculations for consistent model positioning and rotation - Model Orientation: Fixed upside-down and incorrectly rotated models in-game --- addon_script.py | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/addon_script.py b/addon_script.py index a0a26bc..28de7d3 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,7 @@ def get_children(obj, curr_children, obj_type, just_names = False): """ Misc. functions for transforming data """ -#Improved Tangent Calculator +# IMPROVEMENT: Improved Tangent Calculator with better smoothing def calc_tangents(faces, verts, norms, uvs): tangents = [] #Init tangents @@ -166,40 +166,46 @@ def calc_tangents(faces, verts, norms, uvs): return tangents +# FIXED: Improved transform application function for better orientation 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 +510,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 +518,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 +601,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) From 1e173c348d2bfaf707f9383961ed9f441239a313 Mon Sep 17 00:00:00 2001 From: RaYRoD TV <58117976+RaYRoD-TV@users.noreply.github.com> Date: Mon, 31 Mar 2025 22:45:31 -0400 Subject: [PATCH 2/6] Update README.txt --- README.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.txt b/README.txt index 4d4146d..c142217 100644 --- a/README.txt +++ b/README.txt @@ -1,6 +1,6 @@ <<<<<<< HEAD -NMS Custom Model Importer - alpha -coded by monkeyman192 and gregkwaste +NMS Custom Model Importer (pathfinder edition) +coded by monkeyman192 and gregkwaste and revised by RaYRoD_TV Custom blender addon to export models from blender into a format that is compatible with No Man's Sky. From 53962b841a577e3b9c1688a3dfb1201ea698a819 Mon Sep 17 00:00:00 2001 From: RaYRoD TV <58117976+RaYRoD-TV@users.noreply.github.com> Date: Mon, 31 Mar 2025 22:46:14 -0400 Subject: [PATCH 3/6] Update README.txt --- README.txt | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/README.txt b/README.txt index c142217..98998b9 100644 --- a/README.txt +++ b/README.txt @@ -1,21 +1,3 @@ <<<<<<< HEAD -NMS Custom Model Importer (pathfinder edition) -coded by monkeyman192 and gregkwaste and revised by RaYRoD_TV - -Custom blender addon to export models from blender into a format that is compatible with No Man's Sky. - -For a full guide on how to prepare models in blender for exporting read 'Blender Model Setup Guide.txt' -For a full guide on how to add the exported model into No Man's Sky, read 'Adding Model to Mod Guide.txt' - -Any issues please check the Issues page here and we will attempt to fix them as soon as possible. - -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 +NMS Custom Model Importer (for pre-Atlas Rises versions) +coded by monkeyman192 and gregkwaste and improved by RaYRoD_TV From a7561a34a8815e51c9507eb5dc91d571e308e773 Mon Sep 17 00:00:00 2001 From: RaYRoD TV <58117976+RaYRoD-TV@users.noreply.github.com> Date: Mon, 31 Mar 2025 22:46:26 -0400 Subject: [PATCH 4/6] Update README.txt --- README.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/README.txt b/README.txt index 98998b9..5d44cc6 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,2 @@ -<<<<<<< HEAD NMS Custom Model Importer (for pre-Atlas Rises versions) coded by monkeyman192 and gregkwaste and improved by RaYRoD_TV From d6d953dd63ecf9c119447bf97bbd5b929d1c50ed Mon Sep 17 00:00:00 2001 From: RaYRoD TV <58117976+RaYRoD-TV@users.noreply.github.com> Date: Mon, 31 Mar 2025 23:07:50 -0400 Subject: [PATCH 5/6] Update README.txt --- README.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.txt b/README.txt index 5d44cc6..1306ad6 100644 --- a/README.txt +++ b/README.txt @@ -1,2 +1,13 @@ -NMS Custom Model Importer (for pre-Atlas Rises versions) -coded by monkeyman192 and gregkwaste and improved by RaYRoD_TV +NMS Custom Model Importer - alpha +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. + +For a full guide on how to prepare models in blender for exporting read 'Blender Model Setup Guide.txt' +For a full guide on how to add the exported model into No Man's Sky, read 'Adding Model to Mod Guide.txt' + +Any issues please check the Issues page here and we will attempt to fix them as soon as possible. + +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! From c55250300fc02ea962fc73bf3af90360b6673885 Mon Sep 17 00:00:00 2001 From: RaYRoD TV <58117976+RaYRoD-TV@users.noreply.github.com> Date: Mon, 31 Mar 2025 23:31:51 -0400 Subject: [PATCH 6/6] Update addon_script.py --- addon_script.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/addon_script.py b/addon_script.py index 28de7d3..4d5f904 100644 --- a/addon_script.py +++ b/addon_script.py @@ -104,7 +104,6 @@ def get_children(obj, curr_children, obj_type, just_names = False): """ Misc. functions for transforming data """ -# IMPROVEMENT: Improved Tangent Calculator with better smoothing def calc_tangents(faces, verts, norms, uvs): tangents = [] #Init tangents @@ -166,7 +165,6 @@ def calc_tangents(faces, verts, norms, uvs): return tangents -# FIXED: Improved transform application function for better orientation def apply_local_transforms(rotmat, verts, norms, tangents, create_tangents = False): """Apply transformation matrices to vertices, normals and tangents""" # Create proper normal transformation matrix