private Vertex parseVertexNormal(String line, int lineCount) throws ModelFormatException { Vertex vertexNormal = null; if (isValidVertexNormalLine(line)) { line = line.substring(line.indexOf(" ") + 1); String[] tokens = line.split(" "); try { if (tokens.length == 3) return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2])); } catch (NumberFormatException e) { throw new ModelFormatException(String.format("Number formatting error at line %d",lineCount), e); } } else { throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format"); } return vertexNormal; }
private GroupObject parseGroupObject(String line, int lineCount) throws ModelFormatException { GroupObject group = null; if (isValidGroupObjectLine(line)) { String trimmedLine = line.substring(line.indexOf(" ") + 1); if (trimmedLine.length() > 0) { group = new GroupObject(trimmedLine); } } else { throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format"); } return group; }
public ColladaAsset(Document doc) { this.root = doc.getDocumentElement(); String upAxis = GetXPathString("asset/up_axis"); if (upAxis.equals("X_UP")) { xAxis = "Z"; yAxis = "X"; zAxis = "Y"; } else if (upAxis.equals("Y_UP")) { xAxis = "X"; yAxis = "Y"; zAxis = "Z"; } else if (upAxis.equals("Z_UP")) { xAxis = "Y"; yAxis = "Z"; zAxis = "X"; } else throw new ModelFormatException("Invalid up axis configuration"); }
private Matrix parseMatrix(Element matrixElem) { double[] matrixData = splitDataDouble(matrixElem.getTextContent()); if (matrixData.length != 16) throw new ModelFormatException("Invalid matrix data"); double tmp = matrixData[7]; matrixData[7] = matrixData[11]; matrixData[11] = -tmp; ByteBuffer matrixBytes = ByteBuffer.allocateDirect(16 * 8); matrixBytes.order(ByteOrder.nativeOrder()); matrixBytes.clear(); DoubleBuffer matrix = matrixBytes.asDoubleBuffer(); matrix.clear(); for (int j = 0; j < 4; j++) { matrix.put(matrixData[j]); matrix.put(matrixData[j + 4]); matrix.put(matrixData[j + 8]); matrix.put(matrixData[j + 12]); } return new Matrix(matrixElem.getAttribute("id"), toMinecraftCoords(matrix)); }
public WavefrontObject(ResourceLocation resource) throws ModelFormatException { this.fileName = resource.toString(); try { IResource res = Minecraft.func_71410_x().func_110442_L().func_110536_a(resource); loadObjModel(res.func_110527_b()); } catch (IOException e) { throw new ModelFormatException("IO Exception reading model format", e); } }
private Vertex parseVertex(String line, int lineCount) throws ModelFormatException { Vertex vertex = null; if (isValidVertexLine(line)) { line = line.substring(line.indexOf(" ") + 1); String[] tokens = line.split(" "); try { if (tokens.length == 2) { return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1])); } else if (tokens.length == 3) { return new Vertex(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2])); } } catch (NumberFormatException e) { throw new ModelFormatException(String.format("Number formatting error at line %d",lineCount), e); } } else { throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format"); } return vertex; }
private TextureCoordinate parseTextureCoordinate(String line, int lineCount) throws ModelFormatException { TextureCoordinate textureCoordinate = null; if (isValidTextureCoordinateLine(line)) { line = line.substring(line.indexOf(" ") + 1); String[] tokens = line.split(" "); try { if (tokens.length == 2) return new TextureCoordinate(Float.parseFloat(tokens[0]), 1 - Float.parseFloat(tokens[1])); else if (tokens.length == 3) return new TextureCoordinate(Float.parseFloat(tokens[0]), 1 - Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2])); } catch (NumberFormatException e) { throw new ModelFormatException(String.format("Number formatting error at line %d",lineCount), e); } } else { throw new ModelFormatException("Error parsing entry ('" + line + "'" + ", line " + lineCount + ") in file '" + fileName + "' - Incorrect format"); } return textureCoordinate; }
public TechneModel(ResourceLocation resource) throws ModelFormatException { this.fileName = resource.toString(); try { IResource res = Minecraft.func_71410_x().func_110442_L().func_110536_a(resource); loadTechneModel(res.func_110527_b()); } catch (IOException e) { throw new ModelFormatException("IO Exception reading model format", e); } }
public WavefrontObject(ResourceLocation resource) throws ModelFormatException { this.fileName = resource.toString(); try { IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource); loadObjModel(res.getInputStream()); } catch (IOException e) { throw new ModelFormatException("IO Exception reading model format", e); } }
public TechneModel(ResourceLocation resource) throws ModelFormatException { this.fileName = resource.toString(); try { IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource); loadTechneModel(res.getInputStream()); } catch (IOException e) { throw new ModelFormatException("IO Exception reading model format", e); } }
@Override public void preInit(FMLPreInitializationEvent event) { //Load models Game.render().modelProviders.forEach(m -> { ResourceLocation resource = new ResourceLocation(m.domain, "models/" + m.name + "." + m.getType()); try { IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource); m.load(res.getInputStream()); } catch (IOException e) { throw new ModelFormatException("IO Exception reading model format", e); } }); }
TechneModel(String fileName, URL resource) throws ModelFormatException { this.fileName = fileName; this.loadedURL = resource; this.visible = true; loadTechneModel( resource ); }
@Override public IModelCustom loadInstance(ResourceLocation resource) throws ModelFormatException { IResource res; try { res = Minecraft.getMinecraft().getResourceManager() .getResource(resource); } catch (IOException e) { throw new ModelFormatException("IO Exception reading model format", e); } return LoadFromStream(res.getInputStream()); }
private String GetXPathString(Element node, String path) { try { return (String) xpath.evaluate(path, node, XPathConstants.STRING); } catch (XPathExpressionException e) { throw new ModelFormatException( "Could not get the string for the path '" + path + "'", e); } }
private Element GetXPathElement(Element node, String path) { try { return (Element) xpath.evaluate(path, node, XPathConstants.NODE); } catch (XPathExpressionException e) { throw new ModelFormatException( "Could not get the element for the path '" + path + "'", e); } }
private Collection<Element> GetXPathElementList(Element node, String path) { try { LinkedList<Element> result = new LinkedList<Element>(); NodeList nodes = (NodeList) xpath.evaluate(path, node, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) result.add((Element) nodes.item(i)); return result; } catch (XPathExpressionException e) { throw new ModelFormatException( "Could not get the node list for the path '" + path + "'", e); } }
private Translation parseTranslation(Element transElem) { double[] transData = splitDataDouble(transElem.getTextContent()); if (transData.length != 3) throw new ModelFormatException("Invalid translate data"); return new Translation(transElem.getAttribute("id"), toMinecraftCoords( transData[0], transData[1], transData[2])); }
private Rotation parseRotation(Element rotElem) { double[] rotData = splitDataDouble(rotElem.getTextContent()); if (rotData.length != 4) throw new ModelFormatException("Invalid rotate data"); return new Rotation(rotElem.getAttribute("id"), toMinecraftCoords( rotData[0], rotData[1], rotData[2]), rotData[3]); }
private Scale parseScale(Element scaleElem) { double[] scaleData = splitDataDouble(scaleElem.getTextContent()); if (scaleData.length != 3) throw new ModelFormatException("Invalid scale data"); return new Scale(scaleElem.getAttribute("id"), toMinecraftCoords( scaleData[0], scaleData[1], scaleData[2])); }
private void parseMeshTriangles(Geometry geom, Element meshElem, Element triElem) { ColladaSource[] dataSrcs = parseMeshInputSources(meshElem, triElem); int count = Integer.parseInt(triElem.getAttribute("count")); int[] refs = splitDataInt(GetXPathElement(triElem, "p") .getTextContent()); if (refs.length != (count * 9)) throw new ModelFormatException("Wrong number of data elements"); for (int q = 0; q < count; q++) { Vec3[] vertex = new Vec3[3]; Vec3[] normal = new Vec3[3]; Vec3[] texCoords = new Vec3[3]; for (int r = 0; r < 3; r++) { vertex[r] = toMinecraftCoords(dataSrcs[0].getVec3(refs[q * 9 + r * 3], "X", "Y", "Z")); normal[r] = toMinecraftCoords(dataSrcs[1].getVec3(refs[q * 9 + r * 3 + 1], "X", "Y", "Z")); texCoords[r] = dataSrcs[2].getVec2(refs[q * 9 + r * 3 + 2], "S", "T"); } Face poly = new Face(); poly.setVertex(vertex, normal, texCoords); geom.addFace(poly); } }
private void parseMeshPolylist(Geometry geom, Element meshElem, Element polylistElem) { ColladaSource[] dataSrcs = parseMeshInputSources(meshElem, polylistElem); int count = Integer.parseInt(polylistElem.getAttribute("count")); int[] vcount = splitDataInt(GetXPathElement(polylistElem, "vcount") .getTextContent()); int[] refs = splitDataInt(GetXPathElement(polylistElem, "p") .getTextContent()); if (vcount.length != count) throw new ModelFormatException("Wrong number of data elements"); int p = 0; for (int q = 0; q < vcount.length; q++) { Vec3[] vertex = new Vec3[vcount[q]]; Vec3[] normal = new Vec3[vcount[q]]; Vec3[] texCoords = new Vec3[vcount[q]]; for (int r = 0; r < vcount[q]; r++) { vertex[r] = toMinecraftCoords(dataSrcs[0].getVec3(refs[p * 3], "X", "Y", "Z")); normal[r] = toMinecraftCoords(dataSrcs[1].getVec3( refs[p * 3 + 1], "X", "Y", "Z")); texCoords[r] = dataSrcs[2].getVec2(refs[p * 3 + 2], "S", "T"); p++; } Face poly = new Face(); poly.setVertex(vertex, normal, texCoords); geom.addFace(poly); } }
private void parseMeshPolygons(Geometry geom, Element meshElem, Element polyElem) { ColladaSource[] dataSrcs = parseMeshInputSources(meshElem, polyElem); int count = Integer.parseInt(polyElem.getAttribute("count")); Collection<Element> polysData = GetXPathElementList(polyElem, "p"); if (polysData.size() != count) throw new ModelFormatException("Wrong number of data elements"); for (Element pElem : polysData) { int[] refs = splitDataInt(pElem.getTextContent()); Vec3[] vertex = new Vec3[refs.length / 3]; Vec3[] normal = new Vec3[refs.length / 3]; Vec3[] texCoords = new Vec3[refs.length / 3]; for (int r = 0; r < refs.length / 3; r++) { vertex[r] = toMinecraftCoords(dataSrcs[0].getVec3(refs[r * 3], "X", "Y", "Z")); normal[r] = toMinecraftCoords(dataSrcs[1].getVec3( refs[r * 3 + 1], "X", "Y", "Z")); texCoords[r] = dataSrcs[2].getVec2(refs[r * 3 + 2], "S", "T"); } Face poly = new Face(); poly.setVertex(vertex, normal, texCoords); geom.addFace(poly); } }
public TechneModel(ResourceLocation resource) throws ModelFormatException { this.fileName = resource.toString(); try { IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource); loadTechneModel(res.getInputStream()); } catch (Exception e) { throw new ModelFormatException("IO Exception reading models format", e); } }