Giter Club home page Giter Club logo

Comments (3)

jcyuan avatar jcyuan commented on August 17, 2024 1

lib will soon has some APIs to provide raw geometry data as lines. so that you can draw these lines in your rendering engine to visualize easily.

the data from THREE usually wont match with the physics mesh because usually physic mesh will be much simpler then the actually game world geometry. so, better draw physics world with the data from physics world but not from your THREE world.

from rapier.js.

jcyuan avatar jcyuan commented on August 17, 2024

i think it should work as long as the THREE model is in the world space, because the TriMesh is in world space, besides, you probably have to consider for the unit conversion between them, TriMesh: meter, THREE: vector.
you can try to visualize it. 👍

from rapier.js.

sylwesterdigital avatar sylwesterdigital commented on August 17, 2024

Not sure if this would be a right place to ask, if RAPIER.ColliderDesc.trimesh(vertices, indices) is fully implemented or this is still on the roadmap? I tried load a simple model 3D of the cube:
Screenshot 2023-09-12 at 23 24 48

import('@dimforge/rapier3d').then(rapierModule => {


    setupScene()


    RAPIER = rapierModule;
    console.log("initRapier()");

    let gravity = { x: 0.0, y: -2.1, z: 0.0 };
    let world = new RAPIER.World(gravity);
    const eventQueue = new RAPIER.EventQueue(true);

    // Load the 3D model using Three.js's GLTFLoader
    const loader = new GLTFLoader();

    loader.load('models/floor1.glb', function (gltf) {

      scene.add(gltf.scene)

      const model = gltf.scene.children[0].geometry;

          // Ensure vertices and indices are correctly defined and formatted
          const vertices = new Float32Array(model.attributes.position.array);

          let indices;
          if (model.index) {
              indices = new Uint32Array(model.index.array);
          } else {
              // Handle unindexed geometry by generating indices
              indices = new Uint32Array([...Array(vertices.length / 3).keys()]);
          }


          console.log('Vertices:', vertices);
          console.log('Indices:', indices);

        try {
            const trimesh = new RAPIER.TriMesh(vertices, indices);
            console.log('TriMesh created successfully', trimesh);

            const isValid = validateMapping(trimesh.vertices, trimesh.indices);
            console.log("isValid",isValid)

            console.log('Vertices length:', vertices.length);
            console.log('Indices length:', indices.length);


            let groundColliderDesc = RAPIER.ColliderDesc.trimesh(trimesh)
            //     // .setTranslation(0, groundHeight, 0)
            //     // .setActiveEvents(RAPIER.ActiveEvents.COLLISION_EVENTS);

            let groundCollider = world.createCollider(groundColliderDesc);


            init()

            window.groundColliderHandle = groundCollider.handle;
            window.myRapierWorld = world;
            window.eventQueue = eventQueue;
            


        } catch (error) {
            console.error('Failed to create TriMesh:', error);
        }
    });
});

got this errors:
Screenshot 2023-09-12 at 23 26 54

Any clue?

from rapier.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.