Comments (10)
I believe that's in the World class file, it's an older attempt to polyfill. I will take a look soon if Marco doesn't beat me to it.
from cannon-es.
Yup, @babel/runtime
wasn't in dependencies as explained in the documentation.
However we don't need that plugin, since it only ends up saving ~100 bytes.
Should be fixed in #24, @donmccurdy you can check if it works for now using react-spring/cannon-es#fix-babel
as a version in the package.json.
from cannon-es.
Released in [email protected]
from cannon-es.
I would try to avoid eval
and Function()
, which will break for users who need a Content Security Policy.
The answer may depend on your build setup. In some cases you can configure it to output both Node.js- and Browser-friendly builds, see How to write a JavaScript package for both Node and the browser. This may be more trouble than you want for a profiling dependency.
You could also try just putting it in an if()
block. Say:
let performance;
if (typeof window !== 'undefined') {
performance = window.performance;
} else {
performance = require('perf_hooks').performance;
}
As long as the user's build system doesn't bundle a perf_hooks
implementation automatically (some bundlers do this for node.js dependencies, I think?), that shouldn't affect build size.
Finally, you could just require node.js users to provide a reference to the object when they enable profiling. Mildly inconvenient, but predictable, and unlikely to affect the majority of users.
from cannon-es.
Yes I've found a solution in #38.
It avoids us from using any polyfill.
from cannon-es.
Thanks for the quick fix! :)
I did have one error after that change:
> [email protected] test /Users/donmccurdy/Documents/Projects/three-to-cannon
> node test/index.js
/Users/donmccurdy/Documents/Projects/three-to-cannon/node_modules/cannon-es/dist/cannon-es.cjs.js:13030
performance = {};
^
ReferenceError: performance is not defined
at Object.<anonymous> (/Users/donmccurdy/Documents/Projects/three-to-cannon/node_modules/cannon-es/dist/cannon-es.cjs.js:13030:15)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/Users/donmccurdy/Documents/Projects/three-to-cannon/dist/three-pathfinding.js:1:7)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
npm ERR! Test failed. See above for more details.
This is only in my test suite, which runs in node.js, and was easy enough to patch. If you have users who are actually using cannon-es serverside, they may need the same fix. I don't see the related code in this project, perhaps it's generated in the build step somehow.
// Before importing `cannon-es` in node.js:
const {performance} = require('perf_hooks');
global.performance = performance;
from cannon-es.
Hey @donmccurdy, I'm finally getting around to this. What do you think is the best solution, considering you need to require('perf_hooks')
in Node? I can see this as an option, but not sure if there is a better way:
// Check if global window object exists to understand runtime context (browser vs node)
const hasWindow = new Function('try {return this===window;}catch(e){return false;}')
// performance.now()
const performance = hasWindow() ? (window.performance || {}) : (global.performance || {})
if (!performance.now) {
let nowOffset = Date.now()
if (performance.timing && performance.timing.navigationStart) {
nowOffset = performance.timing.navigationStart
}
performance.now = () => Date.now() - nowOffset
}
from cannon-es.
Finally, you could just require node.js users to provide a reference to the object when they enable profiling. Mildly inconvenient, but predictable, and unlikely to affect the majority of users.
Thank you for the suggestions. I'd honestly rather rely on the existing polyfill than breaking the isomorphic API parity. The conditional require should be fine, I think perf_hooks is pretty tiny.
Fixed in #35 and released in [email protected]
. Please let me know if you see any other issues.
from cannon-es.
This solution (#35) causes an issue with webpack builds #37
I'm not sure of the most elegant isomorphic solution. As mentioned above, we can manually polyfill performance
in Node environments, or change the cannon-es
API for Node environments to require passing in the perf_hooks
module.
@marcofugaro Do you have any ideas for this?
from cannon-es.
Released fix in [email protected]
from cannon-es.
Related Issues (20)
- Documentation question: After getting the red box wireframe working, and want to get gray boxes bouncing...
- ConvexPolyhedron: Tetrahedron working vs. not working HOT 3
- DisableMotor() method does not work in HingeConstraint. HOT 1
- RaycastVehicle: We have twice call updateWheelTransformWorld in updateWheelTransform(from updateVehicle) and then in castRay
- How can I get a list of bodies touching the line between two vectors?
- getVelocityAtWorldPoint() requires result parameter, despite returning result HOT 1
- Documentation for vectorToWorldFrame() incorrect
- Unknown Force is applied on some vertically stacked cubes on straight plane? HOT 3
- What are indices parameters of CANNON.Trimesh function?
- I added a model, I don't know why there is no physical characteristics
- About the basic parameter units of RaycastVehicle in canon-es
- ConvexPolyhedron isn't working for certain vertices
- The sphere flies away after a few seconds while the tab is not active HOT 1
- Implementation of third person controller. How to prevent character from rotating when moving at an angle to an incline HOT 1
- Event `collide` is only thrown once when stacked objects enter trigger HOT 1
- Make code with examples more accessible
- why the fixed body position is updated? HOT 1
- How to know when world.raycastAll has fully resolved HOT 1
- BUG: RaycastAll fails to detect sleeping and static bodies at expected y position HOT 2
- Request for Soft Body Physics Feature in Cannon-es HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cannon-es.