Closed chellem closed 3 years ago
It's difficult to diagnose without seeing the model. Is it possible the cube is small enough to be entirely contained by the blender object, or that they do not intersect.
If you use mesh.merge()
instead of subtract, and then display the result, do you see the two objects intersecting?
@nicklockwood
I'll give a try with the merge
and let you know.
How can I know if they not intersecting ? Is there any way of knowing the vertices? (am a bit new to it)
When doing a union
of the two, I get the my blender model and a white space beneath it.
How can I know if they not intersecting ?
I just mean visually inspect them in an SCNView and see if they occupy the same space.
When doing a union of the two, I get the my blender model and a white space beneath it.
That's odd. Can you share your blender model? Is it possible that it's not a closed surface? i.e it has holes in it?
When doing a union of the two, I get the my blender model and a white space beneath it.
That's odd. Can you share your blender model? Is it possible that it's not a closed surface? i.e it has holes in it?
Yes, it has holes with it. I have actually downloaded the model, please make a test with it.
Let me know how can I use it with open surface.
My aim is to subtract a cube from it at a specific position (vertices).
@chellem based on the example I posted in your other ticket, this code seems to work if you plug it into the Example project that ships with Euclid. The T-shirt model has a rather weird default size and position so I had to translate and scale it to get it to align with the cube, which might be why you had issues before.
// load scene
guard let url = Bundle.main.url(forResource: "T-shirt", withExtension: "usdz"),
let importedScene = try? SCNScene(url: url, options: [
.flattenScene: true,
.createNormalsIfAbsent: true,
.convertToYUp: true,
])
else {
preconditionFailure("Failed to load model")
}
// create Mesh
var importedNode = importedScene.rootNode
var mesh: Mesh!
while true {
if let geometry = importedNode.geometry {
mesh = Mesh(geometry)
break
}
guard let childNode = importedNode.childNodes.first else {
preconditionFailure("Model contained no geometry")
}
importedNode = childNode
}
// move and scale mesh
mesh = mesh
.translated(by: Vector(0, -700, 0))
.scaled(by: 0.01)
// subtract cube
let cube = Mesh.cube(size: Vector(1, 1, 2), material: UIColor.red)
mesh = mesh.subtract(cube)
// create SCNNode
let geometry = SCNGeometry(mesh)
let node = SCNNode(geometry: geometry)
scene.rootNode.addChildNode(node)
@nicklockwood Thank you. This has helped me very much.
@chellem FYI I've just released version 0.4.5 that adds a new init(url:)
method for Mesh that loads a file directly, so you can cut down some of this boilerplate.
Hello,
I've been trying to manipulate a 3D converted from blender (.obj). I could not get the subtract method to work.
Can you help me with this ?
Am not seeing any change in the initial node. What am doing wrong here?