List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname)
From source file:com.ardor3d.extension.model.collada.jdom.ColladaMeshUtils.java
License:Open Source License
public Mesh buildMeshTriangles(final Element colladaGeometry, final Element tris) { if (tris == null || tris.getChild("input") == null || tris.getChild("p") == null) { return null; }/*from w ww .jav a 2s . c o m*/ final Mesh triMesh = new Mesh(extractName(colladaGeometry, tris)); triMesh.getMeshData().setIndexMode(IndexMode.Triangles); // Build and set RenderStates for our material _colladaMaterialUtils.applyMaterial(tris.getAttributeValue("material"), triMesh); final LinkedList<ColladaInputPipe> pipes = new LinkedList<ColladaInputPipe>(); final int maxOffset = extractPipes(tris, pipes); final int interval = maxOffset + 1; // use interval & size of p array to determine buffer sizes. final int[] vals = _colladaDOMUtil.parseIntArray(tris.getChild("p")); final int numEntries = vals.length / interval; // Construct nio buffers for specified inputs. for (final ColladaInputPipe pipe : pipes) { pipe.setupBuffer(numEntries, triMesh.getMeshData(), _dataCache); } // Add to vert mapping final int[] indices = new int[numEntries]; final MeshVertPairs mvp = new MeshVertPairs(triMesh, indices); _dataCache.getVertMappings().put(colladaGeometry, mvp); // go through the p entry // for each p, iterate using max offset final int[] currentVal = new int[interval]; // Go through entries and add to buffers. for (int j = 0, max = numEntries; j < max; j++) { // add entry to buffers System.arraycopy(vals, j * interval, currentVal, 0, interval); final int rVal = processPipes(pipes, currentVal); if (rVal != Integer.MIN_VALUE) { indices[j] = rVal; } } if (_optimizeMeshes) { final VertMap map = _geometryTool.minimizeVerts(triMesh, _optimizeSettings); _dataCache.setMeshVertMap(triMesh, map); } triMesh.updateModelBound(); return triMesh; }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaMeshUtils.java
License:Open Source License
public Line buildMeshLines(final Element colladaGeometry, final Element lines) { if (lines == null || lines.getChild("input") == null || lines.getChild("p") == null) { return null; }/*from ww w . j ava2 s. c om*/ final Line lineMesh = new Line(extractName(colladaGeometry, lines)); // Build and set RenderStates for our material _colladaMaterialUtils.applyMaterial(lines.getAttributeValue("material"), lineMesh); final LinkedList<ColladaInputPipe> pipes = new LinkedList<ColladaInputPipe>(); final int maxOffset = extractPipes(lines, pipes); final int interval = maxOffset + 1; // use interval & size of p array to determine buffer sizes. final int[] vals = _colladaDOMUtil.parseIntArray(lines.getChild("p")); final int numEntries = vals.length / interval; // Construct nio buffers for specified inputs. for (final ColladaInputPipe pipe : pipes) { pipe.setupBuffer(numEntries, lineMesh.getMeshData(), _dataCache); } // Add to vert mapping final int[] indices = new int[numEntries]; final MeshVertPairs mvp = new MeshVertPairs(lineMesh, indices); _dataCache.getVertMappings().put(colladaGeometry, mvp); // go through the p entry // for each p, iterate using max offset final int[] currentVal = new int[interval]; // Go through entries and add to buffers. for (int j = 0, max = numEntries; j < max; j++) { // add entry to buffers System.arraycopy(vals, j * interval, currentVal, 0, interval); final int rVal = processPipes(pipes, currentVal); if (rVal != Integer.MIN_VALUE) { indices[j] = rVal; } } if (_optimizeMeshes) { final VertMap map = _geometryTool.minimizeVerts(lineMesh, _optimizeSettings); _dataCache.setMeshVertMap(lineMesh, map); } lineMesh.updateModelBound(); return lineMesh; }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaNodeUtils.java
License:Open Source License
/** * Retrieves the scene and returns it as an Ardor3D Node. * //from w ww . ja v a2 s . c om * @param colladaRoot * The collada root element * @return Scene as an Node or null if not found */ @SuppressWarnings("unchecked") public Node getVisualScene(final Element colladaRoot) { if (colladaRoot.getChild("scene") == null) { logger.warning("No scene found in collada file!"); return null; } final Element instance_visual_scene = colladaRoot.getChild("scene").getChild("instance_visual_scene"); if (instance_visual_scene == null) { logger.warning("No instance_visual_scene found in collada file!"); return null; } final Element visualScene = _colladaDOMUtil .findTargetWithId(instance_visual_scene.getAttributeValue("url")); if (visualScene != null) { final Node sceneRoot = new Node( visualScene.getAttributeValue("name") != null ? visualScene.getAttributeValue("name") : "Collada Root"); // Load each sub node and attach final JointNode baseJointNode = new JointNode(null); _dataCache.setRootJointNode(baseJointNode); for (final Element n : visualScene.getChildren("node")) { final Node subNode = buildNode(n, baseJointNode); if (subNode != null) { sceneRoot.attachChild(subNode); } } // build a list of joints - one list per skeleton - and build a skeleton for each joint list. for (final JointNode jointChildNode : _dataCache.getRootJointNode().getChildren()) { final List<Joint> jointList = Lists.newArrayList(); buildJointLists(jointChildNode, jointList); final Joint[] joints = jointList.toArray(new Joint[jointList.size()]); final Skeleton skeleton = new Skeleton(joints[0].getName() + "_skeleton", joints); if (logger.isLoggable(Level.FINE)) { logger.fine("skeleton created: " + skeleton.getName()); } for (final Joint joint : jointList) { _dataCache.getJointSkeletonMapping().put(joint, skeleton); if (logger.isLoggable(Level.FINE)) { logger.fine("- Joint " + joint.getName() + " - index: " + joint.getIndex() + " parent index: " + joint.getParentIndex()); } } _dataCache.addSkeleton(skeleton); } // update our world transforms so we can use them to init the default bind matrix of any joints. sceneRoot.updateWorldTransform(true); initDefaultJointTransforms(baseJointNode); // Setup our skinned mesh objects. for (final ControllerStore controllerStore : _dataCache.getControllers()) { _colladaMaterialUtils.bindMaterials(controllerStore.instanceController.getChild("bind_material")); _colladaAnimUtils.buildController(controllerStore.ardorParentNode, controllerStore.instanceController); _colladaMaterialUtils.unbindMaterials(controllerStore.instanceController.getChild("bind_material")); } return sceneRoot; } return null; }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaNodeUtils.java
License:Open Source License
/** * Recursively parse the node hierarcy./*from w ww . ja v a2 s . co m*/ * * @param dNode * @return a new Ardor3D node, created from the given <node> element */ @SuppressWarnings("unchecked") private Node buildNode(final Element dNode, JointNode jointNode) { final NodeType nodeType = getNodeType(dNode); final JointNode jointChildNode; if (nodeType == NodeType.JOINT) { String name = dNode.getAttributeValue("name"); if (name == null) { name = dNode.getAttributeValue("id"); } if (name == null) { name = dNode.getAttributeValue("sid"); } final Joint joint = new Joint(name); jointChildNode = new JointNode(joint); jointChildNode.setParent(jointNode); jointNode.getChildren().add(jointChildNode); jointNode = jointChildNode; _dataCache.getElementJointMapping().put(dNode, joint); } else { jointChildNode = null; } String nodeName = dNode.getAttributeValue("name", (String) null); if (nodeName == null) { // use id if name doesn't exist nodeName = dNode.getAttributeValue("id", dNode.getName()); } final Node node = new Node(nodeName); final List<Element> transforms = new ArrayList<Element>(); for (final Element child : dNode.getChildren()) { if (_dataCache.getTransformTypes().contains(child.getName())) { transforms.add(child); } } // process any transform information. if (!transforms.isEmpty()) { final Transform localTransform = getNodeTransforms(transforms); node.setTransform(localTransform); if (jointChildNode != null) { jointChildNode.setSceneNode(node); } } // process any instance geometries for (final Element instance_geometry : dNode.getChildren("instance_geometry")) { _colladaMaterialUtils.bindMaterials(instance_geometry.getChild("bind_material")); final Spatial mesh = _colladaMeshUtils.getGeometryMesh(instance_geometry); if (mesh != null) { node.attachChild(mesh); } _colladaMaterialUtils.unbindMaterials(instance_geometry.getChild("bind_material")); } // process any instance controllers for (final Element instanceController : dNode.getChildren("instance_controller")) { _dataCache.getControllers().add(new ControllerStore(node, instanceController)); } // process any instance nodes for (final Element in : dNode.getChildren("instance_node")) { final Node subNode = getNode(in, jointNode); if (subNode != null) { node.attachChild(subNode); if (nodeType == NodeType.JOINT && getNodeType( _colladaDOMUtil.findTargetWithId(in.getAttributeValue("url"))) == NodeType.NODE) { // make attachment createJointAttachment(jointChildNode, node, subNode); } } } // process any concrete child nodes. for (final Element n : dNode.getChildren("node")) { final Node subNode = buildNode(n, jointNode); if (subNode != null) { node.attachChild(subNode); if (nodeType == NodeType.JOINT && getNodeType(n) == NodeType.NODE) { // make attachment createJointAttachment(jointChildNode, node, subNode); } } } // Cache reference _dataCache.getElementSpatialMapping().put(dNode, node); return node; }
From source file:com.ardor3d.extension.model.collada.jdom.plugin.GoogleEarthPlugin.java
License:Open Source License
@Override public boolean processExtra(final Element extra, final Object[] params) { if (params.length > 0 && params[0] instanceof Mesh) { final Mesh mesh = (Mesh) params[0]; // should have a child: <technique profile="GOOGLEEARTH"> final Element technique = extra.getChild("technique"); if (technique != null) { final Attribute profile = technique.getAttribute("profile"); if (profile != null && "GOOGLEEARTH".equalsIgnoreCase(profile.getValue())) { for (final Element child : technique.getChildren()) { // disable back face culling if it's been enabled. if ("double_sided".equalsIgnoreCase(child.getName()) && "1".equals(child.getTextTrim())) { final CullState cs = new CullState(); cs.setEnabled(false); mesh.setRenderState(cs); }/*from w ww . jav a 2s .c om*/ } return true; } } } return false; }
From source file:com.astronomy.project.Orientation.java
/** * //w w w .j a v a 2 s.c o m * @param e XML elemento for orientation * @throws ProcessException Format error */ public Orientation(Element e) throws ProcessException { super(SexagesimalDegree.valueOf(e.getChild("acimut").getText()), SexagesimalDegree.valueOf(e.getChild("elevacion").getText())); }
From source file:com.astronomy.project.Project.java
/** * Parse XML project/* w w w . j a va 2 s .c om*/ * @param file XML file * @throws JDOMException XML error * @throws IOException IO error * @throws ProcessException Format error */ public void parseXML(File file) throws JDOMException, IOException, ProcessException { SAXBuilder saxBuilder = new SAXBuilder(); Document document = saxBuilder.build(file); Element raiz = document.getRootElement(); name = raiz.getAttributeValue("nombre"); List<Element> aa = raiz.getChild("alineamientos").getChildren(); data.clear(); for (Element e : aa) { data.add(new Alignment(e)); } }
From source file:com.astronomy.project.ReferencePoint.java
/** * //from ww w .j av a2 s . co m * @param e Reference point as XML element * @throws ProcessException Format error */ public ReferencePoint(Element e) throws ProcessException { this.type = e.getAttributeValue("tipo"); this.name = e.getChild("nombre").getText(); try { coordinates = new Geographic( SexagesimalDegree.valueOf(e.getChild("coordenadas").getChild("latitud").getText()), SexagesimalDegree.valueOf(e.getChild("coordenadas").getChild("longitud").getText()), Double.valueOf(e.getChild("coordenadas").getChild("altitud").getText())); } catch (NullPointerException ex) { coordinates = null; } }
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * ? ?? Data setting (data class : PDFMetadataDefinition) * /*from w w w . j a va 2 s .c o m*/ * @param root * @param rootData * @param upload * @throws Exception */ public static void setDynamicSection(Element root, PDFMetadataDefinition rootData, Upload upload) throws Exception { List<Element> childs = new ArrayList<Element>(); AnalyzeDefinition data = rootData.getEarDefinition(); setDynamicSection(root, data, upload); for (Element e : root.getChildren()) { if (e.getName().equals("section")) { if (e.getChild("war_child_deploy") != null) { //ear Web Applications childs = setChildDeployData(rootData, upload, "war"); } else if (e.getChild("jar_child_deploy") != null) { //ear EJB Applications childs = setChildDeployData(rootData, upload, "jar"); } else if (e.getChild("trans_application_xml_info") != null) { //?? - application Deployment Descriptor childs = setTransXmlData(rootData, upload, "application"); } else if (e.getChild("trans_web_xml_info") != null) { //?? - Web Deployment Descriptor childs = setTransXmlData(rootData, upload, "web"); } else if (e.getChild("trans_ejb_xml_info") != null) { //?? - EJB Deployment Descriptor childs = setTransXmlData(rootData, upload, "ejb"); } } for (Element child : childs) { e.addContent(child); } childs = new ArrayList<Element>(); } //?? ? start(chapter ? ?? section? ? ) for (Element e : root.getChildren()) { if (e.getName().equals("exception_info")) { childs = setExceptionData(rootData, upload); } } for (Element child : childs) { root.addContent(child); } childs = new ArrayList<Element>(); //?? ? end }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * /*w w w. j a va 2s. c om*/ * list * * @param section list section ? * @param e list element * @throws Exception */ public static void setList(Section section, Element e) throws Exception { List list = new List(false, 15); list.setIndentationLeft(23); for (Element e1 : e.getChildren()) { ListItem item = new ListItem(e1.getText(), fnNormal); if (e1.getChild("url") != null) { item.add(getUrl(e1.getChild("url"))); } item.setMultipliedLeading(1.8F); list.add(item); } list.getFirstItem().setSpacingBefore(-14); list.getLastItem().setSpacingAfter(14); section.add(list); }