GrayFox

Cylinder between two points

Recommended Posts

Hi Wingnut

But to modify the extrusions every time the user changes the sizes the mesh is never completed. It has to call flat shade after every update.

I'm trying to get a shape like this

      shape = [
                           new BABYLON.Vector3(-50,  -50,0),
                           new BABYLON.Vector3(50,  -50,0),
                           new BABYLON.Vector3(20,  50,0),
                           new BABYLON.Vector3(-20, 50,0)
                    ];

Is there any way of using the ExtrudeShape or similar but keep flat sides?

Thanks

Share this post


Link to post
Share on other sites

ExtrudeShape can't add flat sides automatically as this is an expensive process

But you can use shaders to do the work for you :)

https://www.babylonjs-playground.com/#165IV6#166

 

By removing the normals you will force the shaders to compute them and it will do it in flat mode

Share this post


Link to post
Share on other sites

Hi Deltakosh

That will probably save a lot of thinking!

I have been going down the PolygonMeshBuilder route as this was making flat sides by default?

I have hacked together this https://www.babylonjs-playground.com/#PTTMVI#21

With a bit of trial and error which seems to let you move one of the original vertex numbers and it modifies the other end of the extrusion.

I need this for resizing the glass that goes between my beams but your method above will work for changing the length of the beams.

Thanks!

Share this post


Link to post
Share on other sites

Hi I'm still struggling!

I have tried to use the comments in this thread to make a frame with 4 sides but one side is not working.

I tried swapping the start point for that one side as suggested in one comment but that spins the shape around.

There must be a cleaner approach to this?

http://www.babylonjs-playground.com/#1RWE59#117

Thanks

Share this post


Link to post
Share on other sites

Hi John

Thanks for your reply. The problem is this frame will get a lot more complex so I wanted to work in angles from the corner points to reduce the amount of code later. It might not be a square, it can have 3 to any number of sides and be any shape.

If I use the cylinder the one side seems in the right position if I don't setPivotMatrix

http://www.babylonjs-playground.com/#1RWE59#121

But if setting setPivotMatrix it goes wrong. I don't get it.

http://www.babylonjs-playground.com/#1RWE59#120

 

Share this post


Link to post
Share on other sites

I do not think your problem is with the pivot. I have tapered and coloured your cylinders. The first cylinder is red and they get less green as you create them. You can see that the direction of rotation is not consistent. This is because in two case your v1 and v2 are parallel and do the cross product is zero giving a zero axis and so rotation is indeterminate.

https://www.babylonjs-playground.com/#1RWE59#122

Interestingly I have been working on a different problem but there are similarities. It was about drawing a line with width along given points.

https://www.babylonjs-playground.com/#FA2H7X#1

There is likely to be a way of doing this with an extrusion between points though not sure exactly with what will happen at corners. It might be worth you having a play and I will have a look over the next few days.

Good luck

 

Share this post


Link to post
Share on other sites

@Pryme8 +1 for new avatar. ok, what now? Ok caught up. Yeah, Blender model import is pretty good but -> ah yeah: how to import #'s from AutoCAD?

@captainleighwalker Do you need AutoCAD importer? That would be cool... ping @JCPalmer . Is it even possible? Peace out... from the infinite thread. : )

Share this post


Link to post
Share on other sites

Someone help me fine the post that I was helping I think @Arte with where we were coming up with functions for making dynamic/parametric cabinets.

I found his demo post, but cant find the discussion we had that lead him to it.

That conversation has all the examples you will need.

Share this post


Link to post
Share on other sites

@captainleighwalker Have had a play around and have made a frameMaker function.

The profile of the frame is given as an array of Vector3s with all zs 0, ie give profile in XoY plane.

The path of the frame is given in terms of its outer edge as an array of Vector3s again in the XoY plane.

The leftmost point(s) of the profile will follow the path so the left hand side of the profile forms the outer edge of the frame.

You need to pass the profile and path as options

var frame = frameMaker("frame", {path: path, profile:profilePoints}, scene);

The direction of the path (clockwise or counter-clockwise) determines the orientation of the profile around the frame.

If it turns out you need to flip the profile then reverse the path array before passing to frameMaker.

myPath.reverse();

Hope this is useful https://www.babylonjs-playground.com/#1RWE59#124

Share this post


Link to post
Share on other sites
13 minutes ago, captainleighwalker said:

Would you mind adding/explaining how you used the dot and cross of the vectors?

The function was based on work I did last year so whilst at the time I knew exactly what I was doing I cannot remember all the details, for example why I did Math.PI - calculated angle rather than just angle. However the basic idea goes like this.

Given a polygon of lines you need to know the internal angle A between between two lines L and K meeting at a point P. Just using the dot product you do not know if you are getting the internal or external angle at point P. However using a cross product will tell you which.

Just be consistent in moving around the polygon in a clockwise or counter clockwise direction, say K follows L., so always use L before K and find the line normal to L, say N.

As L is in XoY plane one way to find N is to swap the x and y coordinates of L and make one negative (x, y).(y, -x) = xy - xy = 0 so must be perpendicular.

Taking (consistently in order) the cross product of L and N this will give you a vector in the z direction (either positive or negative). Whether it is positive or negative determines whether you have found and internal or external angle.

If P is an outer point of the frame and Q an inner point on the frame with the width between P and Q being we need to project Q onto the line R parallel to L but a distance w from it using angle A.

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.