68989

Modify the Bounding Box Size of 3D model

Question:

This function is supposed to add a 3D model to screen in a confined space:

func addCharacter(gridPosition: SCNVector3, levelNode: SCNNode){ let carScene = SCNScene(named: "assets.scnassets/Models/cube.dae") // Create a material using the model_texture.tga image let carMaterial = SCNMaterial() carMaterial.diffuse.contents = UIImage(named: "assets.scnassets/Textures/model_texture.tga") carMaterial.locksAmbientWithDiffuse = false // Create a clone of the Car node of the carScene - you need a clone because you need to add many cars let carNode = carScene!.rootNode.childNodeWithName("Cube", recursively: false)!.clone() as SCNNode carNode.name = "Cube" carNode.position = gridPosition // Set the material carNode.geometry!.firstMaterial = carMaterial // Create a physicsbody for collision detection let carPhysicsBodyShape = SCNPhysicsShape(geometry: SCNBox(width: 0.30, height: 0.20, length: 0.16, chamferRadius: 0.0), options: nil) carNode.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Kinematic, shape: carPhysicsBodyShape) carNode.physicsBody!.categoryBitMask = PhysicsCategory.Car carNode.physicsBody!.collisionBitMask = PhysicsCategory.Player levelNode.addChildNode(carNode) }

The code works if I change the dimensions of the dae file before adding it to Xcode, and by dimensions I mean the Bounding Box Size property of Xcode. I wanted to know if It was possible to change this bounding box size directly from Xcode. It does not seem possible from the UI. Is it possible with code? Or, even better, scale down the object maintaining proportions to a size for the XYZ between the range 0.3 -> 0.7? At the moment my objects show a box size of over 45 for XYZ. Furthermore, If I was to use a .scn file instead of a .dae in the code above, would that still work?

EDIT: If I change the size via code, would it have an impact on efficiency? I notice that for larger .dae models the fps drops from 60 to 30 and the game slows down.

Answer1:

Changing carNode's scale property will reduce the apparent size of the car.

However, I think you'll be ahead to load your .DAE into the Xcode scene editor. That will allow you to scale it down ahead of time (in the Node Inspector, option-command-3). You can also, if you want, add your texture. Then save it as a .SCN file, which is compressed and should load faster.

Changing the scaling, either in code or in the Xcode scene editor, won't affect efficiency. Reducing the complexity of the car (the number of polygons/vertices) will speed things up, though.

Consider creating SCNLevelOfDetail instances for your car node. That will cause the renderer to use substitute, lower resolution geometry when the node is far from the camera. The WWDC 2014 slide deck demonstrates this, slide 38, AAPLSlideLOD.m.

Recommend

  • m2crypto: python 2.7 compatibility and which version of OpenSSL to use?
  • How to set up a java program in IDEone
  • AndEngine: Handling collisions with TMX Objects
  • Angular dynamic component loading
  • What RDF patterns can be used to represent components and the percentage they make up?
  • How to deal with xxx~HEAD after git merge?
  • How to realize with WinForms in C# something like an image with map areas in a homepage (at hooverin
  • UUID into unsigned int
  • Determine if a mesh is inside another mesh in threejs
  • Is there a greater chance to collide when comparing GUIDs based on a hash vs \"Guid.NewGuid()?
  • Git Merge Adds New File Instead of Conflict Markers - CONFLICT (rename/add)
  • Efficiently getting XML into Elasticsearch
  • CSS - how to trim text output?
  • Nested not working on slide
  • Load 24 bit TGA
  • How to know if a JFrame is on screen in a multi screen environment
  • how to resolve OAuthException: (#100)
  • How to get a table cell value using jQuery
  • Updating one element of a bound Observable collection
  • Nodejs bluebird promise fails while processing image
  • How to remove all of a jQuery UI dialog when it is closed
  • d3.js: why is d3.geo.path() giving NaN?
  • Negating Regex PO BOX
  • How to use animated gif in Firemonkey?
  • MultiLevel ExpandableListView not highlighting properly
  • jQuery - resize an elements height to match window without refreshing, on window resize
  • using html data-attributes as css-variable (i.e. text-shadow)
  • Drawing a Path in XAML (with binding) vs. C#. One works, one doesn't
  • chrome video src change not working
  • WPF Template Binding in ToggleButton UserControl
  • WPF version of .ScaleControl?
  • blade.php method outputting it's result to the form
  • D3 get axis values on zoom event
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • How to set/get protobuf's extension field in Go?
  • How to show dropdown in excel using jrxml (jasper api)?
  • RestKit - RKRequestDelegate does not exist
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • python draw pie shapes with colour filled