-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to generate skydome geometry data for Iron
- Loading branch information
1 parent
a657d6e
commit 3fe32f5
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
This script generates the skydome geometry data as stored in | ||
iron/Sources/iron/data/ConstData.hx. | ||
USAGE: | ||
On MacOS/Linux: | ||
Open Blender from the terminal to see the console output. | ||
On Windows: | ||
Open the Blender console via "Window > Toggle System Console". | ||
Select the skydome object in object mode and run this script. Note | ||
that the script flips the normals in the output. The original mesh | ||
is not modified. | ||
After running the script, open the console. If the script ran | ||
successfully, the generated vertex data was printed to the console, | ||
ready to copy to ConstData.hx. | ||
""" | ||
import bmesh | ||
import bpy | ||
|
||
|
||
def list_representation(lst) -> str: | ||
"""List to string without spaces.""" | ||
return f"[{','.join(str(i) for i in lst)}]" | ||
|
||
|
||
def run(): | ||
obj = bpy.context.object | ||
|
||
if obj is None: | ||
print("No object selected, aborting!") | ||
return | ||
|
||
if obj.type != "MESH": | ||
print(f"Selected object '{obj.name}' is not a mesh, aborting!") | ||
return | ||
|
||
bm = bmesh.new() | ||
bm.from_mesh(obj.data) | ||
bmesh.ops.triangulate(bm, faces=bm.faces[:], quad_method="FIXED") | ||
|
||
indices = [] | ||
pos = [] | ||
nor = [] | ||
|
||
# Fill index buffer | ||
for face in bm.faces: | ||
# Turn the normals inside | ||
face.normal_flip() | ||
|
||
for vert in face.verts: | ||
indices.append(vert.index) | ||
|
||
# Vertex buffer data | ||
for vert in bm.verts: | ||
pos.extend(vert.co) | ||
nor.extend(vert.normal) | ||
|
||
bm.free() | ||
|
||
print("\n====================") | ||
print(f"Calculated mesh data for object '{obj.name}':") | ||
print(f"Indices: {list_representation(indices)}") | ||
print("") | ||
print(f"Positions: {list_representation(pos)}") | ||
print("") | ||
print(f"Normals: {list_representation(nor)}") | ||
|
||
|
||
if __name__ == "__main__": | ||
run() |