cannon.js | A lightweight 3D physics engine written in JavaScript | Game Engine library

 by   schteppe JavaScript Version: v0.6.2 License: MIT

kandi X-RAY | cannon.js Summary

kandi X-RAY | cannon.js Summary

cannon.js is a JavaScript library typically used in Manufacturing, Utilities, Automotive, Gaming, Game Engine applications. cannon.js has no vulnerabilities, it has a Permissive License and it has medium support. However cannon.js has 176 bugs. You can install using 'npm i cannon' or download it from GitHub, npm.

A lightweight 3D physics engine written in JavaScript.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              cannon.js has a medium active ecosystem.
              It has 4339 star(s) with 678 fork(s). There are 126 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 188 open issues and 229 have been closed. On average issues are closed in 281 days. There are 21 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of cannon.js is v0.6.2

            kandi-Quality Quality

              cannon.js has 176 bugs (0 blocker, 0 critical, 60 major, 116 minor) and 9 code smells.

            kandi-Security Security

              cannon.js has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              cannon.js code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              cannon.js is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              cannon.js releases are available to install and integrate.
              Deployable package is available in npm.
              Installation instructions, examples and code snippets are available.
              cannon.js saves you 54257 person hours of effort in developing the same functionality from scratch.
              It has 62557 lines of code, 0 functions and 255 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of cannon.js
            Get all kandi verified functions for this library.

            cannon.js Key Features

            No Key Features are available at this moment for cannon.js.

            cannon.js Examples and Code Snippets

            How to save image in local folder using Angular2?
            JavaScriptdot img1Lines of Code : 404dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import { Component, OnInit } from '@angular/core';
            import { FormGroup, FormControl, FormArray, Validators } from '@angular/forms';
            import { ActivatedRoute, ParamMap } from '@angular/router';
            import { Subscription } from 'rxjs';
            import { mi
            (FFmpeg) VP9 Vaapi encoding to a .mp4 or .webm container from given official ffmpeg example
            JavaScriptdot img2Lines of Code : 161dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            ffmpeg -vaapi_device /dev/dri/renderD128 -hwaccel vaapi -re -i http://server:port -vf 'format=nv12|vaapi,hwupload' -c:v vp9_vaapi -global_quality 50 -bf 1 -bsf:v vp9_raw_reorder,vp9_superframe -f segment -segment_time 5 -segment_format_opt
            I can see lines on a three.js object, even though wireframe is off
            JavaScriptdot img3Lines of Code : 117dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            var world, mass, body, shape, timeStep = 1 / 60,
              camera, scene, renderer, geometry, material, mesh,controls;
            initThree();
            initCannon();
            animate();
            
            function initCannon() {
              world = new CANNON.World();
              world.gravity.set(0, 0, 0

            Community Discussions

            QUESTION

            Sending a vector3 to script from patches is not working
            Asked 2020-Oct-23 at 10:21

            So I'm making a ball bounce in spark AR with cannon.js. Everything was working fine until I wanted to get the position of the forehead from the facetracker via the patch editor to a script.

            Error:

            ...

            ANSWER

            Answered 2020-Oct-23 at 10:21

            I've found a selution when working with cannon.js. cannon.js has a kind of update function so you can use .pinLastValue() because it does this every frame in order to update the physics.

            My code:

            Source https://stackoverflow.com/questions/64154964

            QUESTION

            Creating a "floor mat" type of object in Cannon.js that reacts when stepped on
            Asked 2020-Jul-21 at 11:44

            I'm just diving into Cannon.js and was wondering how to achieve this.

            My use case is that I have a circular area on the floor where if the player steps inside, they will trigger some interactions. I didn't want to do raycasting for this because I was already using Cannon.js for other collisions and felt that raycasting would add another layer of performance latency.

            Right now my player object is a simple sphere shape RigidBody that I move by setting its velocity. I made the interaction area to be a Cylinder shape with a very low height. However, when the player goes over this object, the collision gets registered successfully but the player spins out of control and there's a noticeable bump in the movement.

            Is there a standard way to register these kinds of objects for Cannon.js? I would like it so there is no bump, almost as if it's an invisible object that the player can pass through but it still registers collisions.

            ...

            ANSWER

            Answered 2020-Jul-21 at 11:44

            A typical way of solving this issue in games is the usage of triggers. So physics engines are unrelated to this topic.

            A trigger can be implemented as a simple bounding volume like a bounding sphere. In three.js, it's an instance of THREE.Sphere. Each simulation step, you test if the trigger was activated by the player. You can do this in various ways. For example by just testing if the player's position is inside the bounding sphere via Sphere.containsPoint(). Or you represent the player as another bounding volume like a bounding sphere or AABB (via THREE.Box3) and then perform an intersection test.

            Both approaches are very fast and should not noticeable affect the performance of your app. Even if you are doing these tests with more game entities who potentially activate triggers.

            Here is a simple example that demonstrates the concept of triggers in Yuka:

            https://mugen87.github.io/yuka/examples/entity/trigger/

            Source https://stackoverflow.com/questions/63010108

            QUESTION

            Cloth Simulaltion of a 3d obj cloth model
            Asked 2020-Apr-23 at 14:15

            I have seen many cloth simulations in three.js . I found it is done only with 2d plane surfaces . But is there a way that I can simulate a 3d cloth model like the one below ..

            To be simulated like a cloth in the 3d scene.

            There are many tutorials for plane 2d simualtion like

            And the code for them is given below...

            ...

            ANSWER

            Answered 2020-Apr-22 at 14:44

            The code you posted will not do clothing as it as no collisions. The code in ammo.js will but you need to generate the clothing yourself.

            Cloth is typically simulated using masses and springs

            Source https://stackoverflow.com/questions/61365561

            QUESTION

            Display loaded OBJ model in wireframe mode in three.js
            Asked 2020-Apr-20 at 15:13

            I wanted to display my loaded .obj file in wireframe mode.. I got to know about the WireFrameGeometry But for somereason the .mtl texture only gets display .

            Below is the code ..

            ...

            ANSWER

            Answered 2020-Apr-20 at 09:30
            
                     object.traverse(function(child) {
            
                         if (child.isMesh) {
            
                            child.material.wireframe = true;
            
                         }
                     }
            

            Source https://stackoverflow.com/questions/61318968

            QUESTION

            Cannon.js + Three.js: Minimal car + physics
            Asked 2020-Apr-03 at 18:36

            I'm trying to figure out how to create a minimal car with physics using Three.js and Cannon.js. I have created my visual and physics-based elements of my car and wheels, and my car responds to up arrow and left/right arrow commands to speed up and turn:

            ...

            ANSWER

            Answered 2020-Apr-03 at 18:36

            Aha, I was applying the hacky rotation to the mesh when I should have been applying it to the geometry!

            The answer below just adds one line to the vehicle.wheelInfos loop:

            Source https://stackoverflow.com/questions/61017721

            QUESTION

            How can I build cannon.js source code to get cannon.js lib
            Asked 2019-Aug-23 at 19:49

            The cannon.js project is in github url: https://github.com/schteppe/cannon.js

            But I cannot find anyways to build this source code to get cannon.js library in binary folder.

            Can you tell me the way to build this source code?

            ...

            ANSWER

            Answered 2019-Aug-23 at 19:49

            Make sure you have git, Node.js, and grunt installed.

            On the command line, do the following:

            Source https://stackoverflow.com/questions/57619645

            QUESTION

            Cannon.js lock constraint for two overlapping bodies without explosion
            Asked 2019-Aug-21 at 08:21

            I created two boxes and want to set a lock constraint but two boxes are overlapping.

            How can I set that without explosion with cannon.js?

            ...

            ANSWER

            Answered 2019-Aug-21 at 08:21

            QUESTION

            Cannon.js - How to prevent objects clipping 'floor' on update
            Asked 2019-Aug-14 at 09:30

            I'm using Cannon.js with Three.js.

            I've created a scene which consists of 1 heightfield and 5 balls. I want the balls to roll around the heightfield, using the cannon.js physics.

            On mouse move, I rotate the heightfield along the y-axis to make the spheres roll back and forth.

            I have an update loop, which copies the sphere position & quaternion from cannon.js and applies to the visual sphere of three.js. The heightfield is also updated at the same time as the three.js visual floor. Both of these run in a for loop, in requestAnimationFrame.

            ...

            ANSWER

            Answered 2018-Oct-30 at 08:41

            Directly (i.e. "instantly") setting position/rotation is likely to break collision handling in all physics engines, including cannon.js . Effectively you are teleporting things through space, causing objects to get stuck in or pass through each other.

            What you should do is

            • Set the velocity (both .velocity and .angularVelocity) or apply forces to the Cannon.js bodies
            • Copy the transform of those bodies to your visual meshes (notices this is exactly the other way around of what you are currently doing in the code)

            Determining the right amount of force to apply to get the desired visual behavior is usually the tricky part.

            Source https://stackoverflow.com/questions/53050721

            QUESTION

            Disable collision of body in Cannon.js
            Asked 2019-Apr-10 at 17:05

            I have a bunch of planes that fit together to form terrain. Each individual plane has it's own cannon.js body (I use three.js for rendering visuals) for collision. Due to memory constraints I de-render each object when the player moves to far away from the object. I can de-render objects easily in three.js just by turning them invisible, but there's no clear way to do this in cannon.js. Basically I want to disable a cannon.js object without deleting it outright.

            I've already looked through the docs and there's basically nothing on how to do this. I've also seen no questions on any form on this topic.

            Example code below to show you how I want to implement this.

            ...

            ANSWER

            Answered 2019-Apr-10 at 17:05

            To exclude a CANNON.Body from the simulation, run the following:

            Source https://stackoverflow.com/questions/55583217

            QUESTION

            A-Frame with aframe-physics-system - address cannon elements from javsascript?
            Asked 2019-Mar-16 at 10:47

            I'm in an A-Frame scene, using its underlying three.js to create objects like:

            ...

            ANSWER

            Answered 2019-Mar-16 at 10:47

            I'm quite sure you cannot add DOM attributes to js non-DOM objects, such as THREE objects.

            The static body attribute is actually creating a new object (CANNON.Body with its type set to Cannon.Body.STATIC). What aframe-physics does is synchronization - the THREE.js mesh with the Cannon.Body.

            Source code: body creation here, and syncing here.

            You could create a CANNON.Body and synchronize its position with your box, but i would approach it differently:

            You can have an empty a-frame entity with the physics attribute:

            Source https://stackoverflow.com/questions/55165899

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install cannon.js

            Just include cannon.js or cannon.min.js in your html and you're done:.
            Install the cannon package via NPM:.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/schteppe/cannon.js.git

          • CLI

            gh repo clone schteppe/cannon.js

          • sshUrl

            git@github.com:schteppe/cannon.js.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Reuse Pre-built Kits with cannon.js

            Consider Popular Game Engine Libraries

            godot

            by godotengine

            phaser

            by photonstorm

            libgdx

            by libgdx

            aseprite

            by aseprite

            Babylon.js

            by BabylonJS

            Try Top Libraries by schteppe

            p2.js

            by schteppeJavaScript

            poly-decomp.js

            by schteppeJavaScript

            gpu-physics.js

            by schteppeJavaScript

            ammo.js-demos

            by schteppeJavaScript

            imgui-wasm

            by schteppeC++