Custom mesh between points

Hi!
I wondered how to make the plane (3D model) be tied by the sides to two objects. And he changed his position, scale and rotation with them

Update: I figured out how to change position and scale using Script Graph.

But I can’t make the correct rotation change :pensive:

Here’s the script I ended up with.

//@input SceneObject handleA
/** @type {SceneObject} */
var handleA = script.handleA

//@input SceneObject handleB
/** @type {SceneObject} */
var handleB = script.handleB

//@input SceneObject plane
/** @type {SceneObject} */
var plane = script.plane

script.createEvent('UpdateEvent').bind(function(){

  var posA = handleA.getTransform().getWorldPosition()
  var posB = handleB.getTransform().getWorldPosition()
  
  // set position
  var midPoint = posA.add(posB).mult(new vec3(.5, .5, .5))
  var planeTransform = plane.getTransform()
  planeTransform.setWorldPosition(midPoint)

  // set rotation
  var up = posA.normalize().cross(posB.normalize())
  planeTransform.setWorldRotation(quat.lookAt(posA.sub(posB), up))

  // set scale
  var distance = posA.distance(posB)
  planeTransform.setWorldScale(new vec3(1, 1, distance * .066))
  
})

Position and scale are pretty self explanatory (except I’m not sure what that multiplier is for). For the rotation, you can use the quat.lookAt method to determine how to rotate the object to align with the two control handles.

snap-plane-controller.zip (4.9 MB)

2 Likes