SceneKit: how to control size of imported assets, one DAE file creates SCNNode of huge size while another is “normal”

試著忘記壹切 提交于 2019-12-10 21:23:40

问题


A designer provided the attached two DAE files created in Cinema 4D.

Both assets are of comparable size inside of Cinema 4D. Both DAE files were produced with the same export process.

Importing the DAE files into a SceneKit scene, however, produces different results.

Chango.dae imports at a "normal" size with a bounding box of ~3x4x3.

Tiki.dae imports at a huge size with a bounding box of ~155x325x140. Its dimensions inside C4D are ~122x283x142.

Questions:

1) How do you make sure assets "fit" into a SceneKit scene? Are you supposed to scale down assets with the "scale" property of the SCNNode, or are you supposed to ask the designer to make the asset of a certain size? In SpriteKit and UIKit, this is straightforward. The asset size correlates directly to its screen size (e.g., 20x20 icon takes about that much screen space depending on resolution). However, what's the analog for SceneKit? If you want an asset to fit into a 1x1x1 SCNNode, what size do you ask the designer to make the asset?

2) If your asset is too large for a scene, how do you scale it down? In UIKit, for instance, you can scale an image to fit a UIView with something like ScaleAspectFit. There doesn't seem to be an analog for a SCNNode. Using the SCNNode's scale property changes the appearance, but doesn't change the asset's bounding box. And even changing the appearance isn't precise. For instance, with Tiki.dae, the original height of the asset (as shown by the bounding box) is 324.36. If you set the Y-scale to 0.01, however, the height doesn't become ~3.24. It becomes smaller than 3, which you can prove by fitting it comfortably within a sphere of height 3 (radius of 1.5).


回答1:


If you open the Collada files you'll find that in one case distances are expressed in meters:

Chango.dae

<unit name="meter"/>

and in the other case they are expressed in centimeters:

Tiki.dae

<unit meter="0.01" name="centimeter"/>

So a value of 1 means 1m in one file and 1cm in the other. This is an asset issue that you can probably fix in Cinema 4D, or by manually editing the Collada file. You can also use the convertUnitsToMeters option to convert units at load time.



来源:https://stackoverflow.com/questions/39358586/scenekit-how-to-control-size-of-imported-assets-one-dae-file-creates-scnnode-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!