How to consider PIVOT when we create mesh from node or geometry
PrashantKT opened this issue · 4 comments
let's say I have following code
let plane = SCNBox(width: 12, height: 2, length: 12, chamferRadius: 0)
plane.firstMaterial?.diffuse.contents = UIColor.red
let planeNode = SCNNode(geometry: plane)
planeNode.name = "Plane1"
planeNode.pivot = SCNMatrix4MakeTranslation(0, -0.5, 0)
planeNode.geometry?.firstMaterial?.diffuse.contents = UIColor.red.withAlphaComponent(0.3)
planeNode.scale.y = 4 //SCALE FROM BOTTOM
Question : How can I create MESH from this object with Pivot ?
if there is no pivot I can easily create mesh with following code - But in Transformation pivot is not consider So the Created mesh is shifted
extension SCNNode {
var mesh: Mesh {
Mesh.init(self, materialLookup: nil)
}
var meshWithTransform:Mesh {
Mesh(self) { mat in
return mat.copy() as! SCNMaterial
}.transformed(by: c_Transform)
}
var c_Transform:Transform {
return Transform.init(offset: Vector(self.position), rotation: Rotation(self.orientation), scale: Vector(self.scale))
}
}
Could you please guide me how to solve this
Thanks in advance
@PrashantKT I wasn't aware of the pivot property, but I'll add support for it. In the meantime, if the pivot is something simple like a translation then you can probably just pre-apply it to the Mesh before you apply the node transform. Converting an arbitrary SCNMatrix to a Transform is a little more complex though.
@PrashantKT I've pushed a quick fix to the develop branch. If you check out that branch and then create a Mesh with:
let mesh = Mesh(planeNode, ignoringTransforms: false)
It should the right thing.
@nicklockwood Thanks for quick response ,I will check it
@nicklockwood Working Great !! thank you - but in dev brach some function are missing may be you removed it
But I have added manually so no issues
/// Applies a uniform inset to the faces of the mesh.
/// - Parameter distance: The distance by which to inset the polygon faces.
/// - Returns: A copy of the mesh, inset by the specified distance.
///
/// > Note: Passing a negative `distance` will expand the mesh instead of shrinking it.
func inset(by distance: Double) -> Mesh {
Mesh(polygons.insetFaces(by: distance))
}