Engine API Reference - v2.7.3
    Preparing search index...

    Class BoxGeometry

    A procedural box-shaped geometry.

    Typically, you would:

    1. Create a BoxGeometry instance.
    2. Generate a Mesh from the geometry.
    3. Create a MeshInstance referencing the mesh.
    4. Create an Entity with a RenderComponent and assign the MeshInstance to it.
    5. Add the entity to the Scene.
    // Create a mesh instance
    const geometry = new pc.BoxGeometry();
    const mesh = pc.Mesh.fromGeometry(app.graphicsDevice, geometry);
    const material = new pc.StandardMaterial();
    const meshInstance = new pc.MeshInstance(mesh, material);

    // Create an entity
    const entity = new pc.Entity();
    entity.addComponent('render', {
    meshInstances: [meshInstance]
    });

    // Add the entity to the scene hierarchy
    app.scene.root.addChild(entity);

    Hierarchy (View Summary)

    Index

    Constructors

    • Create a new BoxGeometry instance.

      By default, the constructor creates a box centered on the object space origin with a width, length and height of 1 unit and 1 segment in either axis (2 triangles per face). The box is created with UVs in the range of 0 to 1 on each face.

      Parameters

      • Optionalopts: {
            calculateTangents?: boolean;
            halfExtents?: Vec3;
            heightSegments?: number;
            lengthSegments?: number;
            widthSegments?: number;
            yOffset?: number;
        } = {}

        Options object.

        • OptionalcalculateTangents?: boolean

          Generate tangent information. Defaults to false.

        • OptionalhalfExtents?: Vec3

          The half dimensions of the box in each axis. Defaults to [0.5, 0.5, 0.5].

        • OptionalheightSegments?: number

          The number of divisions along the Y axis of the box. Defaults to 1.

        • OptionallengthSegments?: number

          The number of divisions along the Z axis of the box. Defaults to 1.

        • OptionalwidthSegments?: number

          The number of divisions along the X axis of the box. Defaults to 1.

        • OptionalyOffset?: number

          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.

      Returns BoxGeometry

      const geometry = new pc.BoxGeometry({
      halfExtents: new pc.Vec3(1, 1, 1),
      widthSegments: 2,
      lengthSegments: 2,
      heightSegments: 2
      });

    Properties

    blendIndices: undefined | number[]

    Blend indices.

    blendWeights: undefined | number[]

    Blend weights.

    colors: undefined | number[]

    Colors.

    Methods