Jump to content

Shape support or...


Butterwell
 Share

Recommended Posts

I've got some code in THREE.js that uses the Shape abstraction. I haven't been able to figure out how to do a similar thing in Babylon.js at this level of abstraction. My code does thus to create a fat arc (a 2D geometry/mesh):

function fatArcGeometry(bandWidth, radius, radians) {
    const outerRadius = radius + (bandWidth/2)
    const innerRadius = radius - (bandWidth/2)
    var arcShape = new THREE.Shape();
    arcShape.moveTo( outerRadius, 0 );
    arcShape.absarc( 0, 0, outerRadius, 0, radians, false );
    arcShape.lineTo( Math.cos(radians)*innerRadius, Math.sin(radians)*innerRadius );
    arcShape.absarc( 0, 0, innerRadius, radians, 0, true );
    
    var geometry = new THREE.ShapeBufferGeometry( arcShape );
    
    return geometry
}

Is there a similar abstraction or... what are the Babylon building blocks to build a 2D fat arc?

Link to comment
Share on other sites

Got it to work.

http://www.babylonjs-playground.com/#9BWQ4C

The meat of the solution:

    var r1 = 3; // inner radius
    var r2 = 5; // outer radius
    var segments = 4;
    var points = segments + 1;

    var arc1 = [];
    var arc2 = [];
    var radians = Math.PI
    for (var i = 0; i < points; i++) {
        arc1.push(new BABYLON.Vector3(r1*Math.cos(radians*i/segments), r1*Math.sin(radians*i/segments), 0));
        arc2.push(new BABYLON.Vector3(r2*Math.cos(radians*i/segments), r2*Math.sin(radians*i/segments), 0));
    }

 

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...