Line to 3D object
Nilesh04 opened this issue · comments
Hello @nicklockwood
I have polyline now i want to convert it to 3d object. So that I can rotate it.
Is there any way with you library to achieve it ?
As I can see in notes, But How can I use it ?
A Path is a sequence of PathPoints representing a line or curve formed from straight segments joined end-to-end. A Path can be either open (a polyline) or closed (a polygon), but should not be self-intersecting or otherwise degenerate.
Paths may be formed from multiple subpaths, which can be accessed via the subpaths property.
A closed, flat Path without nested subpaths can be converted into a Polygon, but it can also be used for other purposes, such as defining a cross-section or profile of a 3D shape.
Paths are typically 2-dimensional, but because PathPoint positions have a Z coordinate, they are not required to be. Even a flat Path (where all points lie on the same plane) can be translated or rotated so that its points do not necessarily lie on the XY plane.
@Nilesh04 You can use Mesh.extrude() or Mesh.lathe(), etc. depending on what kind of 3D shape you want to create from the polyline.
Ok @nicklockwood
Thank you for quick response. Let me check this methods.
If I am right I need to pass array of points i.e. x,y,z
Right ?
@nicklockwood Is it the right way to do polyline to 3D object. It is on live camera i.e. ARKit
var drawingNode: SCNNode?
drawingNode = SCNNode()
var data = [PathPoint]()
data.append(PathPoint(Vector(99.6176, 0.16275197, 8.736245), isCurved: false))
data.append(PathPoint(Vector(99.6451, 0.16890676, 8.416687), isCurved: false))
data.append(PathPoint(Vector(99.680084, 0.1592451, 7.9918666), isCurved: false))
data.append(PathPoint(Vector(99.6957, 0.14947532, 7.794631), isCurved: false))
data.append(PathPoint(Vector(99.72096, 0.10061771, 7.464483), isCurved: false))
data.append(PathPoint(Vector(99.72513, 0.0815701, 7.4087462), isCurved: false))
data.append(PathPoint(Vector(99.736046, 0.07609548, 7.260345), isCurved: false))
data.append(PathPoint(Vector(99.768425, 0.0736808, 6.800977), isCurved: false))
data.append(PathPoint(Vector(99.79159, 0.084656745, 6.4521675), isCurved: false))
data.append(PathPoint(Vector(99.803505, 0.07794015, 6.2653117), isCurved: false))
data.append(PathPoint(Vector(99.83454,0.05711637, 5.7497005), isCurved: false))
let pa = Path(data)
let mesh = Mesh.extrude(pa, material: UIColor.red)
// create SCNNode
let geometry = SCNGeometry(mesh) {
let material = SCNMaterial()
material.diffuse.contents = $0 as? UIColor
return material
}
let node = SCNNode(geometry: geometry)
self.sceneLocationView.scene.rootNode.addChildNode(node)
Yes, although it's a laborious way to write the polyline code. You can just write:
let path = Path([
.point(Vector(...)),
.point(Vector(...)),
....etc
])
I'm not sure why your polyline points have x y and z coordinates though. If the path points are not flat on a plane then it can't be extruded, so maybe you are trying to do something else?