Skip to content

Commit

Permalink
[#82] ItemRender: Clone RenderState instead of reversing every previo…
Browse files Browse the repository at this point in the history
…us operation
  • Loading branch information
Danielxs01 committed May 10, 2023
1 parent 27790b6 commit 6fb1286
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,21 @@ private static void renderSignals(String itemId, Map<String, String> itemGroupSt
final OBJModel model = cache.get(objId);

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

RenderState iterationState = state.clone();

final ContentPackItem item = signalModel.getItem().get(ContentPackItemRenderType.DEFAULT);
final Vec3d translate = item.getAsVec3d(item::getTranslation);
final Vec3d scale = item.getAsVec3d(item::getScaling);
final Vec3d rotation = item.getAsVec3d(item::getRotation);

state.scale(scale);
state.translate(translate);
state.rotate(rotation.x, 1, 0, 0);
state.rotate(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(rotation.y, 0, 1, 0);
iterationState.rotate(rotation.z, 0, 0, 1);

try (OBJRender.Binding vbo = model.binder().texture(signalModel.getTextures()).bind(iterationState)) {
// Render
String[] groups = signalModel.getObj_groups();
if (groups.length == 0) {
Expand All @@ -238,11 +240,6 @@ private static void renderSignals(String itemId, Map<String, String> itemGroupSt

}

state.rotate(-rotation.z, 0,0, 1);
state.rotate(-rotation.y, 0, 1, 0);
state.rotate(-rotation.x, 1, 0, 0);
state.translate(translate.scale(-1.0));
state.scale(1 / scale.x, 1 / scale.y, 1 / scale.z);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ private static void renderBase(String itemId, RenderState state) {
OBJModel model = cache.get(objId);

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

RenderState iterationState = state.clone();

ContentPackItem item = baseModel.getItem().get(ContentPackItemRenderType.DEFAULT);
Vec3d translate = item.getAsVec3d(item::getTranslation);
Vec3d scale = item.getAsVec3d(item::getScaling);
Expand Down Expand Up @@ -126,11 +129,6 @@ private static void renderBase(String itemId, RenderState state) {

}

state.rotate(-rotation.z, 0,0, 1);
state.rotate(-rotation.y, 0, 1, 0);
state.rotate(-rotation.x, 1, 0, 0);
state.translate(translate.scale(-1.0));
state.scale(1 / scale.x, 1 / scale.y, 1 / scale.z);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,21 @@ private static void renderBase(String itemId, RenderState state) {
OBJModel model = cache.get(objId);

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

RenderState iterationState = state.clone();

ContentPackItem item = baseModel.getItem().get(ContentPackItemRenderType.DEFAULT);
Vec3d translate = item.getAsVec3d(item::getTranslation);
Vec3d scale = item.getAsVec3d(item::getScaling);
Vec3d rotation = item.getAsVec3d(item::getRotation);

state.scale(scale);
state.translate(translate);
state.rotate(rotation.x, 1, 0, 0);
state.rotate(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(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 All @@ -123,11 +126,6 @@ private static void renderBase(String itemId, RenderState state) {

}

state.rotate(-rotation.z, 0,0, 1);
state.rotate(-rotation.y, 0, 1, 0);
state.rotate(-rotation.x, 1, 0, 0);
state.translate(translate.scale(-1.0));
state.scale(1 / scale.x, 1 / scale.y, 1 / scale.z);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,21 @@ private static void renderBase(String itemId, RenderState state) {
OBJModel model = cache.get(objId);

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

RenderState iterationState = state.clone();

ContentPackItem item = baseModel.getItem().get(ContentPackItemRenderType.DEFAULT);
Vec3d translate = item.getAsVec3d(item::getTranslation);
Vec3d scale = item.getAsVec3d(item::getScaling);
Vec3d rotation = item.getAsVec3d(item::getRotation);

state.scale(scale);
state.translate(translate);
state.rotate(rotation.x, 1, 0, 0);
state.rotate(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(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 All @@ -128,12 +131,6 @@ private static void renderBase(String itemId, RenderState state) {

}

state.rotate(-rotation.z, 0,0, 1);
state.rotate(-rotation.y, 0, 1, 0);
state.rotate(-rotation.x, 1, 0, 0);
state.translate(translate.scale(-1.0));
state.scale(1 / scale.x, 1 / scale.y, 1 / scale.z);

}
}
}
Expand Down

0 comments on commit 6fb1286

Please sign in to comment.