render instance controllers
This commit is contained in:
parent
fda7c28b2c
commit
a672190459
2
Makefile
2
Makefile
@ -79,8 +79,6 @@ src/scenes/%.cpp: scenes/%.DAE include/scenes/%.hpp
|
|||||||
@mkdir -p $(@D)
|
@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=.idx) $(<:.DAE=.vjw) rc/$(notdir $(<:.DAE=.rc)) $(notdir $(<:.DAE=.mk))
|
||||||
|
|
||||||
# $(BUILD_TYPE)/curve_interpolation.res \
|
|
||||||
|
|
||||||
OBJS = \
|
OBJS = \
|
||||||
$(BUILD_TYPE)/main.res \
|
$(BUILD_TYPE)/main.res \
|
||||||
$(BUILD_TYPE)/robot_player.obj \
|
$(BUILD_TYPE)/robot_player.obj \
|
||||||
|
|||||||
@ -933,6 +933,7 @@ def render_controller(state, collada, controller):
|
|||||||
assert type(controller.control_element) == types.Skin
|
assert type(controller.control_element) == types.Skin
|
||||||
skin = controller.control_element
|
skin = controller.control_element
|
||||||
geometry = collada.lookup(skin.source, types.Geometry)
|
geometry = collada.lookup(skin.source, types.Geometry)
|
||||||
|
geometry_name = sanitize_name(state, geometry.id, geometry)
|
||||||
vertex_index_table = state.geometry__vertex_index_tables[geometry.id]
|
vertex_index_table = state.geometry__vertex_index_tables[geometry.id]
|
||||||
# this is a special index buffer that contains mixed floats/ints,
|
# this is a special index buffer that contains mixed floats/ints,
|
||||||
# and needs to be packed accordingly
|
# and needs to be packed accordingly
|
||||||
@ -948,6 +949,8 @@ def render_controller(state, collada, controller):
|
|||||||
|
|
||||||
yield f"controller const controller_{controller_name} = {{"
|
yield f"controller const controller_{controller_name} = {{"
|
||||||
yield ".skin = {"
|
yield ".skin = {"
|
||||||
|
yield f".geometry = &geometry_{geometry_name},"
|
||||||
|
yield ""
|
||||||
yield f".inverse_bind_matrices = inverse_bind_matrices_{controller_name},"
|
yield f".inverse_bind_matrices = inverse_bind_matrices_{controller_name},"
|
||||||
yield ""
|
yield ""
|
||||||
yield f".vertex_buffer_offset = {vertex_buffer_offset},"
|
yield f".vertex_buffer_offset = {vertex_buffer_offset},"
|
||||||
|
|||||||
@ -65,8 +65,13 @@ namespace collada_scene {
|
|||||||
node_instance const& node_instance,
|
node_instance const& node_instance,
|
||||||
int light_index);
|
int light_index);
|
||||||
|
|
||||||
void render_geometries(collada::instance_geometry const * const instance_geometries,
|
void render_geometry(collada::geometry const& geometry,
|
||||||
int const instance_geometries_count);
|
collada::instance_material const * const instance_materials,
|
||||||
|
int const instance_materials_count);
|
||||||
|
void render_instance_geometries(collada::instance_geometry const * const instance_geometries,
|
||||||
|
int const instance_geometries_count);
|
||||||
|
void render_instance_controllers(collada::instance_controller const * const instance_controllers,
|
||||||
|
int const instance_controllers_count);
|
||||||
void set_material(collada::effect const& effect);
|
void set_material(collada::effect const& effect);
|
||||||
void set_color_or_texture(collada::color_or_texture const& color_or_texture,
|
void set_color_or_texture(collada::color_or_texture const& color_or_texture,
|
||||||
ID3D10EffectVectorVariable * pVectorVariable,
|
ID3D10EffectVectorVariable * pVectorVariable,
|
||||||
|
|||||||
@ -258,6 +258,8 @@ namespace collada {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct skin {
|
struct skin {
|
||||||
|
geometry const * const geometry; // source
|
||||||
|
|
||||||
matrix const * const inverse_bind_matrices; // one per joint
|
matrix const * const inverse_bind_matrices; // one per joint
|
||||||
|
|
||||||
int const vertex_buffer_offset;
|
int const vertex_buffer_offset;
|
||||||
@ -271,7 +273,7 @@ namespace collada {
|
|||||||
struct instance_controller {
|
struct instance_controller {
|
||||||
controller const * const controller;
|
controller const * const controller;
|
||||||
|
|
||||||
//node const * const skeleton;
|
//node const * const skeleton; // a reference to the root of the joint heirarchy
|
||||||
|
|
||||||
int const * const joint_node_indices; // one per joint
|
int const * const joint_node_indices; // one per joint
|
||||||
int const joint_count;
|
int const joint_count;
|
||||||
|
|||||||
@ -14,4 +14,3 @@ RES_COLLADA_SCENE_FXO RCDATA "collada_scene.fxo"
|
|||||||
RES_MODELS_CURVE_INTERPOLATION_VTX RCDATA "scenes/curve_interpolation/curve_interpolation.vtx"
|
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_IDX RCDATA "scenes/curve_interpolation/curve_interpolation.idx"
|
||||||
RES_MODELS_CURVE_INTERPOLATION_VJW RCDATA "scenes/curve_interpolation/curve_interpolation.vjw"
|
RES_MODELS_CURVE_INTERPOLATION_VJW RCDATA "scenes/curve_interpolation/curve_interpolation.vjw"
|
||||||
|
|
||||||
@ -422,37 +422,61 @@ namespace collada_scene {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scene_state::render_geometries(instance_geometry const * const instance_geometries,
|
void scene_state::render_geometry(geometry const& geometry,
|
||||||
int const instance_geometries_count)
|
instance_material const * const instance_materials,
|
||||||
|
int const instance_materials_count)
|
||||||
|
{
|
||||||
|
mesh const& mesh = geometry.mesh;
|
||||||
|
|
||||||
|
UINT strides[1] = { 3 * 3 * 4 };
|
||||||
|
UINT offsets[1] = { (UINT)mesh.vertex_buffer_offset };
|
||||||
|
g_pd3dDevice->IASetVertexBuffers(0, m_numBuffers, m_pVertexBuffers, strides, offsets);
|
||||||
|
g_pd3dDevice->IASetIndexBuffer(m_pIndexBuffer, DXGI_FORMAT_R32_UINT, mesh.index_buffer_offset);
|
||||||
|
|
||||||
|
D3D10_TECHNIQUE_DESC techDesc;
|
||||||
|
g_pTechniqueBlinn->GetDesc(&techDesc);
|
||||||
|
|
||||||
|
for (int j = 0; j < instance_materials_count; j++) {
|
||||||
|
instance_material const& instance_material = instance_materials[j];
|
||||||
|
triangles const& triangles = mesh.triangles[instance_material.element_index];
|
||||||
|
set_material(*instance_material.material->effect);
|
||||||
|
int texture_channels[4] = {
|
||||||
|
instance_material.emission.input_set,
|
||||||
|
instance_material.ambient.input_set,
|
||||||
|
instance_material.diffuse.input_set,
|
||||||
|
instance_material.specular.input_set,
|
||||||
|
};
|
||||||
|
g_pTextureChannelVariable->SetIntVector(texture_channels);
|
||||||
|
|
||||||
|
g_pTechniqueBlinn->GetPassByIndex(0)->Apply(0);
|
||||||
|
g_pd3dDevice->IASetInputLayout(m_pVertexLayouts[triangles.inputs_index]);
|
||||||
|
g_pd3dDevice->DrawIndexed(triangles.count * 3, triangles.index_offset, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void scene_state::render_instance_geometries(instance_geometry const * const instance_geometries,
|
||||||
|
int const instance_geometries_count)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < instance_geometries_count; i++) {
|
for (int i = 0; i < instance_geometries_count; i++) {
|
||||||
instance_geometry const &instance_geometry = instance_geometries[i];
|
instance_geometry const &instance_geometry = instance_geometries[i];
|
||||||
mesh const& mesh = instance_geometry.geometry->mesh;
|
geometry const& geometry = *instance_geometry.geometry;
|
||||||
|
|
||||||
UINT strides[1] = { 3 * 3 * 4 };
|
render_geometry(geometry,
|
||||||
UINT offsets[1] = { (UINT)mesh.vertex_buffer_offset };
|
instance_geometry.instance_materials,
|
||||||
g_pd3dDevice->IASetVertexBuffers(0, m_numBuffers, m_pVertexBuffers, strides, offsets);
|
instance_geometry.instance_materials_count);
|
||||||
g_pd3dDevice->IASetIndexBuffer(m_pIndexBuffer, DXGI_FORMAT_R32_UINT, mesh.index_buffer_offset);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
D3D10_TECHNIQUE_DESC techDesc;
|
void scene_state::render_instance_controllers(instance_controller const * const instance_controllers,
|
||||||
g_pTechniqueBlinn->GetDesc(&techDesc);
|
int const instance_controllers_count)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < instance_controllers_count; i++) {
|
||||||
|
instance_controller const &instance_controller = instance_controllers[i];
|
||||||
|
geometry const& geometry = *instance_controller.controller->skin.geometry;
|
||||||
|
|
||||||
for (int j = 0; j < instance_geometry.instance_materials_count; j++) {
|
render_geometry(geometry,
|
||||||
instance_material const& instance_material = instance_geometry.instance_materials[j];
|
instance_controller.instance_materials,
|
||||||
triangles const& triangles = mesh.triangles[instance_material.element_index];
|
instance_controller.instance_materials_count);
|
||||||
set_material(*instance_material.material->effect);
|
|
||||||
int texture_channels[4] = {
|
|
||||||
instance_material.emission.input_set,
|
|
||||||
instance_material.ambient.input_set,
|
|
||||||
instance_material.diffuse.input_set,
|
|
||||||
instance_material.specular.input_set,
|
|
||||||
};
|
|
||||||
g_pTextureChannelVariable->SetIntVector(texture_channels);
|
|
||||||
|
|
||||||
g_pTechniqueBlinn->GetPassByIndex(0)->Apply(0);
|
|
||||||
g_pd3dDevice->IASetInputLayout(m_pVertexLayouts[triangles.inputs_index]);
|
|
||||||
g_pd3dDevice->DrawIndexed(triangles.count * 3, triangles.index_offset, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -728,7 +752,8 @@ namespace collada_scene {
|
|||||||
|
|
||||||
g_pWorldVariable->SetMatrix((float *)&node_instance.world);
|
g_pWorldVariable->SetMatrix((float *)&node_instance.world);
|
||||||
|
|
||||||
render_geometries(node.instance_geometries, node.instance_geometries_count);
|
render_instance_geometries(node.instance_geometries, node.instance_geometries_count);
|
||||||
|
render_instance_controllers(node.instance_controllers, node.instance_controllers_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1592,6 +1592,8 @@ matrix const inverse_bind_matrices_geom_box001_skin1[] = {
|
|||||||
|
|
||||||
controller const controller_geom_box001_skin1 = {
|
controller const controller_geom_box001_skin1 = {
|
||||||
.skin = {
|
.skin = {
|
||||||
|
.geometry = &geometry_geom_box001,
|
||||||
|
|
||||||
.inverse_bind_matrices = inverse_bind_matrices_geom_box001_skin1,
|
.inverse_bind_matrices = inverse_bind_matrices_geom_box001_skin1,
|
||||||
|
|
||||||
.vertex_buffer_offset = 0,
|
.vertex_buffer_offset = 0,
|
||||||
@ -1993,8 +1995,8 @@ instance_light const instance_lights_node_geosphere[] = {
|
|||||||
|
|
||||||
channel const * const node_channels_node_geosphere[] = {
|
channel const * const node_channels_node_geosphere[] = {
|
||||||
&node_channel_node_geosphere_scale,
|
&node_channel_node_geosphere_scale,
|
||||||
&node_channel_node_geosphere_scaleaxisrotation,
|
|
||||||
&node_channel_node_geosphere_inversescaleaxisrotation,
|
&node_channel_node_geosphere_inversescaleaxisrotation,
|
||||||
|
&node_channel_node_geosphere_scaleaxisrotation,
|
||||||
};
|
};
|
||||||
|
|
||||||
node const node_node_geosphere = {
|
node const node_node_geosphere = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user