collada_scene: load vertex/index buffers from descriptor

This commit is contained in:
Zack Buhman 2026-02-02 21:57:50 -06:00
parent 86b0abad5b
commit a7dfd1b782
14 changed files with 82 additions and 54 deletions

View File

@ -51,8 +51,7 @@ SHADERS = \
$(BUILD_TYPE)/effect/collada.fxo \
$(BUILD_TYPE)/effect/collada_scene.fxo
SCENES = \
src/scenes/curve_interpolation/curve_interpolation.cpp
SCENES = $(shell find src/scenes -type f -name "*.cpp")
include curve_interpolation.mk
include ship20.mk
@ -79,7 +78,7 @@ include/scenes/%.hpp: $(COLLADA_PY_SOURCE)
src/scenes/%.cpp: scenes/%.DAE include/scenes/%.hpp
@mkdir -p $(@D)
PYTHONPATH=. python -m collada.main $< $@ $(<:.DAE=.vtx) $(<:.DAE=.idx) $(<:.DAE=.vjw) rc/$(notdir $(<:.DAE=.rc)) $(notdir $(<:.DAE=.mk))
PYTHONPATH=. python -m collada.main $< $@ $(<:.DAE=.vtx) $(<:.DAE=.vjw) $(<:.DAE=.idx) rc/$(notdir $(<:.DAE=.rc)) $(notdir $(<:.DAE=.mk))
OBJS = \
$(BUILD_TYPE)/main.res \

View File

@ -24,7 +24,7 @@ class State:
# buffers
vertex_buffer: BytesIO
index_buffer: BytesIO
joints_weights_vertex_buffer: BytesIO
joint_weight_vertex_buffer: BytesIO
# geometry__indices:
# keys: collada <geometry> id
@ -68,7 +68,7 @@ class State:
def __init__(self, input_filename):
self.vertex_buffer = BytesIO()
self.index_buffer = BytesIO()
self.joints_weights_vertex_buffer = BytesIO()
self.joint_weight_vertex_buffer = BytesIO()
self.geometry__indices = {}
self.geometry__vertex_index_tables = {}
self.symbol_names = {}
@ -662,6 +662,10 @@ def render_descriptor(namespace):
yield ""
yield ".images = images,"
yield ".images_count = (sizeof (images)) / (sizeof (images[0])),"
yield ""
yield f'.position_normal_texture_buffer = L"RES_SCENES_{namespace.upper()}_VTX",'
yield f'.joint_weight_buffer = L"RES_SCENES_{namespace.upper()}_VJW",'
yield f'.index_buffer = L"RES_SCENES_{namespace.upper()}_IDX",'
yield "};"
def render_end_of_namespace():
@ -949,9 +953,9 @@ def render_controller(state, collada, controller):
# fixme: skin_vertex_buffer should multiply vertices by the bind shape matrix
vertex_buffer = buffer.skin_vertex_buffer(collada, skin, vertex_index_table)
# skin.vertex_weights and skin.source are entirely dealt with
vertex_buffer_offset = state.joints_weights_vertex_buffer.tell()
renderbin_any(state.joints_weights_vertex_buffer, vertex_buffer)
vertex_buffer_size = state.joints_weights_vertex_buffer.tell() - vertex_buffer_offset
vertex_buffer_offset = state.joint_weight_vertex_buffer.tell()
renderbin_any(state.joint_weight_vertex_buffer, vertex_buffer)
vertex_buffer_size = state.joint_weight_vertex_buffer.tell() - vertex_buffer_offset
yield from render_inverse_bind_matrices(collada, skin, controller_name)

View File

@ -7,7 +7,7 @@ from collada import header
def usage():
name = sys.argv[0]
print("usage (source):")
print(f" {name} [input_collada.dae] [output_source.cpp] [output_vertex.vtx] [output_vertex.idx] [output_joints_weights_vertex.vjw] [output_resource.rc] [output_makefile.mk]")
print(f" {name} [input_collada.dae] [output_source.cpp] [output_position_normal_texture.vtx] [output_joint_weight.vjw] [output_index.idx] [output_resource.rc] [output_makefile.mk]")
print("usage (header):")
print(f" {name} [output_header.hpp]")
sys.exit(1)
@ -16,7 +16,11 @@ def parse_namespace(filename):
namespace = os.path.splitext(os.path.split(filename)[1])[0]
return namespace
def render_resource_file(state, f):
def render_resource_file(state, namespace, output_vtx, output_vjw, output_idx, f):
f.write(f'RES_SCENES_{namespace.upper()}_VTX RCDATA "{output_vtx}"\r\n'.encode('ascii'))
f.write(f'RES_SCENES_{namespace.upper()}_VJW RCDATA "{output_vjw}"\r\n'.encode('ascii'))
f.write(f'RES_SCENES_{namespace.upper()}_IDX RCDATA "{output_idx}"\r\n'.encode('ascii'))
f.write(b"\r\n")
for resource_name, path in state.resource_names.items():
filename = os.path.split(path)[1]
filename = os.path.splitext(filename)[0]
@ -41,23 +45,25 @@ def render_makefile(state, f):
f.write(f"IMAGES += image/{filename}.DDS\r\n".encode('ascii'))
f.write(f"image/{filename}.DDS: {escaped}\r\n".encode('ascii'))
f.write(f"\t@mkdir -p image\r\n".encode('ascii'))
f.write('\ttexconv10.exe -f BC1_UNORM -nologo "$<"\r\n'.encode('ascii'))
f.write(f'\tmv "$(<:.{ext[1:]}=.DDS)" "$@"\r\n\r\n'.encode('ascii'))
f.write(f'\tmv "$(<:.{ext[1:]}=.DDS)" "$@"\r\n'.encode('ascii'))
f.write(b"\r\n")
def main():
try:
input_collada = sys.argv[1]
output_source = sys.argv[2]
output_vertex = sys.argv[3]
output_index = sys.argv[4]
output_joints_weights_vertex = sys.argv[5]
output_position_normal_texture = sys.argv[3]
output_joint_weight = sys.argv[4]
output_index = sys.argv[5]
output_resource = sys.argv[6]
output_makefile = sys.argv[7]
assert input_collada.lower().endswith(".dae")
assert output_source.lower().endswith(".cpp")
assert output_vertex.lower().endswith(".vtx")
assert output_position_normal_texture.lower().endswith(".vtx")
assert output_joint_weight.lower().endswith(".vjw")
assert output_index.lower().endswith(".idx")
assert output_joints_weights_vertex.lower().endswith(".vjw")
assert output_resource.lower().endswith(".rc")
assert output_makefile.lower().endswith(".mk")
except Exception as e:
@ -72,17 +78,17 @@ def main():
assert "\r\n" in source_buf
f.write(source_buf.encode('utf-8'))
with open(output_vertex, 'wb') as f:
with open(output_position_normal_texture, 'wb') as f:
f.write(state.vertex_buffer.getvalue())
with open(output_index, 'wb') as f:
f.write(state.index_buffer.getvalue())
with open(output_joints_weights_vertex, 'wb') as f:
f.write(state.joints_weights_vertex_buffer.getvalue())
with open(output_joint_weight, 'wb') as f:
f.write(state.joint_weight_vertex_buffer.getvalue())
with open(output_resource, 'wb') as f:
render_resource_file(state, f)
render_resource_file(state, namespace, output_position_normal_texture, output_joint_weight, output_index, f)
with open(output_makefile, 'wb') as f:
render_makefile(state, f)

View File

@ -1,25 +1,30 @@
IMAGES += image/american_cherry.DDS
image/american_cherry.DDS: C:/Program\ Files/Common\ Files/Autodesk\ Shared/Materials/Textures/1/Mats/american_cherry.png
@mkdir -p image
texconv10.exe -f BC1_UNORM -nologo "$<"
mv "$(<:.png=.DDS)" "$@"
IMAGES += image/Masonry.Unit\ Masonry.Glass\ Block.Square.Stack.DDS
image/Masonry.Unit\ Masonry.Glass\ Block.Square.Stack.DDS: C:/Program\ Files/Common\ Files/Autodesk\ Shared/Materials/Textures/2/Mats/Masonry.Unit\ Masonry.Glass\ Block.Square.Stack.jpg
@mkdir -p image
texconv10.exe -f BC1_UNORM -nologo "$<"
mv "$(<:.jpg=.DDS)" "$@"
IMAGES += image/102.DDS
image/102.DDS: C:/Program\ Files/Common\ Files/Autodesk\ Shared/Materials/Textures/3/Mats/102.png
@mkdir -p image
texconv10.exe -f BC1_UNORM -nologo "$<"
mv "$(<:.png=.DDS)" "$@"
IMAGES += image/Finishes.Flooring.Tile.Square.Medium\ Blue.DDS
image/Finishes.Flooring.Tile.Square.Medium\ Blue.DDS: C:/Program\ Files/Common\ Files/Autodesk\ Shared/Materials/Textures/3/Mats/Finishes.Flooring.Tile.Square.Medium\ Blue.png
@mkdir -p image
texconv10.exe -f BC1_UNORM -nologo "$<"
mv "$(<:.png=.DDS)" "$@"
IMAGES += image/SiteWork.Planting.Grass.Bermuda1.DDS
image/SiteWork.Planting.Grass.Bermuda1.DDS: C:/Program\ Files/Common\ Files/Autodesk\ Shared/Materials/Textures/3/Mats/SiteWork.Planting.Grass.Bermuda1.jpg
@mkdir -p image
texconv10.exe -f BC1_UNORM -nologo "$<"
mv "$(<:.jpg=.DDS)" "$@"

View File

@ -398,5 +398,10 @@ namespace collada {
//animation const * const animations;
//int const animations_count;
// hmm, this part is not really platform-agnostic:
wchar_t const * const position_normal_texture_buffer;
wchar_t const * const joint_weight_buffer;
wchar_t const * const index_buffer;
};
}

View File

@ -1,3 +1,7 @@
RES_SCENES_CURVE_INTERPOLATION_VTX RCDATA "scenes/curve_interpolation/curve_interpolation.vtx"
RES_SCENES_CURVE_INTERPOLATION_VJW RCDATA "scenes/curve_interpolation/curve_interpolation.vjw"
RES_SCENES_CURVE_INTERPOLATION_IDX RCDATA "scenes/curve_interpolation/curve_interpolation.idx"
_AMERICAN_CHERRY_PNG RCDATA "image/american_cherry.DDS"
_MASONRY_UNIT_MASONRY_GLASS_BLOCK_SQUARE_STACK_JPG RCDATA "image/Masonry.Unit Masonry.Glass Block.Square.Stack.DDS"
_102_PNG RCDATA "image/102.DDS"

View File

@ -10,11 +10,3 @@ RES_FONT_TERMINUS_6X12 RCDATA "font/terminus_128x64_6x12.data"
RES_COLLADA_FXO RCDATA "collada.fxo"
RES_COLLADA_SCENE_FXO RCDATA "collada_scene.fxo"
RES_MODELS_CURVE_INTERPOLATION_VTX RCDATA "scenes/curve_interpolation/curve_interpolation.vtx"
RES_MODELS_CURVE_INTERPOLATION_IDX RCDATA "scenes/curve_interpolation/curve_interpolation.idx"
RES_MODELS_CURVE_INTERPOLATION_VJW RCDATA "scenes/curve_interpolation/curve_interpolation.vjw"
RES_SCENES_SHIP20_VTX RCDATA "scenes/ship20/ship20.vtx"
RES_SCENES_SHIP20_IDX RCDATA "scenes/ship20/ship20.idx"
RES_SCENES_SHIP20_VJW RCDATA "scenes/ship20/ship20.vjw"

View File

@ -1 +1,5 @@
RES_SCENES_SHIP20_VTX RCDATA "scenes/ship20/ship20.vtx"
RES_SCENES_SHIP20_VJW RCDATA "scenes/ship20/ship20.vjw"
RES_SCENES_SHIP20_IDX RCDATA "scenes/ship20/ship20.idx"
_0_SHIPPLE2_PNG RCDATA "image/0_shipple2.DDS"

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -1,5 +1,6 @@
IMAGES += image/0_shipple2.DDS
image/0_shipple2.DDS: scenes/ship20/./images/0_shipple2.png
@mkdir -p image
texconv10.exe -f BC1_UNORM -nologo "$<"
mv "$(<:.png=.DDS)" "$@"

View File

@ -209,15 +209,15 @@ namespace collada_scene {
if (FAILED(hr))
return E_FAIL;
hr = LoadVertexBuffer(L"RES_SCENES_SHIP20_VTX", &m_pVertexBuffers[0]);
hr = LoadVertexBuffer(descriptor->position_normal_texture_buffer, &m_pVertexBuffers[0]);
if (FAILED(hr))
return E_FAIL;
hr = LoadVertexBuffer(L"RES_SCENES_SHIP20_VJW", &m_pVertexBuffers[1]);
hr = LoadVertexBuffer(descriptor->joint_weight_buffer, &m_pVertexBuffers[1]);
if (FAILED(hr))
return E_FAIL;
hr = LoadIndexBuffer(L"RES_SCENES_SHIP20_IDX", &m_pIndexBuffer);
hr = LoadIndexBuffer(descriptor->index_buffer, &m_pIndexBuffer);
if (FAILED(hr))
return E_FAIL;

View File

@ -2248,8 +2248,8 @@ instance_light const instance_lights_node_cube[] = {
};
channel const * const node_channels_node_cube[] = {
&node_channel_node_cube_translation_y,
&node_channel_node_cube_translation_x,
&node_channel_node_cube_translation_y,
};
node const node_node_cube = {
@ -2519,9 +2519,9 @@ instance_light const instance_lights_node_geosphere[] = {
};
channel const * const node_channels_node_geosphere[] = {
&node_channel_node_geosphere_scaleaxisrotation,
&node_channel_node_geosphere_inversescaleaxisrotation,
&node_channel_node_geosphere_scale,
&node_channel_node_geosphere_inversescaleaxisrotation,
&node_channel_node_geosphere_scaleaxisrotation,
};
node const node_node_geosphere = {
@ -2569,8 +2569,8 @@ instance_light const instance_lights_node_light[] = {
};
channel const * const node_channels_node_light[] = {
&node_channel_node_light_translation_y,
&node_channel_node_light_translation_x,
&node_channel_node_light_translation_y,
};
node const node_node_light = {
@ -2899,12 +2899,12 @@ instance_light const instance_lights_node_pyramid001[] = {
};
channel const * const node_channels_node_pyramid001[] = {
&node_channel_node_pyramid001_rotationy_angle,
&node_channel_node_pyramid001_translation_z,
&node_channel_node_pyramid001_rotationx_angle,
&node_channel_node_pyramid001_translation_x,
&node_channel_node_pyramid001_rotationz_angle,
&node_channel_node_pyramid001_translation_y,
&node_channel_node_pyramid001_translation_x,
&node_channel_node_pyramid001_rotationx_angle,
&node_channel_node_pyramid001_rotationy_angle,
&node_channel_node_pyramid001_rotationz_angle,
};
node const node_node_pyramid001 = {
@ -2961,6 +2961,10 @@ collada::descriptor const descriptor = {
.images = images,
.images_count = (sizeof (images)) / (sizeof (images[0])),
.position_normal_texture_buffer = L"RES_SCENES_CURVE_INTERPOLATION_VTX",
.joint_weight_buffer = L"RES_SCENES_CURVE_INTERPOLATION_VJW",
.index_buffer = L"RES_SCENES_CURVE_INTERPOLATION_IDX",
};
}

View File

@ -242,12 +242,12 @@ transform const transforms_node_ship[] = {
instance_material const instance_geometry_instance_materials_node_ship_0[] = {
{
.element_index = 2, // an index into mesh.triangles
.material = &material_emissivetexture_material,
.element_index = 1, // an index into mesh.triangles
.material = &material_cyanengine_material,
.emission = { .input_set = 0 },
.emission = { .input_set = -1 },
.ambient = { .input_set = -1 },
.diffuse = { .input_set = 0 },
.diffuse = { .input_set = -1 },
.specular = { .input_set = -1 },
},
{
@ -260,12 +260,12 @@ instance_material const instance_geometry_instance_materials_node_ship_0[] = {
.specular = { .input_set = -1 },
},
{
.element_index = 1, // an index into mesh.triangles
.material = &material_cyanengine_material,
.element_index = 2, // an index into mesh.triangles
.material = &material_emissivetexture_material,
.emission = { .input_set = -1 },
.emission = { .input_set = 0 },
.ambient = { .input_set = -1 },
.diffuse = { .input_set = -1 },
.diffuse = { .input_set = 0 },
.specular = { .input_set = -1 },
},
};
@ -420,6 +420,10 @@ collada::descriptor const descriptor = {
.images = images,
.images_count = (sizeof (images)) / (sizeof (images[0])),
.position_normal_texture_buffer = L"RES_SCENES_SHIP20_VTX",
.joint_weight_buffer = L"RES_SCENES_SHIP20_VJW",
.index_buffer = L"RES_SCENES_SHIP20_IDX",
};
}