Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions README.txt
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
44 changes: 25 additions & 19 deletions addon_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from mathutils import Matrix,Vector
from BlenderExtensions import *

BASEPATH = 'CUSTOMMODELS'
BASEPATH = 'CUSTOM/MODELS'

customNodes = NMSNodes()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 """

Expand Down Expand Up @@ -504,20 +508,22 @@ def anim_generator(self):
StillFrameData = StillFrameData))
return AnimationFiles

#Main Mesh parser - Fixed to eliminate faceting
# FIXED: Fixed mesh parser for proper orientation and smoothing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also no fixes here...

def mesh_parser(self, ob):
#Lists
verts = []
norms = []
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!
Expand Down Expand Up @@ -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)
Expand Down