hapticdata / toxiclibsjs

Toxiclibsjs is a library for computational design tasks with JavaScript. This library is a port of http://toxiclibs.org for java and processing.
http://haptic-data.com/toxiclibsjs
GNU Lesser General Public License v2.1
806 stars 107 forks source link

SurfaceMeshBuilder + Sphere Circular Dependency issue in build #18

Closed hapticdata closed 11 years ago

hapticdata commented 12 years ago

Currently there is a circular dependency issue between toxi.geom.mesh.SurfaceMeshBuilder and toxi.geom.Sphere in the toxiclibs.js or toxiclibs.min.js builds. This can cause toxi.geom.Sphere#toMesh to fail.

hapticdata commented 12 years ago

Sphere#toMesh issue now only appears in rare use as an individual AMD module before using the require.js build process, at times of latency.

almostscientific commented 12 years ago

I'm having a problem with SurfaceMeshBuilder:

var mesh = new toxi.geom.Sphere(80).toMesh(null, 20);

line 5671 in toxiclibs.js

var builder = new SurfaceMeshBuilder(new SphereFunction(this)); Uncaught TypeError: undefined is not a function

hapticdata commented 12 years ago

It appears to me that you are using v0.1.0, can you please try the v0.1.1 (the current master) and confirm you are still experiencing this issue? this has been a tricky one.

almostscientific commented 12 years ago

Okay, I just downloaded the current master f54bd6a and I'm still getting the error.

hapticdata commented 12 years ago

Ok, I am able to recreate the error on my side. I've put a possible temporary workaround in this gist: https://gist.github.com/2377350

the error only persists if the mesh is constructed within the first second after window.onload is called. if there is any sort of delay first (or say the mesh is intended to be constructed by a user interaction) then it works successfully. The error occurs because at that time the module 'toxi/geom/mesh/TriangleMesh' has not yet been resolved.

this is high priority for the next release.

hapticdata commented 12 years ago

Having a hard time putting this down :) I am able to get the whole thing working (without any delay) by making TriangleMesh#getBoundingSphere an asynchronous call, which isn't a perfect solution, but might be the best possible for this type of circular dependency.

So, https://github.com/hapticdata/toxiclibsjs/tree/issue_18 the build file in that should work fine, however if in slim-chance you are going to need TriangleMesh#getBoundingSphere you will need to use it like so:

mesh.getBoundingSphere(function( sphere ) {
    console.log( sphere );
});
hapticdata commented 11 years ago

This issue has been resolved in the develop branch, without the use of asynchronous functions. It will be merged to master soon with the next release.

hapticdata commented 11 years ago

this was merged to master for v0.1.3