/** * Build string representation of object hierarchy * @param parent * @param sb * @param prefix */ private void buildObjectGraph(Object3D parent, StringBuffer sb, String prefix) { sb.append(prefix).append("-->").append((parent.isContainer() ? "GROUP " : "") + parent.getName()).append('\n'); for(int i=0; i<parent.getNumChildren(); i++) { buildObjectGraph(parent.getChildAt(i), sb, prefix+"\t"); } }
/** * Retrieve the number of objects in the object, recursive method * * @return int the total object count for the object. */ public int getNumObjects() { int objectCount = 0; for (int i = 0, j = getNumChildren(); i < j; i++) { Object3D child = getChildAt(i); if (child.getGeometry() != null && child.getGeometry().getVertices() != null && child.isVisible()) { if (child.getNumChildren() > 0) { objectCount += child.getNumObjects() + 1; } else { objectCount++; } } } return objectCount; }
/** * Retrieve the number of objects on the screen, recursive method * * @return int the total object count for the screen. */ public int getNumObjects() { int objectCount = 0; ArrayList<Object3D> children = getChildrenCopy(); for (int i = 0, j = children.size(); i < j; i++) { Object3D child = children.get(i); if (child.getGeometry() != null && child.getGeometry().getVertices() != null && child.isVisible()) if (child.getNumChildren() > 0) { objectCount += child.getNumObjects() + 1; } else { objectCount++; } } return objectCount; } }
if (mRootObject.getNumChildren() == 1) mRootObject = mRootObject.getChildAt(0);
if(mRootObject.getNumChildren() == 1 && !mRootObject.getChildAt(0).isContainer()) mRootObject = mRootObject.getChildAt(0); for(int i=0; i<mRootObject.getNumChildren(); i++) mergeGroupsAsObjects(mRootObject.getChildAt(i));
/** * Retrieve the number of triangles of the object, recursive method * * @return int the total triangle count for the object. */ public int getNumTriangles() { int triangleCount = 0; for (int i = 0, j = getNumChildren(); i < j; i++) { Object3D child = getChildAt(i); if (child.getGeometry() != null && child.getGeometry().getVertices() != null && child.isVisible()) { if (child.getNumChildren() > 0) { triangleCount += child.getNumTriangles(); } else { triangleCount += child.getGeometry().getVertices().limit() / 9; } } } return triangleCount; }
/** * Update the lights on this child's material. This method should only * be called when the lights collection is dirty. It will * trigger compilation of all light-enabled shaders. * * @param child */ private void updateChildMaterialWithLights(Object3D child) { Material material = child.getMaterial(); if(material != null && material.lightingEnabled()) material.setLights(new ArrayList<ALight>(mLights)); if(material!= null && mFogParams != null) material.addPlugin(new FogMaterialPlugin(mFogParams)); int numChildren = child.getNumChildren(); for(int i=0; i<numChildren; i++) { Object3D grandChild = child.getChildAt(i); updateChildMaterialWithLights(grandChild); } }
/** * Retrieve the number of triangles this scene contains, recursive method * * @return int the total triangle count for the scene. */ public int getNumTriangles() { int triangleCount = 0; ArrayList<Object3D> children = getChildrenCopy(); for (int i = 0, j = children.size(); i < j; i++) { Object3D child = children.get(i); if (child.getGeometry() != null && child.getGeometry().getVertices() != null && child.isVisible()) if (child.getNumChildren() > 0) { triangleCount += child.getNumTriangles(); } else { triangleCount += child.getGeometry().getVertices().limit() / 9; } } return triangleCount; }
/** * Collapse single-object groups. (Some obj exporters use g token for objects) * @param object */ private void mergeGroupsAsObjects(Object3D object) { if(object.isContainer() && object.getNumChildren()==1 && object.getChildAt(0).getName().startsWith("Object")) { Object3D child = object.getChildAt(0); object.removeChild(child); child.setName(object.getName()); addChildSetParent(object.getParent(), child); object.getParent().removeChild(object); object = child; } for(int i=0; i<object.getNumChildren(); i++) { mergeGroupsAsObjects(object.getChildAt(i)); } }
/** * Returns a {@link BoundingBox} for this Object3D and creates it if needed. * Utilizes children's bounding values to calculate its own {@link BoundingBox}. * * @return */ public BoundingBox getBoundingBox() { if (getNumChildren() > 0 && !mGeometry.hasBoundingBox()) { Vector3 min = new Vector3(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE); Vector3 max = new Vector3(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); for (int i = 0; i < getNumChildren(); i++) { Object3D child = getChildAt(i); updateMaxMinCoords(min, max, child); } if (mGeometry.getVertices() != null) { updateMaxMinCoords(min, max, this); } mGeometry.setBoundingBox(new BoundingBox(min, max)); } return mGeometry.getBoundingBox(); }
private void addShadowMapMaterialPlugin(Object3D o, ShadowMapMaterialPlugin materialPlugin) { Material m = o.getMaterial(); if(m != null && m.lightingEnabled()) { if(materialPlugin != null) { m.addPlugin(materialPlugin); } else if(mShadowMapMaterial != null) { m.removePlugin(mShadowMapMaterial.getMaterialPlugin()); } } for(int i=0; i<o.getNumChildren(); i++) addShadowMapMaterialPlugin(o.getChildAt(i), materialPlugin); }
public Object3D clone(boolean copyMaterial, boolean cloneChildren) { final Object3D clone = new Object3D(); cloneTo(clone, copyMaterial); clone.setOrientation(mOrientation); clone.setScale(getScale()); if (cloneChildren) { int childCount = this.getNumChildren(); for (int i = 0; i < childCount; i++) { clone.addChild(this.getChildAt(i).clone(copyMaterial, cloneChildren)); } } return clone; }
mGeometry.setMaterial(materials[m++]); for(int i = 0; i < mGeometry.getNumChildren(); i++) mGeometry.getChildAt(i).setMaterial(materials[Math.min(materials.length-1, m++)]);
/** * Build string representation of object hierarchy * @param parent * @param sb * @param prefix */ private void buildObjectGraph(Object3D parent, StringBuffer sb, String prefix) { sb.append(prefix).append("-->").append((parent.isContainer() ? "GROUP " : "") + parent.getName()).append('\n'); for(int i=0; i<parent.getNumChildren(); i++) { buildObjectGraph(parent.getChildAt(i), sb, prefix+"\t"); } }
/** * Retrieve the number of objects in the object, recursive method * * @return int the total object count for the object. */ public int getNumObjects() { int objectCount = 0; for (int i = 0, j = getNumChildren(); i < j; i++) { Object3D child = getChildAt(i); if (child.getGeometry() != null && child.getGeometry().getVertices() != null && child.isVisible()) if (child.getNumChildren() > 0) { objectCount += child.getNumObjects() + 1; } else { objectCount++; } } return objectCount; }
/** * Retrieve the number of objects on the screen, recursive method * * @return int the total object count for the screen. */ public int getNumObjects() { int objectCount = 0; ArrayList<Object3D> children = getChildrenCopy(); for (int i = 0, j = children.size(); i < j; i++) { Object3D child = children.get(i); if (child.getGeometry() != null && child.getGeometry().getVertices() != null && child.isVisible()) if (child.getNumChildren() > 0) { objectCount += child.getNumObjects() + 1; } else { objectCount++; } } return objectCount; } }
/** * Collapse single-object groups. (Some obj exporters use g token for objects) * @param object */ private void mergeGroupsAsObjects(Object3D object) { if(object.isContainer() && object.getNumChildren()==1 && object.getChildAt(0).getName().startsWith("Object")) { Object3D child = object.getChildAt(0); object.removeChild(child); child.setName(object.getName()); addChildSetParent(object.getParent(), child); object.getParent().removeChild(object); object = child; } for(int i=0; i<object.getNumChildren(); i++) { mergeGroupsAsObjects(object.getChildAt(i)); } }
private void addShadowMapMaterialPlugin(Object3D o, ShadowMapMaterialPlugin materialPlugin) { Material m = o.getMaterial(); if (m != null && m.lightingEnabled()) { if (materialPlugin != null) { m.addPlugin(materialPlugin); } else if (mShadowMapMaterial != null) { m.removePlugin(mShadowMapMaterial.getMaterialPlugin()); } } for (int i = 0; i < o.getNumChildren(); i++) addShadowMapMaterialPlugin(o.getChildAt(i), materialPlugin); }
public Object3D clone(boolean copyMaterial, boolean cloneChildren) { final Object3D clone = new Object3D(); cloneTo(clone, copyMaterial); clone.setOrientation(mOrientation); clone.setScale(getScale()); if (cloneChildren) { int childCount = this.getNumChildren(); for (int i = 0; i < childCount; i++) { clone.addChild(this.getChildAt(i).clone(copyMaterial, cloneChildren)); } } return clone; }
/** * Update the lights on this child's material. This method should only * be called when the lights collection is dirty. It will * trigger compilation of all light-enabled shaders. * * @param child */ private void updateChildMaterialWithLights(Object3D child) { Material material = child.getMaterial(); if (material != null && material.lightingEnabled()) material.setLights(mLights); if (material != null && mFogParams != null) material.addPlugin(new FogMaterialPlugin(mFogParams)); int numChildren = child.getNumChildren(); for (int i = 0; i < numChildren; i++) { Object3D grandChild = child.getChildAt(i); updateChildMaterialWithLights(grandChild); } }