Skip to content

⬅️ Back to Table of Contents

📄 RapierHelper.js

📊 Analysis Summary

Metric Count
🔧 Functions 2
🧱 Classes 1
📦 Imports 3

📚 Table of Contents

🛠️ File Location:

📂 examples/jsm/helpers/RapierHelper.js

📦 Imports

Name Source
LineSegments three
LineBasicMaterial three
BufferAttribute three

Functions

RapierHelper.update(): void

JSDoc:

/**
     * Call this in the render loop to update the outlines.
     */

Returns: void

Calls:

  • this.world.debugRender
  • this.geometry.deleteAttribute
  • this.geometry.setAttribute
Code
update() {

        const { vertices, colors } = this.world.debugRender();

        this.geometry.deleteAttribute( 'position' );
        this.geometry.deleteAttribute( 'color' );

        this.geometry.setAttribute( 'position', new BufferAttribute( vertices, 3 ) );
        this.geometry.setAttribute( 'color', new BufferAttribute( colors, 4 ) );

    }

RapierHelper.dispose(): void

JSDoc:

/**
     * Frees the GPU-related resources allocated by this instance. Call this
     * method whenever this instance is no longer used in your app.
     */

Returns: void

Calls:

  • this.geometry.dispose
  • this.material.dispose
Code
dispose() {

        this.geometry.dispose();
        this.material.dispose();

    }

Classes

RapierHelper

Class Code
class RapierHelper extends LineSegments {

    /**
     * Constructs a new Rapier debug helper.
     *
     * @param {RAPIER.world} world - The Rapier world to visualize.
     */
    constructor( world ) {

        super();

        /**
         * The Rapier world to visualize.
         *
         * @type {RAPIER.world}
         */
        this.world = world;

        this.material = new LineBasicMaterial( { vertexColors: true } );
        this.frustumCulled = false;

    }

    /**
     * Call this in the render loop to update the outlines.
     */
    update() {

        const { vertices, colors } = this.world.debugRender();

        this.geometry.deleteAttribute( 'position' );
        this.geometry.deleteAttribute( 'color' );

        this.geometry.setAttribute( 'position', new BufferAttribute( vertices, 3 ) );
        this.geometry.setAttribute( 'color', new BufferAttribute( colors, 4 ) );

    }

    /**
     * Frees the GPU-related resources allocated by this instance. Call this
     * method whenever this instance is no longer used in your app.
     */
    dispose() {

        this.geometry.dispose();
        this.material.dispose();

    }

}

Methods

update(): void
Code
update() {

        const { vertices, colors } = this.world.debugRender();

        this.geometry.deleteAttribute( 'position' );
        this.geometry.deleteAttribute( 'color' );

        this.geometry.setAttribute( 'position', new BufferAttribute( vertices, 3 ) );
        this.geometry.setAttribute( 'color', new BufferAttribute( colors, 4 ) );

    }
dispose(): void
Code
dispose() {

        this.geometry.dispose();
        this.material.dispose();

    }