use of mchorse.blockbuster.api.ModelTransform in project blockbuster by mchorse.
the class ModelLazyLoaderVOX method generateVOXModel.
/**
* Generate custom model based on given VOX
*/
private Model generateVOXModel(String model) throws Exception {
/* Generate custom model for a VOX model */
Model data = new Model();
ModelPose blocky = new ModelPose();
/* Generate limbs */
VoxDocument document = this.getVox();
for (VoxDocument.LimbNode node : document.generate()) {
ModelLimb limb = data.addLimb(node.name);
ModelTransform transform = new ModelTransform();
limb.origin[0] = 0;
limb.origin[1] = 0;
limb.origin[2] = 0;
transform.translate[0] = -node.translation.x;
transform.translate[1] = node.translation.z;
transform.translate[2] = -node.translation.y;
blocky.limbs.put(limb.name, transform);
}
/* General model properties */
data.providesObj = true;
data.providesMtl = true;
blocky.setSize(1, 1, 1);
data.poses.put("flying", blocky.copy());
data.poses.put("standing", blocky.copy());
data.poses.put("sneaking", blocky.copy());
data.poses.put("sleeping", blocky.copy());
data.poses.put("riding", blocky.copy());
data.name = model;
return data;
}
use of mchorse.blockbuster.api.ModelTransform in project blockbuster by mchorse.
the class StructureMorph method render.
@Override
@SideOnly(Side.CLIENT)
public void render(EntityLivingBase entity, double x, double y, double z, float entityYaw, float partialTicks) {
StructureRenderer renderer = STRUCTURES.get(this.structure);
if (renderer != null) {
if (renderer.status != StructureStatus.LOADED) {
if (renderer.status == StructureStatus.UNLOADED) {
renderer.status = StructureStatus.LOADING;
Dispatcher.sendToServer(new PacketStructureRequest(this.structure));
}
return;
}
float lastX = OpenGlHelper.lastBrightnessX;
float lastY = OpenGlHelper.lastBrightnessY;
if (GuiModelRenderer.isRendering() && !this.lighting) {
Minecraft.getMinecraft().entityRenderer.enableLightmap();
}
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
/* These states are important to enable */
GlStateManager.pushMatrix();
GlStateManager.enableRescaleNormal();
GlStateManager.translate(x, y, z);
ModelTransform transform = this.pose;
float anchorX = this.anchorX;
float anchorY = this.anchorY;
float anchorZ = this.anchorZ;
if (this.animation.isInProgress()) {
transform = new ModelTransform();
transform.copy(this.pose);
this.animation.apply(transform, partialTicks);
if (this.animation.lastAnchorX != null) {
float factor = this.animation.getFactor(partialTicks);
anchorX = this.animation.interp.interpolate(this.animation.lastAnchorX, anchorX, factor);
anchorY = this.animation.interp.interpolate(this.animation.lastAnchorY, anchorY, factor);
anchorZ = this.animation.interp.interpolate(this.animation.lastAnchorZ, anchorZ, factor);
}
}
transform.transform();
GlStateManager.translate(anchorX, anchorY, anchorZ);
RenderHelper.disableStandardItemLighting();
GlStateManager.shadeModel(GL11.GL_SMOOTH);
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
renderer.render(this);
GlStateManager.disableBlend();
GlStateManager.disableAlpha();
GlStateManager.shadeModel(GL11.GL_FLAT);
GlStateManager.enableLighting();
GlStateManager.enableLight(0);
GlStateManager.enableLight(1);
GlStateManager.enableColorMaterial();
GL11.glColor4f(1, 1, 1, 1);
renderer.renderTEs(this);
GlStateManager.popMatrix();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lastX, lastY);
if (GuiModelRenderer.isRendering() && !this.lighting) {
Minecraft.getMinecraft().entityRenderer.disableLightmap();
}
}
}
use of mchorse.blockbuster.api.ModelTransform in project blockbuster by mchorse.
the class ModelCustom method applyLimbPose.
/**
* Apply transform from current pose on given limb
*/
public void applyLimbPose(ModelCustomRenderer limb) {
ModelTransform trans = this.pose.limbs.get(limb.limb.name);
limb.applyTransform(trans == null ? ModelTransform.DEFAULT : trans);
}
use of mchorse.blockbuster.api.ModelTransform in project blockbuster by mchorse.
the class ModelExporterOBJ method generateMeshes.
/**
* Prepare and generate meshes. This method is responsible for
* turning model's limbs into boxes and also preparing
* transformation matrices for actual generation of OBJ geometry.
*/
private void generateMeshes(Map<ModelLimb, Mesh> meshes) {
ModelBase base = new ModelBase() {
};
base.textureWidth = this.data.texture[0];
base.textureHeight = this.data.texture[1];
for (ModelLimb limb : this.data.limbs.values()) {
ModelTransform transform = this.pose.limbs.get(limb.name);
if (transform == null) {
transform = ModelTransform.DEFAULT;
}
Matrix4f mat = new Matrix4f();
mat.setIdentity();
Matrix3f rotScale = new Matrix3f();
rotScale.setIdentity();
mat.setTranslation(new Vector3f(transform.translate));
mat.m23 = -mat.m23;
mat.m13 = -mat.m13;
Matrix3f x = new Matrix3f();
rotScale.m00 = transform.scale[0];
rotScale.m11 = transform.scale[1];
rotScale.m22 = transform.scale[2];
Matrix3f rot = new Matrix3f();
rot.setIdentity();
x.setIdentity();
x.rotZ((float) Math.toRadians(-transform.rotate[2]));
rot.mul(x);
x.setIdentity();
x.rotY((float) Math.toRadians(-transform.rotate[1]));
rot.mul(x);
x.setIdentity();
x.rotX((float) Math.toRadians(transform.rotate[0]));
rot.mul(x);
rotScale.mul(rot);
mat.setRotationScale(rotScale);
int w = limb.size[0];
int h = limb.size[1];
int d = limb.size[2];
float ox = 1 - limb.anchor[0];
float oy = limb.anchor[1];
float oz = limb.anchor[2];
ModelBox box = new ModelBox(new ModelRenderer(base), limb.texture[0], limb.texture[1], -w * ox, -h * oy, -d * oz, w, h, d, limb.sizeOffset, limb.mirror);
meshes.put(limb, new Mesh(box, mat, rot));
}
}
use of mchorse.blockbuster.api.ModelTransform in project blockbuster by mchorse.
the class ModelPoseAdapter method serialize.
@Override
public JsonElement serialize(ModelPose src, Type typeOfSrc, JsonSerializationContext context) {
JsonElement serial = ModelAdapter.plainGSON.toJsonTree(src, typeOfSrc);
JsonObject map = serial.getAsJsonObject();
JsonObject limbs = new JsonObject();
map.remove("limbs");
if (src.shapes.isEmpty()) {
map.remove("shapes");
}
for (Map.Entry<String, ModelTransform> limb : src.limbs.entrySet()) {
ModelTransform trans = limb.getValue();
JsonObject transform = new JsonObject();
boolean empty = true;
if (!isDefault(trans.translate, 0)) {
addFloatArray(transform, "translate", trans.translate);
empty = false;
}
if (!isDefault(trans.rotate, 0)) {
addFloatArray(transform, "rotate", trans.rotate);
empty = false;
}
if (!isDefault(trans.scale, 1)) {
addFloatArray(transform, "scale", trans.scale);
empty = false;
}
if (!empty) {
limbs.add(limb.getKey(), transform);
}
}
map.add("limbs", limbs);
return map;
}
Aggregations