Skip to content

Commit

Permalink
model export / import
Browse files Browse the repository at this point in the history
  • Loading branch information
rpereira committed Nov 27, 2017
1 parent 28dd092 commit 7840744
Show file tree
Hide file tree
Showing 18 changed files with 303 additions and 93 deletions.
Binary file modified POT/assets.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion POT/src/com/pot/client/renderer/model/POTModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class POTModels implements IModResource {

@Override
public void load(Mod mod, ResourceManager manager) {
registerJSONModel(manager, R.getResPath(ModPOT.MOD_ID, "models/physicTest/"), EntityBipedTest.class);
registerJSONModel(manager, R.getResPath(ModPOT.MOD_ID, "models/physicTest2/"), EntityBipedTest.class);
registerJSONModel(manager, R.getResPath(ModPOT.MOD_ID, "models/animTest/"), EntityTest.class);
}

Expand Down
Binary file modified VoxelEngine/assets.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ public static byte[] getImagePixels(BufferedImage img) {
* @param atlas
*/
public static void exportPNGImage(String filepath, BufferedImage image) {
exportPNGImage(new File(filepath), image);
}

public static void exportPNGImage(File file, BufferedImage image) {
try {
File file = new File(filepath);
if (!file.exists()) {
file.mkdirs();
file.createNewFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import com.grillecube.client.renderer.gui.GuiRenderer;
import com.grillecube.client.renderer.gui.event.GuiEventAspectRatio;
import com.grillecube.client.renderer.gui.event.GuiListener;
import com.grillecube.client.renderer.world.WorldRenderer;
import com.grillecube.client.renderer.world.flat.WorldFlatRenderer;
import com.grillecube.common.world.WorldFlat;

public class GuiViewWorld extends GuiView {

private GuiTexture txWorld;
private WorldRenderer<WorldFlat> worldRenderer;
private WorldFlatRenderer worldRenderer;
private CameraProjective camera;
private int worldID;

Expand Down Expand Up @@ -84,7 +82,7 @@ protected void onUpdate() {
this.worldRenderer.getCamera().setAspect(aspect);
}

public final WorldRenderer<WorldFlat> getWorldRenderer() {
public final WorldFlatRenderer getWorldRenderer() {
return (this.worldRenderer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ public final Bone getBone(String boneName) {
return (this.bonesMap.get(boneName));
}

/** get a bone by it id */
public final Bone getBone(int boneID) {
return (boneID < 0 || boneID >= this.bonesList.size() ? null : this.bonesList.get(boneID));
}

/** get a bone by it id */
public final String getBoneName(int boneID) {
Bone bone = this.getBone(boneID);
return (bone == null ? null : bone.getName());
}

/** remove a bone */
public final void removeBone(Bone bone) {
this.bonesMap.remove(bone.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Bone {
private final Matrix4f localBindTransform;
private final Matrix4f inverseBindTransform;
private final Vector3f translate;
private final Vector3f rotate;
private final Quaternion rotate;

/**
* @param ModelSkeleton
Expand All @@ -43,7 +43,7 @@ public Bone(ModelSkeleton modelSkeleton, String name) {
this.localBindTransform = new Matrix4f();
this.inverseBindTransform = new Matrix4f();
this.translate = new Vector3f();
this.rotate = new Vector3f(0.0f, 0.0f, 0.0f);
this.rotate = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
}

/** get the joint name */
Expand All @@ -69,10 +69,15 @@ public String addChild(String child) {
}

/** return true if this joint has a children */
public boolean hasChildren() {
public final boolean hasChildren() {
return (this.childrenNames != null && this.childrenNames.size() > 0);
}

/** return true if this joint has a parent */
public final boolean hasParent() {
return (this.parentName != null);
}

/** remove a child of this joint */
public void removeChild(String childName) {
this.childrenNames.remove(childName);
Expand Down Expand Up @@ -112,15 +117,16 @@ public final void setLocalBindTransform(Matrix4f setLocalBindTransform) {

public final void setLocalBindTransform(float x, float y, float z, float rx, float ry, float rz, float rw) {
this.translate.set(x, y, z);
Quaternion.toEulerAngle(this.rotate, rx, ry, rz, rw);
this.rotate.set(rx, ry, rz, rw);
Vector3f rot = Quaternion.toEulerAngle(rx, ry, rz, rw);

this.localBindTransform.setIdentity();
this.localBindTransform.translate(x, y, z);
this.localBindTransform.rotateXYZ(this.rotate);
this.localBindTransform.rotateXYZ(rot);
this.localBindTransform.translate(this.translate);
}

public final Vector3f getLocalRotation() {
public final Quaternion getLocalRotation() {
return (this.rotate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.grillecube.client.renderer.model.editor.gui.GuiModelEditor;
import com.grillecube.client.renderer.model.editor.gui.GuiModelView;
import com.grillecube.client.renderer.model.editor.gui.toolbox.GuiToolbox;
import com.grillecube.client.renderer.model.json.JSONModelExporter;
import com.grillecube.common.Logger;
import com.grillecube.common.resources.R;

public class ModelEditor {

Expand Down Expand Up @@ -40,7 +43,15 @@ private void run() {
try {
engine.loop();
} catch (InterruptedException e) {
e.printStackTrace();
Logger.get().log(Logger.Level.ERROR, "That's unfortunate... VoxelEngine crashed.", e.getLocalizedMessage());
String path = R.getResPath("models/tmp/" + System.currentTimeMillis());
try {
Logger.get().log(Logger.Level.ERROR, "Trying to save model...", path);
JSONModelExporter.export(guiModelEditor.getSelectedModel(), path);
} catch (Exception exception) {
Logger.get().log(Logger.Level.ERROR, "Couldn't save model... sorry bro",
exception.getLocalizedMessage());
}
}
engine.deinitialize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ private final void updateSelection() {
Vector3i o1 = BlockRenderer.VERTICES[BlockRenderer.FACES_VERTICES[face.getID()][1]];
Vector3i o2 = BlockRenderer.VERTICES[BlockRenderer.FACES_VERTICES[face.getID()][2]];
Vector3i o3 = BlockRenderer.VERTICES[BlockRenderer.FACES_VERTICES[face.getID()][3]];
this.quad[0].set(this.getX() + this.getWidth() * o0.x, this.getY() + this.getHeight() * o0.y,
this.getZ() + this.getDepth() * o0.z);
this.quad[1].set(this.getX() + this.getWidth() * o1.x, this.getY() + this.getHeight() * o1.y,
this.getZ() + this.getDepth() * o1.z);
this.quad[2].set(this.getX() + this.getWidth() * o2.x, this.getY() + this.getHeight() * o2.y,
this.getZ() + this.getDepth() * o2.z);
this.quad[3].set(this.getX() + this.getWidth() * o3.x, this.getY() + this.getHeight() * o3.y,
this.getZ() + this.getDepth() * o3.z);
this.quad[0].set(this.getPositionX() + this.getSizeX() * o0.x, this.getPositionY() + this.getSizeY() * o0.y,
this.getPositionZ() + this.getSizeZ() * o0.z);
this.quad[1].set(this.getPositionX() + this.getSizeX() * o1.x, this.getPositionY() + this.getSizeY() * o1.y,
this.getPositionZ() + this.getSizeZ() * o1.z);
this.quad[2].set(this.getPositionX() + this.getSizeX() * o2.x, this.getPositionY() + this.getSizeY() * o2.y,
this.getPositionZ() + this.getSizeZ() * o2.z);
this.quad[3].set(this.getPositionX() + this.getSizeX() * o3.x, this.getPositionY() + this.getSizeY() * o3.y,
this.getPositionZ() + this.getSizeZ() * o3.z);

LineRendererFactory factory = super.guiModelView.getWorldRenderer().getLineRendererFactory();
for (Line line : this.lines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ private final void updateSelection() {
Vector3i o1 = BlockRenderer.VERTICES[BlockRenderer.FACES_VERTICES[face.getID()][1]];
Vector3i o2 = BlockRenderer.VERTICES[BlockRenderer.FACES_VERTICES[face.getID()][2]];
Vector3i o3 = BlockRenderer.VERTICES[BlockRenderer.FACES_VERTICES[face.getID()][3]];
this.quad[0].set(this.getX() + this.getWidth() * o0.x, this.getY() + this.getHeight() * o0.y,
this.getZ() + this.getDepth() * o0.z);
this.quad[1].set(this.getX() + this.getWidth() * o1.x, this.getY() + this.getHeight() * o1.y,
this.getZ() + this.getDepth() * o1.z);
this.quad[2].set(this.getX() + this.getWidth() * o2.x, this.getY() + this.getHeight() * o2.y,
this.getZ() + this.getDepth() * o2.z);
this.quad[3].set(this.getX() + this.getWidth() * o3.x, this.getY() + this.getHeight() * o3.y,
this.getZ() + this.getDepth() * o3.z);
this.quad[0].set(this.getPositionX() + this.getSizeX() * o0.x, this.getPositionY() + this.getSizeY() * o0.y,
this.getPositionZ() + this.getSizeZ() * o0.z);
this.quad[1].set(this.getPositionX() + this.getSizeX() * o1.x, this.getPositionY() + this.getSizeY() * o1.y,
this.getPositionZ() + this.getSizeZ() * o1.z);
this.quad[2].set(this.getPositionX() + this.getSizeX() * o2.x, this.getPositionY() + this.getSizeY() * o2.y,
this.getPositionZ() + this.getSizeZ() * o2.z);
this.quad[3].set(this.getPositionX() + this.getSizeX() * o3.x, this.getPositionY() + this.getSizeY() * o3.y,
this.getPositionZ() + this.getSizeZ() * o3.z);

LineRendererFactory factory = super.guiModelView.getWorldRenderer().getLineRendererFactory();
for (Line line : this.lines) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.grillecube.client.renderer.model.editor.gui.toolbox;

import java.io.IOException;

import com.grillecube.client.renderer.gui.components.Gui;
import com.grillecube.client.renderer.gui.components.GuiButton;
import com.grillecube.client.renderer.gui.components.GuiColoredQuad;
Expand All @@ -17,6 +19,7 @@
import com.grillecube.client.renderer.model.editor.mesher.EditableModel;
import com.grillecube.client.renderer.model.instance.ModelInstance;
import com.grillecube.client.renderer.model.json.JSONEditableModelInitializer;
import com.grillecube.client.renderer.model.json.JSONModelExporter;
import com.grillecube.common.Logger;
import com.grillecube.common.resources.R;
import com.grillecube.common.utils.Color;
Expand Down Expand Up @@ -115,7 +118,13 @@ public void invoke(GuiSpinnerEventPick<GuiSpinnerEditor> event) {
}

private final void saveCurrentModel() {
// TODO
try {
String path = R.getResPath("models/" + System.currentTimeMillis());
JSONModelExporter.export(this.getSelectedModel(), path);
Logger.get().log(Logger.Level.FINE, "model saved properly at", path);
} catch (Exception e) {
Logger.get().log(Logger.Level.ERROR, "error when exporting model", e.getMessage());
}
}

private final void createNewModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class GuiToolboxModel extends GuiView {
public GuiToolboxModel(ModelInstance modelInstance) {
super();

this.setHoverable(false);

this.modelInstance = modelInstance;

GuiParameter<GuiText> center = new GuiTextParameterTextCenterBox();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.grillecube.client.renderer.model.editor.gui.GuiPromptEditor;
import com.grillecube.client.renderer.model.editor.gui.GuiSpinnerEditor;
import com.grillecube.common.maths.Matrix4f;
import com.grillecube.common.maths.Quaternion;
import com.grillecube.common.maths.Vector3f;

public class GuiToolboxModelPanelSkeleton extends GuiToolboxModelPanel {
Expand Down Expand Up @@ -131,7 +132,7 @@ public void invoke(GuiEventClick<GuiButton> event) {
this.posY.getPrompt().setHeldText(String.valueOf(bone.getLocalTranslation().y));
this.posZ.getPrompt().setHeldText(String.valueOf(bone.getLocalTranslation().z));

Vector3f rot = bone.getLocalRotation();
Vector3f rot = Quaternion.toEulerAngle(bone.getLocalRotation());
this.rotX.getPrompt().setHeldText(String.valueOf(rot.x));
this.rotY.getPrompt().setHeldText(String.valueOf(rot.y));
this.rotZ.getPrompt().setHeldText(String.valueOf(rot.z));
Expand All @@ -145,11 +146,14 @@ public void invoke(GuiPromptEventHeldTextChanged<GuiPrompt> event) {
float ry = rotY.getPrompt().asFloat(0.0f);
float rz = rotZ.getPrompt().asFloat(0.0f);
localBindTransform.rotateXYZ(rx, ry, rz);
Quaternion q = Quaternion.toQuaternion(rx, ry, rz);
getSelectedBone().getLocalRotation().set(q);

float x = posX.getPrompt().asFloat(0.0f);
float y = posY.getPrompt().asFloat(0.0f);
float z = posZ.getPrompt().asFloat(0.0f);
System.out.println(x + " : " + y + " : " + z);
localBindTransform.translate(-x, -y, -z);
getSelectedBone().getLocalTranslation().set(x, y, z);
getSelectedBone().setLocalBindTransform(localBindTransform);
getSelectedBone().calcInverseBindTransform();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public final void doGenerate(EditableModel editableModel, Stack<ModelMeshVertex>
/** generate the model mesh */
private final void generateMeshAndSkin(EditableModel editableModel, ArrayList<ModelPlane> planes,
Stack<ModelMeshVertex> vertices, Stack<Short> indices, HashMap<ModelSkin, BufferedImage> skinsData) {
boolean[] ba = new boolean[] { false, false, false, false, false, false };
ModelSkinPacker.fit(planes);
int txWidth = 0, txHeight = 0;

Expand Down
Loading

0 comments on commit 7840744

Please sign in to comment.