I’m trying to draw stylized arrows along a bezeir curve. I understand drawLine
is only meant for debugging, so I had to think of another way to draw my curve. (I’d prefer not to draw individual objects as line segments, but that might be a decent fallback if I can’t get this to work…)
Here’s a test project that shows my struggle:
https://playcanvas.com/project/977132/overview/arrows
I can’t embed images in my post, they are referenced inline below and here’s an album with all my screenshots in the order I mention them in this post:
The idea I came up with was to use a rigged mesh. I’ve got a nice 3D arrow mesh, and I rigged it in Blender.
See image 1, RgFw5Mg
I exported it as an FBX and imported into PC.
In PC, I can verify the rig is working by rotating the child bones:
See image 2, B9y3DDw
…so far, so good.
Here’s my scene without my mesh, with just the debug line drawn:
See image 3, byOnKZ0
Here, I’m looping through the points on my line and just setting the next bone position at each point:
for(var i = 0; i < lut.length - 1; i++){
var current = new pc.Vec3(lut[i].x, lut[i].y, lut[i].z);
var next = new pc.Vec3(lut[i+1].x, lut[i+1].y, lut[i+1].z);
// Draw debug curve
this.app.drawLine(current, next, pc.Color.RED);
// Attempt to set bone position
currentBone.setPosition(current);
//...snip
See image 4, U1BeGp5
See image 5, X0CsY3p
This almost doesn’t look bad, but I want to rotate the bones so they flow better:
for(var i = 0; i < lut.length - 1; i++){
var current = new pc.Vec3(lut[i].x, lut[i].y, lut[i].z);
var next = new pc.Vec3(lut[i+1].x, lut[i+1].y, lut[i+1].z);
// Draw debug curve
this.app.drawLine(current, next, pc.Color.RED);
// Attempt to set bone position AND ROTATION
currentBone.setPosition(current);
currentBone.lookAt(next);
See image 6, YnPxbjL
See image 7, kZvd45H
The first and last bones always points up, no matter what I do. I can set the rotation of that last bone to anything, it has no effect whatsoever. That last bone just won’t rotate!
I’ve tried rigging and re-rigging in Blender, and exported the rig about a thousand times with different settings each time. No matter what I do, the “lookAt” on the first bone and the last bone always points upward.
I feel like there’s a trick, maybe something to do with localRotation, but I’m not smart enough to calculate the proper rotation values for each bone.
Any ideas? What else can I try? Is there a different way I should approach this problem? I just want to have some stylized, curvy arrows drawn from code.
Thanks so much! I’m a huge fan of PlayCanvas since I started using it a few weeks ago, I’ve loved every step of the way until now.