Search in sources :

Example 1 with ModelTransform

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;
}
Also used : ModelPose(mchorse.blockbuster.api.ModelPose) ModelTransform(mchorse.blockbuster.api.ModelTransform) Model(mchorse.blockbuster.api.Model) VoxDocument(mchorse.blockbuster.api.formats.vox.VoxDocument) ModelLimb(mchorse.blockbuster.api.ModelLimb)

Example 2 with ModelTransform

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();
        }
    }
}
Also used : ModelTransform(mchorse.blockbuster.api.ModelTransform) PacketStructureRequest(mchorse.blockbuster.network.common.structure.PacketStructureRequest) StructureRenderer(mchorse.blockbuster_pack.morphs.structure.StructureRenderer) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with ModelTransform

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);
}
Also used : ModelTransform(mchorse.blockbuster.api.ModelTransform)

Example 4 with ModelTransform

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));
    }
}
Also used : Matrix4f(javax.vecmath.Matrix4f) ModelTransform(mchorse.blockbuster.api.ModelTransform) Matrix3f(javax.vecmath.Matrix3f) ModelRenderer(net.minecraft.client.model.ModelRenderer) ModelBox(net.minecraft.client.model.ModelBox) Vector3f(javax.vecmath.Vector3f) ModelBase(net.minecraft.client.model.ModelBase) ModelLimb(mchorse.blockbuster.api.ModelLimb)

Example 5 with ModelTransform

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;
}
Also used : ModelTransform(mchorse.blockbuster.api.ModelTransform) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Map(java.util.Map)

Aggregations

ModelTransform (mchorse.blockbuster.api.ModelTransform)11 ModelPose (mchorse.blockbuster.api.ModelPose)4 Map (java.util.Map)3 ModelLimb (mchorse.blockbuster.api.ModelLimb)3 ModelRenderer (net.minecraft.client.model.ModelRenderer)3 HashMap (java.util.HashMap)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Matrix3f (javax.vecmath.Matrix3f)1 Matrix4f (javax.vecmath.Matrix4f)1 Vector3f (javax.vecmath.Vector3f)1 Model (mchorse.blockbuster.api.Model)1 VoxDocument (mchorse.blockbuster.api.formats.vox.VoxDocument)1 ModelCustomRenderer (mchorse.blockbuster.client.model.ModelCustomRenderer)1 PacketStructureRequest (mchorse.blockbuster.network.common.structure.PacketStructureRequest)1 StructureRenderer (mchorse.blockbuster_pack.morphs.structure.StructureRenderer)1 ModelBase (net.minecraft.client.model.ModelBase)1 ModelBox (net.minecraft.client.model.ModelBox)1