Skip to content

Commit

Permalink
[#82] BlockRender: Cloning RenderState to fix issues with multiple mo…
Browse files Browse the repository at this point in the history
…dels
  • Loading branch information
Danielxs01 committed May 10, 2023
1 parent 88fdce8 commit c7e7917
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,20 @@ private static void renderBase(String blockId, TileComplexSignal tile, RenderSta
final OBJModel model = cache.get(objId);

for (ContentPackModel baseModel : baseModels.getValue()) {

RenderState iterationState = state.clone();

final ContentPackBlock block = baseModel.getBlock();
final Vec3d translate = block.getAsVec3d(block::getTranslation).add(offset);
final Vec3d scale = block.getAsVec3d(block::getScaling);
final Vec3d rotation = block.getAsVec3d(block::getRotation);

state.scale(scale);
state.translate(translate);
state.rotate(rotation.x,1, 0, 0);
state.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0);
state.rotate(rotation.z, 0, 0, 1);
try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(state)) {
iterationState.scale(scale);
iterationState.translate(translate);
iterationState.rotate(rotation.x,1, 0, 0);
iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0);
iterationState.rotate(rotation.z, 0, 0, 1);
try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) {

// Render
String[] groups = baseModel.getObj_groups();
Expand Down Expand Up @@ -181,17 +184,20 @@ private static void renderSignals(final String blockId, final TileComplexSignal
final OBJModel model = cache.get(objId);

for (ContentPackModel signalModel : signalModels.getValue()) {

RenderState iterationState = state.clone();

ContentPackBlock block = signalModel.getBlock();
final Vec3d translate = block.getAsVec3d(block::getTranslation).add(offset);
final Vec3d scale = block.getAsVec3d(block::getScaling);
final Vec3d rotation = block.getAsVec3d(block::getRotation);

state.scale(scale);
state.translate(translate);
state.rotate(rotation.x,1, 0, 0);
state.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0);
state.rotate(rotation.z, 0, 0, 1);
try (OBJRender.Binding vbo = model.binder().texture(signalModel.getTextures()).bind(state)) {
iterationState.scale(scale);
iterationState.translate(translate);
iterationState.rotate(rotation.x,1, 0, 0);
iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0);
iterationState.rotate(rotation.z, 0, 0, 1);
try (OBJRender.Binding vbo = model.binder().texture(signalModel.getTextures()).bind(iterationState)) {

String[] groups = signalModel.getObj_groups();

Expand All @@ -213,7 +219,6 @@ private static void renderSignals(final String blockId, final TileComplexSignal

}


}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,21 @@ private static void renderBase(String blockId, TileDeco tile, RenderState state)
OBJModel model = cache.get(objId);

for (ContentPackModel baseModel : baseModels.getValue()) {

RenderState iterationState = state.clone();

ContentPackBlock block = baseModel.getBlock();
Vec3d translate = block.getAsVec3d(block::getTranslation);
Vec3d scale = block.getAsVec3d(block::getScaling);
Vec3d rotation = block.getAsVec3d(block::getRotation);

state.scale(scale);
state.translate(translate);
state.rotate(rotation.x,1, 0, 0);
state.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0);
state.rotate(rotation.z, 0, 0, 1);
iterationState.scale(scale);
iterationState.translate(translate);
iterationState.rotate(rotation.x,1, 0, 0);
iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0);
iterationState.rotate(rotation.z, 0, 0, 1);

try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(state)) {
try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) {

// Render
String[] groups = baseModel.getObj_groups();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,21 @@ private static void renderBase(String blockId, TileSignPart tile, RenderState st
OBJModel model = cache.get(objId);

for (ContentPackModel baseModel : baseModels.getValue()) {

RenderState iterationState = state.clone();

ContentPackBlock block = baseModel.getBlock();
Vec3d translate = block.getAsVec3d(block::getTranslation);
Vec3d scale = block.getAsVec3d(block::getScaling);
Vec3d rotation = block.getAsVec3d(block::getRotation);

state.scale(scale);
state.translate(translate);
state.rotate(rotation.x, 1, 0, 0);
state.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0);
state.rotate(rotation.z, 0, 0, 1);
iterationState.scale(scale);
iterationState.translate(translate);
iterationState.rotate(rotation.x, 1, 0, 0);
iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0);
iterationState.rotate(rotation.z, 0, 0, 1);

try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(state)) {
try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) {

// Render
String[] groups = baseModel.getObj_groups();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,21 @@ private static void renderBase(final String blockId, final TileSignalBox tile, R
final OBJModel model = cache.get(objId);

for (ContentPackModel baseModel : baseModels.getValue()) {

RenderState iterationState = state.clone();

final ContentPackBlock block = baseModel.getBlock();
final Vec3d translate = block.getAsVec3d(block::getTranslation);
final Vec3d scale = block.getAsVec3d(block::getScaling);
final Vec3d rotation = block.getAsVec3d(block::getRotation);

state.scale(scale);
state.translate(translate);
state.rotate(rotation.x,1, 0, 0);
state.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0);
state.rotate(rotation.z, 0, 0, 1);
iterationState.scale(scale);
iterationState.translate(translate);
iterationState.rotate(rotation.x,1, 0, 0);
iterationState.rotate(tile.getBlockRotate() + rotation.y, 0, 1, 0);
iterationState.rotate(rotation.z, 0, 0, 1);

try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(state)) {
try (OBJRender.Binding vbo = model.binder().texture(baseModel.getTextures()).bind(iterationState)) {

// Render
String[] groups = baseModel.getObj_groups();
Expand Down

0 comments on commit c7e7917

Please sign in to comment.