Jump to content

Uncaught TypeError: Cannot read property 'subtract' of undefined


mwpowellhtx
 Share

Recommended Posts

Hello,

I've got the following "simple" code. This will be the most complex my model gets, probably, but currently it is not working. I receive the following error when I call BABYLON.Mesh.CreateTube,

Quote

Uncaught TypeError: Cannot read property 'subtract' of undefined

//...
var tp = createArchPoints(10, 32);
var tube = BABYLON.Mesh.CreateTube('my tube', tp, 2, 12, null, BABYLON.Mesh.CAP_ALL, scene);
//...

Which my arch points are created using the very helpful Quadratic Bezier calculation.

var createArchPoints = function(dim, count) {
    var po = new BABYLON.Vector3(0,0,0); // origin
    var pc = new BABYLON.Vector3(0,0,dim); // control
    var pd = new BABYLON.Vector3(dim,0,dim); // destination
    var points = BABYLON.Curve3.CreateQuadraticBezier(po, pc, pd, count);
    return points;
}

I know the radius, will be constant; so I do not want a radius function. The points themselves, as far as I can tell, appear to be realistic, as expected.

Is there something I need to do to dress the CreateQuadraticBezier result before passing them to CreateTube?

My assumption is that one returned a Vector3[], which the other expects as a parameter, but I could be wrong, it's hard to tell sometimes with JavaScript being weakly typed.

Any other calculations I need will be along the lines of rectangles in 3D space, even with a couple of transformations and translations, but these are more straightforward in my mind.

To help with response, my level of js confidence is growing probably 4 out of 10; 3D about the same, my frame of reference are libraries like Helix Toolkit for WPF (C#) in which I've already done a similar model, just wanting to do something like that with Babylon; also loosely familiar with THREE, so probably same, 4 out of 10. That to say, I'm learning, but I can discuss halfway intelligently.

Thank you...

Regards,

Michael Powell

Link to comment
Share on other sites

I got it to work. Since Curve3 is returned from Bezier, it is necessary to access the points.

// better name for it
var createArchCurve = function(dim, count) {
    var po = new BABYLON.Vector3(0,0,0); // origin
    var pc = new BABYLON.Vector3(0,0,dim); // control
    var pd = new BABYLON.Vector3(dim,0,dim); // destination
    var points = BABYLON.Curve3.CreateQuadraticBezier(po, pc, pd, count);
    return points;
}

Following which,

var archCurve = createArchCurve(10, 32);
var tube = BABYLON.Mesh.CreateTube('my tube', archCurve.getPoints(), 0.25, 12, null, BABYLON.Mesh.CAP_ALL, scene);

After that can have fun with material, color, etc.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...