-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NPM Support #213
Comments
I saw the #217 which implements it for v0.1.x. physi.js (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('THREE')) :
typeof define === 'function' && define.amd ? define(['THREE'], factory) :
global.physijs = factory(global.THREE);
}(this, function (THREE) {
...[physi.js code]...
})); main.js var THREE = require('three');
var physijs = require('../../node_modules/physijs/dist/physi.js');
var renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setClearColor( new THREE.Color( 0xffffff ) );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var scene = new physijs.Scene( '../../node_modules/physijs/dist/physijs-worker.js' );
var camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 100 );
camera.position.z = 10;
var sphere_geometry = new THREE.SphereGeometry( 1, 12, 12 );
var normal_material = new THREE.MeshNormalMaterial();
var sphere = new physijs.Sphere( sphere_geometry, normal_material, { mass: 0 } );
scene.add( sphere );
var box = new physijs.Box(
new THREE.BoxGeometry( 1, 1, 1 ), normal_material
, { mass: 2 }
);
box.position.set( 0.13, 3, 0 );
box.physics.linear_velocity.y = -5;
scene.add( box );
sphere.addEventListener(
'physics.newContact',
function( event ) {
console.log( 'collided at', event.relative_linear_velocity.length() );
}
);
var physics_framerate = 1000 / 60;
function onStep() {
renderer.render( scene, camera );
setTimeout( scene.step.bind( scene, physics_framerate / 1000, undefined, onStep ), physics_framerate );
}
scene.step( physics_framerate / 1000, undefined, onStep ); This throws THREE.Object3D.add: object not an instance of THREE.Object3D. pointing to
When I try it with No idea... this is a bit too much for me. Maybe someone knows more about this or can give me a hand. |
Well totally random and a few years later, I decided to randomly work on my fork -- https://github.com/agilgur5/physijs-webpack -- and now it's working with NPM. It works with webpack and browserify out-of-the-box, and should be easy to support other bundlers if needed. Uses the latest version of Physijs (v1.x I guess since v2 was never completed), a slightly modified version of the I'll leave this open since it's not in the core fork and so anyone else searching can find it more easily. Edit: I got ownership of the |
I'd love to be able to use this with Browserify/NPM, and implementing an optional module system would be really useful
The text was updated successfully, but these errors were encountered: