Skip to content

Patched as of blender 4.1+ #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
61 changes: 31 additions & 30 deletions spaceship_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def add_cylinders_to_face(bm, face):
cap_ends=True,
cap_tris=False,
segments=num_segments,
diameter1=cylinder_size,
diameter2=cylinder_size,
radius1=cylinder_size/2,
radius2=cylinder_size/2,
depth=cylinder_depth,
matrix=cylinder_matrix)

Expand Down Expand Up @@ -233,8 +233,8 @@ def add_weapons_to_face(bm, face):
cap_ends=True,
cap_tris=False,
segments=num_segments,
diameter1=weapon_size * 0.9,
diameter2=weapon_size,
radius1=weapon_size * 0.9/2,
radius2=weapon_size/2,
depth=weapon_depth,
matrix=face_matrix)

Expand All @@ -246,8 +246,8 @@ def add_weapons_to_face(bm, face):
cap_ends=True,
cap_tris=False,
segments=num_segments,
diameter1=weapon_size * 0.6,
diameter2=weapon_size * 0.5,
radius1=(weapon_size * 0.6)/2,
radius2=(weapon_size * 0.5)/2,
depth=weapon_depth * 2,
matrix=left_guard_mat)

Expand All @@ -259,8 +259,8 @@ def add_weapons_to_face(bm, face):
cap_ends=True,
cap_tris=False,
segments=num_segments,
diameter1=weapon_size * 0.5,
diameter2=weapon_size * 0.6,
radius1=(weapon_size * 0.5)/2,
radius2=(weapon_size * 0.6)/2,
depth=weapon_depth * 2,
matrix=right_guard_mat)

Expand All @@ -273,8 +273,8 @@ def add_weapons_to_face(bm, face):
cap_ends=True,
cap_tris=False,
segments=8,
diameter1=weapon_size * 0.4,
diameter2=weapon_size * 0.4,
radius1=weapon_size * 0.4/2,
radius2=weapon_size * 0.4/2,
depth=weapon_depth * 5,
matrix=turret_house_mat)

Expand All @@ -283,17 +283,17 @@ def add_weapons_to_face(bm, face):
cap_ends=True,
cap_tris=False,
segments=8,
diameter1=weapon_size * 0.1,
diameter2=weapon_size * 0.1,
radius1=weapon_size * 0.1/2,
radius2=weapon_size * 0.1/2,
depth=weapon_depth * 6,
matrix=turret_house_mat @ \
Matrix.Translation(Vector((weapon_size * 0.2, 0, -weapon_size))).to_4x4())
bmesh.ops.create_cone(bm,
cap_ends=True,
cap_tris=False,
segments=8,
diameter1=weapon_size * 0.1,
diameter2=weapon_size * 0.1,
radius1=weapon_size * 0.1/2,
radius2=weapon_size * 0.1/2,
depth=weapon_depth * 6,
matrix=turret_house_mat @ \
Matrix.Translation(Vector((weapon_size * -0.2, 0, -weapon_size))).to_4x4())
Expand All @@ -309,7 +309,7 @@ def add_sphere_to_face(bm, face):
uniform(0, sphere_size * 0.5))
result = bmesh.ops.create_icosphere(bm,
subdivisions=3,
diameter=sphere_size,
radius=sphere_size/2,
matrix=sphere_matrix)
for vert in result['verts']:
for face in vert.link_faces:
Expand Down Expand Up @@ -337,13 +337,13 @@ def add_surface_antenna_to_face(bm, face):
material_index = Material.hull if random() > 0.5 else Material.hull_dark

# Spire
num_segments = uniform(3, 6)
num_segments = int(uniform(3, 6))
result = bmesh.ops.create_cone(bm,
cap_ends=False,
cap_tris=False,
segments=num_segments,
diameter1=0,
diameter2=base_diameter,
radius1=0,
radius2=base_diameter/2,
depth=depth,
matrix=get_face_matrix(face, pos + face.normal * depth * 0.5))
for vert in result['verts']:
Expand All @@ -355,8 +355,8 @@ def add_surface_antenna_to_face(bm, face):
cap_ends=True,
cap_tris=False,
segments=num_segments,
diameter1=base_diameter * uniform(1, 1.5),
diameter2=base_diameter * uniform(1.5, 2),
radius1=base_diameter * uniform(1, 1.5)/2,
radius2=base_diameter * uniform(1.5, 2)/2,
depth=depth_short,
matrix=get_face_matrix(face, pos + face.normal * depth_short * 0.45))
for vert in result['verts']:
Expand All @@ -373,16 +373,16 @@ def add_disc_to_face(bm, face):
cap_ends=True,
cap_tris=False,
segments=32,
diameter1=depth * 3,
diameter2=depth * 4,
radius1=depth * 3/2,
radius2=depth * 4/2,
depth=depth,
matrix=get_face_matrix(face, face.calc_center_bounds() + face.normal * depth * 0.5))
result = bmesh.ops.create_cone(bm,
cap_ends=False,
cap_tris=False,
segments=32,
diameter1=depth * 1.25,
diameter2=depth * 2.25,
radius1=depth * 1.25/2,
radius2=depth * 2.25/2,
depth=0.0,
matrix=get_face_matrix(face, face.calc_center_bounds() + face.normal * depth * 1.05))
for vert in result['verts']:
Expand Down Expand Up @@ -416,7 +416,7 @@ def add_hull_normal_map(mat, hull_normal_map):

teximage_node = ntree.nodes.new('ShaderNodeTexImage')
teximage_node.image = hull_normal_map
teximage_node.image.colorspace_settings.name = 'Raw'
teximage_node.image.colorspace_settings.name = 'sRGB'#'Raw'
teximage_node.projection ='BOX'
tex_coords_node = ntree.nodes.new('ShaderNodeTexCoord')
links.new(tex_coords_node.outputs['Object'], teximage_node.inputs['Vector'])
Expand All @@ -430,8 +430,8 @@ def add_hull_normal_map(mat, hull_normal_map):
# Sets some basic properties for a hull material.
def set_hull_mat_basics(mat, color, hull_normal_map):
shader_node = getShaderNode(mat)
shader_node.inputs["Specular"].default_value = 0.1
shader_node.inputs["Base Color"].default_value = color
shader_node.inputs[12].default_value = 0.1#Note: input 12 is specular IOR
shader_node.inputs[0].default_value = color

return add_hull_normal_map(mat, hull_normal_map)

Expand Down Expand Up @@ -486,7 +486,8 @@ def create_materials():
teximage_emit_node.image = hull_lights_emessive_map
teximage_emit_node.projection ='BOX'
links.new(tex_coords_node.outputs['Object'], teximage_emit_node.inputs['Vector'])
links.new(teximage_emit_node.outputs[0], shader_node.inputs["Emission"])
links.new(teximage_emit_node.outputs[0], shader_node.inputs[0])#input 0 is emission color




Expand All @@ -501,12 +502,12 @@ def create_materials():
# # Build the exhaust_burn texture
mat = ret[Material.exhaust_burn]
shader_node = getShaderNode(mat)
shader_node.inputs["Emission"].default_value = glow_color
shader_node.inputs[0].default_value = glow_color

# # Build the glow_disc texture
mat = ret[Material.glow_disc]
shader_node = getShaderNode(mat)
shader_node.inputs["Emission"].default_value = glow_color
shader_node.inputs[0].default_value = glow_color

return ret

Expand Down