Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SceneKit custom shapes for complex ".DAE" objects

QUESTION 1:

Code to make collision with elementary object - tube works not correctly:

    let tubeGeometry = SCNTube(innerRadius: 2, outerRadius: 2.5, height: 2)
    let tubeMaterial = SCNMaterial()
    tubeMaterial.diffuse.contents = UIColor.green
    tubeGeometry.materials = [tubeMaterial]

    let tubeNode = SCNNode(geometry: tubeGeometry)
    tubeNode.position = SCNVector3(0, 0, 0)

    let tubeShape = SCNPhysicsShape(geometry: tubeGeometry, options: nil)
    let tubeBody = SCNPhysicsBody(type: .dynamic, shape: tubeShape)

    tubeNode.physicsBody?.categoryBitMask = collisionTube
    tubeNode.physicsBody?.collisionBitMask = collsionTarget
    tubeNode.physicsBody?.mass = 1
    tubeNode.physicsBody = tubeBody

    scene.rootNode.addChildNode(tubeNode)

Screenshot:

TUBE COLLISION

Why balls is on the top of object ?

QUESTION 2:

I'm carefully read the manual to use the classes SCNPhysicsShape and SCNPhysicsBody

Researched all possible ways of imposing constraints to the DAE objects. And came to the conclusion that all restrictions must be programmed complex bundles of SCNNodes in a single physical model of the object.

Found very interesting answer:

LINK

I really hope there is a way to made something like let DAEShape = SCNPhysicsShape(geometry: "*.DAE")..., otherwise the setting collisions to complex objects can take a month or more development.

For example, how to design collisions of the complex tube "DAE" object, as in the screenshot, any advices? DAE OBJECT - COMPLEX TUBE

The question is not about performance rather the ability to implement complex constraints to complex 3D objects the most straightforward way, avoiding the chore of programming...

How to set physic constraints using the vertexes, edges and faces of the "DAE" object?

I really hope that the answer will be... Thanks in advance!

like image 280
Oleg Savelyev Avatar asked Feb 21 '26 00:02

Oleg Savelyev


1 Answers

    let url = Bundle.main.url(forResource: "art.scnassets/half", withExtension: "dae")
    let sceneSource = SCNSceneSource(url: url!, options: nil)
    let tubeGeometry = (sceneSource?.entryWithIdentifier("Cube-mesh", withClass: SCNGeometry.self ))! as SCNGeometry

    tubeNode = SCNNode(geometry: tubeGeometry)
    tubeNode.position = SCNVector3(0, 1, 0)
    tubeNode.eulerAngles = SCNVector3Make(1.5, 2, 0)
    tubeNode.physicsBody = SCNPhysicsBody(type: .static, shape: SCNPhysicsShape(geometry: tubeGeometry, options: [SCNPhysicsShape.Option.type: SCNPhysicsShape.ShapeType.concavePolyhedron]))
    scene.rootNode.addChildNode(tubeNode)
like image 143
Oleg Savelyev Avatar answered Feb 23 '26 13:02

Oleg Savelyev