/** * A procedural box-shaped geometry with rounded edges and corners. * * Typically, you would: * * 1. Create a RoundedBoxGeometry instance. * 2. Generate a {@link Mesh} from the geometry. * 3. Create a {@link MeshInstance} referencing the mesh. * 4. Create an {@link Entity} with a {@link RenderComponent} and assign the {@link MeshInstance} to it. * 5. Add the entity to the {@link Scene}. * * ```javascript * // Create a mesh instance * const geometry = new RoundedBoxGeometry(); * const mesh = Mesh.fromGeometry(app.graphicsDevice, geometry); * const material = new StandardMaterial(); * const meshInstance = new MeshInstance(mesh, material); * * // Create an entity * const entity = new Entity(); * entity.addComponent('render', { * meshInstances: [meshInstance] * }); * * // Add the entity to the scene hierarchy * app.scene.root.addChild(entity); * ``` * * @category Graphics */ export class RoundedBoxGeometry extends Geometry { /** * Create a new RoundedBoxGeometry instance. * * By default, the constructor creates a box centered on the object space origin with a width, * length and height of 1 unit, edges and corners rounded with a radius of 0.1 and 8 segments * across each rounded edge. The faces are laid out as in {@link BoxGeometry}, each with UVs * in the range of 0 to 1. Each face also takes half of each rounded edge next to it, so * neighboring faces meet half way around the rounded edge. * * @param {object} [opts] - Options object. * @param {Vec3} [opts.halfExtents] - The half dimensions of the box in each axis. Defaults to * [0.5, 0.5, 0.5]. * @param {number} [opts.radius] - The radius of the rounded edges and corners. It is clamped to * the smallest half extent, where the box becomes fully rounded in that axis. A radius of 0 * generates a box identical to {@link BoxGeometry}. Defaults to 0.1. * @param {number} [opts.radiusSegments] - The number of segments across each rounded edge, * which turns through 90 degrees. Must be even, as neighboring faces meet half way around the * edge, so an odd value is rounded up. Defaults to 8. * @param {number} [opts.widthSegments] - The number of divisions of the flat part of the box * along the X axis. Defaults to 1. * @param {number} [opts.lengthSegments] - The number of divisions of the flat part of the box * along the Z axis. Defaults to 1. * @param {number} [opts.heightSegments] - The number of divisions of the flat part of the box * along the Y axis. Defaults to 1. * @param {boolean} [opts.calculateTangents] - Generate tangent information. Defaults to false. * @param {number} [opts.yOffset] - Move the box vertically by given offset in local space. Pass * 0.5 to generate the box with pivot point at the bottom face. Defaults to 0. * @example * const geometry = new RoundedBoxGeometry({ * halfExtents: new Vec3(1, 0.5, 0.5), * radius: 0.2, * radiusSegments: 12 * }); */ constructor(opts?: { halfExtents?: Vec3; radius?: number; radiusSegments?: number; widthSegments?: number; lengthSegments?: number; heightSegments?: number; calculateTangents?: boolean; yOffset?: number; }); positions: number[]; normals: number[]; uvs: number[]; uvs1: number[]; indices: number[]; } import { Geometry } from './geometry.js'; import { Vec3 } from '../../core/math/vec3.js';