Search in sources :

Example 1 with ModelRenderer

use of net.minecraft.client.model.ModelRenderer in project ArsMagica2 by Mithion.

the class Animator method update.

public void update(IAnimatedEntity entity) {
    tempTick = prevTempTick = 0;
    correctAnim = false;
    animEntity = entity;
    transformMap.clear();
    prevTransformMap.clear();
    for (int i = 0; i < mainModel.boxList.size(); i++) {
        ModelRenderer box = (ModelRenderer) mainModel.boxList.get(i);
        box.rotateAngleX = 0F;
        box.rotateAngleY = 0F;
        box.rotateAngleZ = 0F;
    }
}
Also used : ModelRenderer(net.minecraft.client.model.ModelRenderer)

Example 2 with ModelRenderer

use of net.minecraft.client.model.ModelRenderer in project ArsMagica2 by Mithion.

the class Animator method endPhase.

private void endPhase(boolean stationary) {
    if (!correctAnim)
        return;
    int animTick = animEntity.getAnimTick();
    if (animTick >= prevTempTick && animTick < tempTick) {
        if (stationary) {
            for (ModelRenderer box : prevTransformMap.keySet()) {
                Transform transform = prevTransformMap.get(box);
                box.rotateAngleX += transform.rotX;
                box.rotateAngleY += transform.rotY;
                box.rotateAngleZ += transform.rotZ;
                box.rotationPointX += transform.offsetX;
                box.rotationPointY += transform.offsetY;
                box.rotationPointZ += transform.offsetZ;
            }
        } else {
            float tick = (animTick - prevTempTick + AnimationAPI.proxy.getPartialTick()) / (tempTick - prevTempTick);
            float inc = MathHelper.sin(tick * PI / 2F), dec = 1F - inc;
            for (ModelRenderer box : prevTransformMap.keySet()) {
                Transform transform = prevTransformMap.get(box);
                box.rotateAngleX += dec * transform.rotX;
                box.rotateAngleY += dec * transform.rotY;
                box.rotateAngleZ += dec * transform.rotZ;
                box.rotationPointX += dec * transform.offsetX;
                box.rotationPointY += dec * transform.offsetY;
                box.rotationPointZ += dec * transform.offsetZ;
            }
            for (ModelRenderer box : transformMap.keySet()) {
                Transform transform = transformMap.get(box);
                box.rotateAngleX += inc * transform.rotX;
                box.rotateAngleY += inc * transform.rotY;
                box.rotateAngleZ += inc * transform.rotZ;
                box.rotationPointX += inc * transform.offsetX;
                box.rotationPointY += inc * transform.offsetY;
                box.rotationPointZ += inc * transform.offsetZ;
            }
        }
    }
    if (!stationary) {
        prevTransformMap.clear();
        prevTransformMap.putAll(transformMap);
        transformMap.clear();
    }
}
Also used : ModelRenderer(net.minecraft.client.model.ModelRenderer)

Example 3 with ModelRenderer

use of net.minecraft.client.model.ModelRenderer in project ArsMagica2 by Mithion.

the class ModelHecate method initRenderers.

private void initRenderers() {
    Main = new ModelRenderer(this, "Main");
    Main.setRotationPoint(0F, 0F, 0F);
    setRotation(Main, 0F, 0F, 0F);
    Main.mirror = true;
    LeftShoulder = new ModelRenderer(this, "LeftShoulder");
    LeftShoulder.setRotationPoint(5.5F, 1F, 0F);
    setRotation(LeftShoulder, 0F, 0F, 0F);
    LeftShoulder.mirror = true;
    LeftElbow = new ModelRenderer(this, "LeftElbow");
    LeftElbow.setRotationPoint(0F, 3F, 0F);
    setRotation(LeftElbow, 0F, 0F, 0F);
    LeftElbow.mirror = true;
    LeftHand = new ModelRenderer(this, "LeftHand");
    LeftHand.setRotationPoint(0F, 4F, 0F);
    setRotation(LeftHand, 0F, 0F, 0F);
    LeftHand.mirror = true;
    LeftOuterFinger = new ModelRenderer(this, "LeftOuterFinger");
    LeftOuterFinger.setRotationPoint(0.5F, 0.6F, 0.5F);
    setRotation(LeftOuterFinger, 0F, 0F, 0F);
    LeftOuterFinger.mirror = true;
    LOF1 = new ModelRenderer(this, "LOF1");
    LOF1.setRotationPoint(0F, 0.6F, 0F);
    setRotation(LOF1, 0F, 0F, 0F);
    LOF1.mirror = true;
    LOF2 = new ModelRenderer(this, "LOF2");
    LOF2.setRotationPoint(0F, 0.6F, 0F);
    setRotation(LOF2, 0F, 0F, 0F);
    LOF2.mirror = true;
    LeftInnerFinger = new ModelRenderer(this, "LeftInnerFinger");
    LeftInnerFinger.setRotationPoint(-0.5F, 0.6F, 0.5F);
    setRotation(LeftInnerFinger, 0F, 0F, 0F);
    LeftInnerFinger.mirror = true;
    LIF1 = new ModelRenderer(this, "LIF1");
    LIF1.setRotationPoint(0F, 0.6F, 0F);
    setRotation(LIF1, 0F, 0F, 0F);
    LIF1.mirror = true;
    LIF2 = new ModelRenderer(this, "LIF2");
    LIF2.setRotationPoint(0F, 0.6F, 0F);
    setRotation(LIF2, 0F, 0F, 0F);
    LIF2.mirror = true;
    LeftThumb = new ModelRenderer(this, "LeftThumb");
    LeftThumb.setRotationPoint(-1F, 0F, 0.5F);
    setRotation(LeftThumb, 0F, 0F, 0F);
    LeftThumb.mirror = true;
    LT1 = new ModelRenderer(this, "LT1");
    LT1.setRotationPoint(0F, 0.5F, 0F);
    setRotation(LT1, 0F, 0F, 0F);
    LT1.mirror = true;
    LT2 = new ModelRenderer(this, "LT2");
    LT2.setRotationPoint(0F, 0.5F, 0F);
    setRotation(LT2, 0F, 0F, 0F);
    LT2.mirror = true;
    RightShoulder = new ModelRenderer(this, "RightShoulder");
    RightShoulder.setRotationPoint(-5.5F, 1F, 0F);
    setRotation(RightShoulder, 0F, 0F, 0F);
    RightShoulder.mirror = true;
    RightElbow = new ModelRenderer(this, "RightElbow");
    RightElbow.setRotationPoint(0F, 3F, 0F);
    setRotation(RightElbow, 0F, 0F, 0F);
    RightElbow.mirror = true;
    RightHand = new ModelRenderer(this, "RightHand");
    RightHand.setRotationPoint(0F, 4F, 0F);
    setRotation(RightHand, 0F, 0F, 0F);
    RightHand.mirror = true;
    RightOuterFinger = new ModelRenderer(this, "RightOuterFinger");
    RightOuterFinger.setRotationPoint(-0.5F, 0.6F, 0.5F);
    setRotation(RightOuterFinger, 0F, 0F, 0F);
    RightOuterFinger.mirror = true;
    ROF1 = new ModelRenderer(this, "ROF1");
    ROF1.setRotationPoint(0F, 0.6F, 0F);
    setRotation(ROF1, 0F, 0F, 0F);
    ROF1.mirror = true;
    ROF2 = new ModelRenderer(this, "ROF2");
    ROF2.setRotationPoint(0F, 0.6F, 0F);
    setRotation(ROF2, 0F, 0F, 0F);
    ROF2.mirror = true;
    RightInnerFinger = new ModelRenderer(this, "RightInnerFinger");
    RightInnerFinger.setRotationPoint(0.5F, 0.6F, 0.5F);
    setRotation(RightInnerFinger, 0F, 0F, 0F);
    RightInnerFinger.mirror = true;
    RIF1 = new ModelRenderer(this, "RIF1");
    RIF1.setRotationPoint(0F, 0.6F, 0F);
    setRotation(RIF1, 0F, 0F, 0F);
    RIF1.mirror = true;
    RIF2 = new ModelRenderer(this, "RIF2");
    RIF2.setRotationPoint(0F, 0.6F, 0F);
    setRotation(RIF2, 0F, 0F, 0F);
    RIF2.mirror = true;
    RightThumb = new ModelRenderer(this, "RightThumb");
    RightThumb.setRotationPoint(1F, 0F, 0.5F);
    setRotation(RightThumb, 0F, 0F, 0F);
    RightThumb.mirror = true;
    RT1 = new ModelRenderer(this, "RT1");
    RT1.setRotationPoint(0F, 0.5F, 0F);
    setRotation(RT1, 0F, 0F, 0F);
    RT1.mirror = true;
    RT2 = new ModelRenderer(this, "RT2");
    RT2.setRotationPoint(0F, 0.5F, 0F);
    setRotation(RT2, 0F, 0F, 0F);
    RT2.mirror = true;
    Head = new ModelRenderer(this, "Head");
    Head.setRotationPoint(0F, -1F, 0.5F);
    setRotation(Head, 0F, 0F, 0F);
    Head.mirror = true;
    H1 = new ModelRenderer(this, "H1");
    H1.setRotationPoint(0F, 0F, -1.9F);
    setRotation(H1, 0F, 0F, 0F);
    H1.mirror = true;
}
Also used : ModelRenderer(net.minecraft.client.model.ModelRenderer)

Example 4 with ModelRenderer

use of net.minecraft.client.model.ModelRenderer in project Engine by VoltzEngine-Project.

the class FixedTechneModel method renderAll.

@Override
public void renderAll() {
    GL11.glPushMatrix();
    bindTexture();
    setup();
    for (ModelRenderer part : parts.values()) {
        part.render(0.0625f);
    }
    GL11.glPopMatrix();
}
Also used : ModelRenderer(net.minecraft.client.model.ModelRenderer)

Example 5 with ModelRenderer

use of net.minecraft.client.model.ModelRenderer in project Engine by VoltzEngine-Project.

the class FixedTechneModel method loadTechneModel.

//TODO break into smaller methods
private void loadTechneModel(InputStream stream) throws ModelFormatException {
    try {
        ZipInputStream zipInput = new ZipInputStream(stream);
        ZipEntry entry;
        while ((entry = zipInput.getNextEntry()) != null) {
            byte[] data = new byte[(int) entry.getSize()];
            // For some reason, using read(byte[]) makes reading stall upon reaching a 0x1E byte
            int i = 0;
            while (zipInput.available() > 0 && i < data.length) {
                data[i++] = (byte) zipInput.read();
            }
            zipContents.put(entry.getName(), data);
        }
        byte[] modelXml = zipContents.get("model.xml");
        if (modelXml == null) {
            throw new ModelFormatException("Model " + fileName + " contains no model.xml file");
        }
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse(new ByteArrayInputStream(modelXml));
        NodeList nodeListTechne = document.getElementsByTagName("Techne");
        if (nodeListTechne.getLength() < 1) {
            throw new ModelFormatException("Model " + fileName + " contains no Techne tag");
        }
        NodeList nodeListModel = document.getElementsByTagName("Model");
        if (nodeListModel.getLength() < 1) {
            throw new ModelFormatException("Model " + fileName + " contains no Model tag");
        }
        NamedNodeMap modelAttributes = nodeListModel.item(0).getAttributes();
        if (modelAttributes == null) {
            throw new ModelFormatException("Model " + fileName + " contains a Model tag with no attributes");
        }
        Node modelTexture = modelAttributes.getNamedItem("texture");
        if (modelTexture != null) {
        //TODO texture = modelTexture.getTextContent();
        }
        NodeList textureSize = document.getElementsByTagName("TextureSize");
        for (int i = 0; i < textureSize.getLength(); i++) {
            String size = textureSize.item(i).getTextContent();
            String[] textureDimensions = size.split(",");
            textureWidth = Integer.parseInt(textureDimensions[0]);
            textureHeight = Integer.parseInt(textureDimensions[1]);
        }
        NodeList shapes = document.getElementsByTagName("Shape");
        for (int i = 0; i < shapes.getLength(); i++) {
            Node shape = shapes.item(i);
            NamedNodeMap shapeAttributes = shape.getAttributes();
            if (shapeAttributes == null) {
                throw new ModelFormatException("Shape #" + (i + 1) + " in " + fileName + " has no attributes");
            }
            Node name = shapeAttributes.getNamedItem("name");
            String shapeName = null;
            if (name != null) {
                shapeName = name.getNodeValue();
            }
            if (shapeName == null) {
                shapeName = "Shape #" + (i + 1);
            }
            String shapeType = null;
            Node type = shapeAttributes.getNamedItem("type");
            if (type != null) {
                shapeType = type.getNodeValue();
            }
            if (shapeType != null && !cubeTypes.contains(shapeType)) {
                FMLLog.warning("Model shape [" + shapeName + "] in " + fileName + " is not a cube, ignoring");
                continue;
            }
            try {
                boolean mirrored = false;
                String[] offset = new String[3];
                String[] position = new String[3];
                String[] rotation = new String[3];
                String[] size = new String[3];
                String[] textureOffset = new String[2];
                NodeList shapeChildren = shape.getChildNodes();
                for (int j = 0; j < shapeChildren.getLength(); j++) {
                    Node shapeChild = shapeChildren.item(j);
                    String shapeChildName = shapeChild.getNodeName();
                    String shapeChildValue = shapeChild.getTextContent();
                    if (shapeChildValue != null) {
                        shapeChildValue = shapeChildValue.trim();
                        switch(shapeChildName) {
                            case "IsMirrored":
                                mirrored = !shapeChildValue.equals("False");
                                break;
                            case "Offset":
                                offset = shapeChildValue.split(",");
                                break;
                            case "Position":
                                position = shapeChildValue.split(",");
                                break;
                            case "Rotation":
                                rotation = shapeChildValue.split(",");
                                break;
                            case "Size":
                                size = shapeChildValue.split(",");
                                break;
                            case "TextureOffset":
                                textureOffset = shapeChildValue.split(",");
                                break;
                        }
                    }
                }
                // That's what the ModelBase subclassing is needed for
                ModelRenderer cube = new ModelRenderer(this, shapeName);
                cube.setTextureOffset(Integer.parseInt(textureOffset[0]), Integer.parseInt(textureOffset[1]));
                cube.mirror = mirrored;
                cube.addBox(Float.parseFloat(offset[0]), Float.parseFloat(offset[1]), Float.parseFloat(offset[2]), Integer.parseInt(size[0]), Integer.parseInt(size[1]), Integer.parseInt(size[2]));
                cube.setRotationPoint(Float.parseFloat(position[0]), Float.parseFloat(position[1]) - 16, Float.parseFloat(position[2]));
                cube.rotateAngleX = (float) Math.toRadians(Float.parseFloat(rotation[0]));
                cube.rotateAngleY = (float) Math.toRadians(Float.parseFloat(rotation[1]));
                cube.rotateAngleZ = (float) Math.toRadians(Float.parseFloat(rotation[2]));
                if (parts.containsKey(shapeName)) {
                    throw new ModelFormatException("Model contained duplicate part name: '" + shapeName + "' node #" + i);
                }
                parts.put(shapeName, cube);
            } catch (NumberFormatException e) {
                FMLLog.warning("Model shape [" + shapeName + "] in " + fileName + " contains malformed integers within its data, ignoring");
                e.printStackTrace();
            }
        }
    } catch (ZipException e) {
        throw new ModelFormatException("Model " + fileName + " is not a valid zip file");
    } catch (IOException e) {
        throw new ModelFormatException("Model " + fileName + " could not be read", e);
    } catch (ParserConfigurationException e) {
    // hush
    } catch (SAXException e) {
        throw new ModelFormatException("Model " + fileName + " contains invalid XML", e);
    }
}
Also used : ModelFormatException(net.minecraftforge.client.model.ModelFormatException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) ZipEntry(java.util.zip.ZipEntry) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) ZipInputStream(java.util.zip.ZipInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ModelRenderer(net.minecraft.client.model.ModelRenderer) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

ModelRenderer (net.minecraft.client.model.ModelRenderer)10 ZipEntry (java.util.zip.ZipEntry)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Entry (java.util.Map.Entry)1 ZipException (java.util.zip.ZipException)1 ZipInputStream (java.util.zip.ZipInputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ModelFormatException (net.minecraftforge.client.model.ModelFormatException)1 Document (org.w3c.dom.Document)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 SAXException (org.xml.sax.SAXException)1