Skip to content

Commit

Permalink
continuing layer implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rpereira committed Dec 1, 2017
1 parent e271021 commit 622bd0a
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ private final void updateHoveredBlock() {
if (modelInstance == null || modelLayer == null) {
return;
}


Entity entity = modelInstance.getEntity();
float s = modelLayer.getBlockSizeUnit();
ModelEditorCamera camera = (ModelEditorCamera) this.getCamera();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void onKeyPress(GuiEventKeyPress<GuiModelView> event) {
@Override
public void restoreState() {
model.setLayer(layerCopy);
model.mergeLayers();
model.requestMeshUpdate();
}
};

Expand All @@ -132,7 +132,8 @@ public void restoreState() {
this.oldStates.pop();
}
this.stackState(state);
modelLayer.requestLayerUpdate();
modelLayer.requestPlanesUpdate();
model.requestMeshUpdate();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private final void setBoneWeight() {
}
}
}
modelLayer.requestLayerUpdate();
modelLayer.requestPlanesUpdate();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ protected void onUpdate(double dt) {
EditableModel editableModel = new EditableModel(new JSONEditableModelInitializer(absolutePath));
try {
editableModel.initialize();
editableModel.regenerateLayers();
editableModel.mergeLayers();
editableModel.generate();
} catch (Exception e) {
Logger.get().log(Logger.Level.ERROR, "Error when parsing model", absolutePath);
e.printStackTrace(Logger.get().getPrintStream());
Expand Down Expand Up @@ -227,7 +226,7 @@ public final EditableModel getSelectedModel() {
}

public final GuiToolboxModel getModelToolbox() {
return (this.modelList == null ? (GuiToolboxModel) this.modelList.getPickedObject() : null);
return (this.modelList != null ? (GuiToolboxModel) this.modelList.getPickedObject() : null);
}

public final EditableModelLayer getSelectedModelLayer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public GuiToolboxModelPanel() {
/** get panel title */
public abstract String getTitle();

public final EditableModel getModel() {
public final EditableModel getSelectedModel() {
return (((GuiToolboxModel) this.getParent()).getModel());
}

public final ModelInstance getModelInstance() {
public final ModelInstance getSelectedModelInstance() {
return (((GuiToolboxModel) this.getParent()).getModelInstance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void invoke(GuiSpinnerEventPick<GuiSpinner> event) {
onAnimationPicked();
}
});
for (ModelSkeletonAnimation modelAnimation : this.getModel().getAnimations()) {
for (ModelSkeletonAnimation modelAnimation : this.getSelectedModel().getAnimations()) {
this.animations.add(modelAnimation, modelAnimation.getName());
}
this.animations.pick(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void invoke(GuiEventClick<GuiButton> event) {

this.layers.setHint("layers...");
this.layers.setBox(1 / 3.0f, 0.65f, 1 / 3.0f, 0.05f, 0);
for (EditableModelLayer layer : this.getModel().getRawLayers().values()) {
for (EditableModelLayer layer : this.getSelectedModel().getRawLayers().values()) {
this.layers.add(layer, layer.getName());
}
this.layers.pick(0);
Expand Down Expand Up @@ -134,7 +134,8 @@ public void invoke(GuiPromptEventHeldTextChanged<GuiPrompt> event) {
@Override
public void invoke(GuiEventClick<GuiButton> event) {
getSelectedModelLayer().translate(1, 0, 0);
getSelectedModelLayer().requestLayerUpdate();
getSelectedModelLayer().requestPlanesUpdate();
getSelectedModel().requestMeshUpdate();
}
});
this.addChild(this.tx);
Expand All @@ -147,7 +148,8 @@ public void invoke(GuiEventClick<GuiButton> event) {
@Override
public void invoke(GuiEventClick<GuiButton> event) {
getSelectedModelLayer().translate(0, 1, 0);
getSelectedModelLayer().requestLayerUpdate();
getSelectedModelLayer().requestPlanesUpdate();
getSelectedModel().requestMeshUpdate();
}
});
this.addChild(this.ty);
Expand All @@ -160,87 +162,94 @@ public void invoke(GuiEventClick<GuiButton> event) {
@Override
public void invoke(GuiEventClick<GuiButton> event) {
getSelectedModelLayer().translate(0, 0, 1);
getSelectedModelLayer().requestLayerUpdate();
getSelectedModelLayer().requestPlanesUpdate();
getSelectedModel().requestMeshUpdate();
}
});
this.addChild(this.tz);

// translate
this.txm.setText("-X");
this.txm.setBox(0.0f, 0.55f, w, 0.05f, 0.0f);
this.txm.setBox(0.0f, 0.50f, w, 0.05f, 0.0f);
this.txm.addTextParameter(new GuiTextParameterTextFillBox(0.75f));
this.txm.addTextParameter(new GuiTextParameterTextCenterBox());
this.txm.addListener(new GuiListener<GuiEventClick<GuiButton>>() {
@Override
public void invoke(GuiEventClick<GuiButton> event) {
getSelectedModelLayer().translate(-1, 0, 0);
getSelectedModelLayer().requestLayerUpdate();
getSelectedModelLayer().requestPlanesUpdate();
getSelectedModel().requestMeshUpdate();
}
});
this.addChild(this.txm);

this.tym.setText("-Y");
this.tym.setBox(w, 0.55f, w, 0.05f, 0.0f);
this.tym.setBox(w, 0.50f, w, 0.05f, 0.0f);
this.tym.addTextParameter(new GuiTextParameterTextFillBox(0.75f));
this.tym.addTextParameter(new GuiTextParameterTextCenterBox());
this.tym.addListener(new GuiListener<GuiEventClick<GuiButton>>() {
@Override
public void invoke(GuiEventClick<GuiButton> event) {
getSelectedModelLayer().translate(0, -1, 0);
getSelectedModelLayer().requestLayerUpdate();
getSelectedModelLayer().requestPlanesUpdate();
getSelectedModel().requestMeshUpdate();
}
});
this.addChild(this.tym);

this.tzm.setText("-Z");
this.tzm.setBox(2.0f * w, 0.55f, w, 0.05f, 0.0f);
this.tzm.setBox(2.0f * w, 0.50f, w, 0.05f, 0.0f);
this.tzm.addTextParameter(new GuiTextParameterTextFillBox(0.75f));
this.tzm.addTextParameter(new GuiTextParameterTextCenterBox());
this.tzm.addListener(new GuiListener<GuiEventClick<GuiButton>>() {
@Override
public void invoke(GuiEventClick<GuiButton> event) {
getSelectedModelLayer().translate(0, 0, -1);
getSelectedModelLayer().requestLayerUpdate();
getSelectedModelLayer().requestPlanesUpdate();
getSelectedModel().requestMeshUpdate();
}
});
this.addChild(this.tzm);

// rotate
this.rx.setText("RX");
this.rx.setBox(0.0f, 0.50f, w, 0.05f, 0.0f);
this.rx.setBox(0.0f, 0.45f, w, 0.05f, 0.0f);
this.rx.addTextParameter(new GuiTextParameterTextFillBox(0.75f));
this.rx.addTextParameter(new GuiTextParameterTextCenterBox());
this.rx.addListener(new GuiListener<GuiEventClick<GuiButton>>() {
@Override
public void invoke(GuiEventClick<GuiButton> event) {
getSelectedModelLayer().rotateX();
getSelectedModelLayer().requestLayerUpdate();
getSelectedModelLayer().requestPlanesUpdate();
getSelectedModel().requestMeshUpdate();
}
});
this.addChild(this.rx);

this.ry.setText("RY");
this.ry.setBox(w, 0.50f, w, 0.05f, 0.0f);
this.ry.setBox(w, 0.45f, w, 0.05f, 0.0f);
this.ry.addTextParameter(new GuiTextParameterTextFillBox(0.75f));
this.ry.addTextParameter(new GuiTextParameterTextCenterBox());
this.ry.addListener(new GuiListener<GuiEventClick<GuiButton>>() {
@Override
public void invoke(GuiEventClick<GuiButton> event) {
getSelectedModelLayer().rotateY();
getSelectedModelLayer().requestLayerUpdate();
getSelectedModelLayer().requestPlanesUpdate();
getSelectedModel().requestMeshUpdate();
}
});
this.addChild(this.ry);

this.rz.setText("RZ");
this.rz.setBox(2.0f * w, 0.50f, w, 0.05f, 0.0f);
this.rz.setBox(2.0f * w, 0.45f, w, 0.05f, 0.0f);
this.rz.addTextParameter(new GuiTextParameterTextFillBox(0.75f));
this.rz.addTextParameter(new GuiTextParameterTextCenterBox());
this.rz.addListener(new GuiListener<GuiEventClick<GuiButton>>() {
@Override
public void invoke(GuiEventClick<GuiButton> event) {
getSelectedModelLayer().rotateZ();
getSelectedModelLayer().requestLayerUpdate();
getSelectedModelLayer().requestPlanesUpdate();
getSelectedModel().requestMeshUpdate();
}
});
this.addChild(this.rz);
Expand Down Expand Up @@ -284,7 +293,7 @@ private final void onBlockSizeUnitChanged() {
return;
}
layer.setBlockSizeUnit(sizeUnit);
layer.requestLayerUpdate();
layer.requestPlanesUpdate();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void invoke(GuiEventClick<GuiButton> event) {
// (System.currentTimeMillis() % 10000) + "");
// getModelSkeleton().addBone(bone);
// refresh();
GuiWindowNewBone win = new GuiWindowNewBone(getModel());
GuiWindowNewBone win = new GuiWindowNewBone(getSelectedModel());
win.open(getOldestParent());
}
});
Expand Down Expand Up @@ -194,7 +194,7 @@ private final void onBonePicked() {
}

public final ModelSkeleton getModelSkeleton() {
return (this.getModel().getSkeleton());
return (this.getSelectedModel().getSkeleton());
}

private final Bone getSelectedBone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onInitialized(GuiRenderer guiRenderer) {

this.skins.setHint("Skins...");
this.skins.setBox(1 / 3.0f, 0.70f, 1 / 3.0f, 0.05f, 0);
for (ModelSkin skin : this.getModel().getSkins()) {
for (ModelSkin skin : this.getSelectedModel().getSkins()) {
this.skins.add(skin, skin.getName());
}
this.skins.pick(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class EditableModel extends Model {
/** blocks data : first key is the layer, value is the blocks data */
private HashMap<String, EditableModelLayer> blocksDataLayers;

private boolean meshUpToDate;

public EditableModel() {
this(null);
}
Expand Down Expand Up @@ -54,18 +56,26 @@ public final void setRawLayers(HashMap<String, EditableModelLayer> blockLayers)
@Override
public final void onBound() {
super.onBound();
boolean updated = false;
for (EditableModelLayer modelLayer : this.blocksDataLayers.values()) {
if (!modelLayer.isMeshUpToDate()) {
updated = true;
modelLayer.setMeshUpToDate();
this.modelMesher.generate(this, modelLayer);
}
if (!this.isMeshUpToDate()) {
this.setMeshUpToDate();
this.generate();
}
}

if (updated) {
this.mergeLayers();
}
public final void generate() {
this.modelMesher.generate(this);
}

private final void setMeshUpToDate() {
this.meshUpToDate = true;
}

private final boolean isMeshUpToDate() {
return (this.meshUpToDate);
}

public final void requestMeshUpdate() {
this.meshUpToDate = false;
}

/**
Expand All @@ -78,17 +88,4 @@ public final int getBlockDataCount() {
}
return (sum);
}

/** merge current set layers into a single final mesh */
public final void mergeLayers() {
this.modelMesher.mergeLayers(this);
}

/** regenerate each layers */
public final void regenerateLayers() {
for (EditableModelLayer modelLayer : this.blocksDataLayers.values()) {
modelLayer.setMeshUpToDate();
this.modelMesher.generate(this, modelLayer);
}
}
}
Loading

0 comments on commit 622bd0a

Please sign in to comment.