nicklockwood / Euclid

A Swift library for creating and manipulating 3D geometry
MIT License
639 stars 53 forks source link

Animate Path #102

Closed PrashantKT closed 1 year ago

PrashantKT commented 1 year ago

I have set of points , I create path from it

How can I animate each point of path (strokeEnd)

func createMesh(points3d:[SCNVector3]) {

    let pointIncisal = (scnView.scene?.rootNode.childNode(withName: "interIncisalPointInMandMesh", recursively: true)?.position ?? .zero)
    let modifiedPoint = points3d.map{ $0 +  pointIncisal}
    let pathPoint = modifiedPoint.map{ PathPoint(Vector($0), texcoord: nil, color: .yellow, isCurved: true)}
    let path = Path.curve(pathPoint)
    let mesh = Mesh.stroke(path,width: 0.1,detail: 4)
    let node = SCNNode(geometry: SCNGeometry(mesh))
    node.name = "NODE_MESH_PATH"
    scnView.scene?.rootNode.childNode(withName: node.name!, recursively: false)?.removeFromParentNode()
    scnView.scene?.rootNode.addChildNode(node)
}
Screenshot 2023-03-17 at 6 40 44 PM
nicklockwood commented 1 year ago

What do you mean by animate each point?

PrashantKT commented 1 year ago

Hi @nicklockwood Thanks for response let's say I have 4 Point

A, B , C ,D

so I want to animate like line form A to B in 0.2 sec , B to C in. 0.1 sec C to D in 0.4 sec

nicklockwood commented 1 year ago

I think this is outside the scope of Euclid since it does not support animation, however one approach would be to take the path created by Path.curve(pathPoint), get the individual points from the path, then use them to create a series of paths from the start to the end.

So for example if the path has 10 points, create a path from just the first 2 points, then the first 4, then the first 6, then 8, then 10. You will now have 5 paths of increasing length, and you can apply a stroke to each of these to turn them into SCNGeometries, then use an SCNAction to create a keyframe animation.

PrashantKT commented 1 year ago

@nicklockwood Thanks for your suggestion , I will try and let you know if it is working