/** * Compute the bounding box of the given {@link GltfModel}. The result * will be an array <code>[minX, minY, minZ, maxX, maxY, maxZ]</code>. * * @param gltfModel The {@link GltfModel} * @return The bounding box */ public static float[] computeBoundingBoxMinMax(GltfModel gltfModel) { Objects.requireNonNull(gltfModel, "The gltfModel may not be null"); BoundingBoxComputer boundingBoxComputer = new BoundingBoxComputer(gltfModel); BoundingBox boundingBox = boundingBoxComputer.compute(); float result[] = { boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ() }; return result; }
/** * Recursively compute the bounding box of the {@link MeshPrimitiveModel} * objects of all {@link MeshModel} objects in the given {@link SceneModel} * (including the respective global node transforms). * If the given result is <code>null</code>, then a new bounding box * will be created and returned. * * @param sceneModel The {@link SceneModel} * @param transform The root transform, as a column major 4x4 matrix * @param boundingBox The optional bounding box that will store the result * @return The result */ private BoundingBox computeSceneBoundingBox( SceneModel sceneModel, float transform[], BoundingBox boundingBox) { BoundingBox localResult = boundingBox; if (localResult == null) { localResult = new BoundingBox(); } List<NodeModel> nodeModels = sceneModel.getNodeModels(); for (NodeModel nodeModel : nodeModels) { computeNodeBoundingBox(nodeModel, transform, localResult); } return localResult; }
/** * Compute the bounding box of the {@link GltfModel} * * @return The bounding box */ BoundingBox compute() { BoundingBox boundingBox = new BoundingBox(); List<SceneModel> sceneModels = gltfModel.getSceneModels(); for (SceneModel sceneModel : sceneModels) { float rootTransform[] = MathUtils.createIdentity4x4(); computeSceneBoundingBox(sceneModel, rootTransform, boundingBox); } return boundingBox; }
computeMeshBoundingBox( meshModel, transform, result); result.combine(meshBoundingBox); for (NodeModel child : children) computeNodeBoundingBox(child, transform, result);
computeBoundingBox(meshPrimitiveModel, transform); if (meshPrimitiveBoundingBox != null)