if (result == null) result = new BoundingBox(); if (meshPrimitiveBoundingBox != null) result.combine(meshPrimitiveBoundingBox);
/** * 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; }
if (result == null) result = new BoundingBox(); computeMeshBoundingBox( meshModel, transform, result); result.combine(meshBoundingBox);
/** * 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; }
/** * Combine this bounding box with the given one * * @param other The other bounding box */ void combine(BoundingBox other) { Objects.requireNonNull(other, "The other bounding box may not be null"); minX = Math.min(minX, other.getMinX()); minY = Math.min(minY, other.getMinY()); minZ = Math.min(minZ, other.getMinZ()); maxX = Math.max(maxX, other.getMaxX()); maxY = Math.max(maxY, other.getMaxY()); maxZ = Math.max(maxZ, other.getMaxZ()); }
BoundingBox boundingBox = new BoundingBox(); for (int e = 0; e < accessorData.getNumElements(); e++) boundingBox.combine( transformedPoint[0], transformedPoint[1],
/** * 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; }