设计师提供了在Cinema 4D 中创建的两个 DAE 文件。
这两种资产在 Cinema 4D 中的大小相当。两个 DAE 文件都是使用相同的导出过程生成的。
但是,将 DAE 文件导入 SceneKit 场景会产生不同的结果。
Chango.dae 以“正常”大小导入,边界框为 ~3x4x3。
Tiki.dae 以大尺寸导入,边界框约为 155x325x140。它在 C4D 中的尺寸约为 122x283x142。
问题:
1) 您如何确保资产“适合”SceneKit 场景?您是应该使用 SCNNode 的“缩放”属性来缩小资产,还是应该要求设计者制作一定大小的资产?在SpriteKit和 中UIKit,这很简单。资产大小与其屏幕大小直接相关(例如,20x20 图标占用大约那么多屏幕空间,具体取决于分辨率)。然而,什么是模拟SceneKit?如果您希望资产适合 1x1x1 SCNNode,您要求设计师制作什么尺寸的资产?
2)如果你的资产对于一个场景来说太大了,你如何缩小它?UIKit例如,在 中,您可以缩放图像以适合UIView类似ScaleAspectFit. 似乎没有 a 的类似物SCNNode。使用 SCNNode 的scale属性会更改外观,但不会更改资产的边界框。甚至改变外观也不精确。例如,对于 Tiki.dae,资产的原始高度(如边界框所示)为 324.36。但是,如果将 Y 比例设置为 0.01,则高度不会变为 ~3.24。它变得小于 3,您可以通过将其舒适地安装在高度为 3(半径为 1.5)的球体中来证明这一点。
我正在使用带有ARKit的SceneKit,现在有一个简单的应用程序,我点击屏幕,它为我的场景添加了一个ARAnchor和一个SCNNode.
在某些时候,我会想要移动整个场景,所以我尝试改变sceneView.scene.rootNode.position.x += 10来测试它.如果我在任何特定节点上调用它,该节点确实会正确移动.但是调用它rootNode,没有任何反应,我希望每个子节点(场景中的每个节点)都随之移动.
为什么我的其他节点没有正确移动,我能做些什么来解决这个问题?或者我在考虑这个错误?
我知道如何在SceneKit中的单个节点中创建一系列SCNActions。但我想知道,如何制作具有不同节点的SCNAction序列?例如
我找到了一个SpriteKit的例子,但我不能使用它,这个... 用不同的节点运行 SKActions 序列
一个序列的代码如下
var sequence = [SCNAction] ()
let force = SCNVector3(0.0, 0.0, -1.0)
let move = SCNAction.move(by: force!, duration: 1.5)
squence.append(move)
let actions = SCNAction.sequence(squence)
nodeSelected?.runAction(actions)
Run Code Online (Sandbox Code Playgroud) How do you define the material on a custom geometry from vertex data, so that it renders the same as 'typical' SCNNodes?
In this scene there are
The red and blue spheres render as I would expect. The two points / spheres in the custom geometry are black.
Why? …
我如何返回用于设置 SCNNode 的球体几何(SCNSphere)的半径。我想在我移动一些与父节点相关的子节点的方法中使用半径。下面的代码失败了,因为结果节点似乎不知道半径,我不应该将节点传递给方法吗?
我的数组索引也失败了,说 Int 不是一个范围。
我想建立的东西,从这个
import UIKit
import SceneKit
class PrimitivesScene: SCNScene {
override init() {
super.init()
self.addSpheres();
}
func addSpheres() {
let sphereGeometry = SCNSphere(radius: 1.0)
sphereGeometry.firstMaterial?.diffuse.contents = UIColor.redColor()
let sphereNode = SCNNode(geometry: sphereGeometry)
self.rootNode.addChildNode(sphereNode)
let secondSphereGeometry = SCNSphere(radius: 0.5)
secondSphereGeometry.firstMaterial?.diffuse.contents = UIColor.greenColor()
let secondSphereNode = SCNNode(geometry: secondSphereGeometry)
secondSphereNode.position = SCNVector3(x: 0, y: 1.25, z: 0.0)
self.rootNode.addChildNode(secondSphereNode)
self.attachChildrenWithAngle(sphereNode, children:[secondSphereNode, sphereNode], angle:20)
}
func attachChildrenWithAngle(parent: SCNNode, children:[SCNNode], angle:Int) {
let parentRadius = parent.geometry.radius //This fails cause geometry …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 SceneKit 中制作一个管子及其物理体。
let BoxGeometry = SCNTube(innerRadius: 5, outerRadius: 12.5, height: 4)
Box = SCNNode(geometry: BoxGeometry)
Box.pivot = SCNMatrix4MakeRotation(Float(M_PI_2/8), 0, 1, 0)
Box.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Static, shape: nil)
Box.physicsBody?.mass = 5
Box.categoryBitMask = colorCategory
scene.rootNode.addChildNode(Box)
Run Code Online (Sandbox Code Playgroud)
然而,当另一个物体落在这个物体上时,它不会通过中心。相反,它似乎悬浮在空气中。它的作用就像物理体是一个完整的圆柱体,而不是中间有孔的管子。我该如何解决这个问题,以便物体可以通过中心?管子外观符合预期。
谢谢!
我有我的相机的位置和方向,屏幕上的 CGPoint 触摸位置,我需要在我的 3d SCNNode 环境中我在屏幕上触摸的方向上的线(最好是矢量),我怎样才能得到这个?
代码片段将非常有帮助。
我试图弄清楚如何以编程方式为 ARKit(XCode 9 / Swift 4)场景中的某个对象(SCNNode)分配材质。我正在尝试以编程方式执行此操作,因为我希望使用太多变体(或用户生成的图像)来渲染相同形状的对象,以便能够通过场景中的菜单分配来执行此操作。该对象只是一个立方体 - 现在,我只是试图让一侧显示从 Assets 文件夹中提取的材料。
这是我尝试引用以前的 Stack 帖子的当前代码,但对象只是保持白色。
let material = SCNMaterial()
material.diffuse.contents = UIImage(named: "texture.jpg")
let nodeObject = self.lastUsedObject?.childNode(withName: "box", recursively: true)
// I believed this lets me grab the last thing I rendered in an ARKit scene - please
// correct me if I'm wrong. My object is also labeled "box".
nodeObject?.geometry?.materials
nodeObject?.geometry?.materials[0] = material // I wanted to grab the first face of the box
Run Code Online (Sandbox Code Playgroud)
非常感谢您!我一直在摆弄这个一段时间,但我似乎无法掌握 Swift 中 3D 对象/场景的编程方法。
我知道当节点扩展时 SCNPhysicsBody 不会扩展,但我还没有找到解决这个问题的好方法。我想缩放节点,然后在缩放后将 SCNPhysicsBody 更新为节点。
let box = SCNBox(width: 0.2, height: 0.3, length: 0.4, chamferRadius: 0.1)
box.firstMaterial?.diffuse.contents = UIColor.blue
var boxNode = SCNNode(geometry: box)
boxNode.scale = SCNVector3(0.5, 0.5, 0.5)
boxNode.position.x += 0.5
boxNode.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.static, shape: SCNPhysicsShape(geometry: box, options: nil))
sceneView.scene.rootNode.addChildNode(boxNode)
Run Code Online (Sandbox Code Playgroud)
有没有人想出一个很好的解决方案来解决这个问题?
我正在尝试扫描参考图像,然后在打印的参考图像上方显示图像本身。“虚拟”图像尺寸应与打印尺寸相同。
我的想法:获取打印的参考图像的大小,然后将图像缩放SCNNode到此大小(或将 SCNNode 缩放到此大小?)
但是:1-> 如何获得打印图像的大小,2-> 缩放SCNNode我也需要这个节点的大小。如何获得?
import UIKit
import SceneKit
import ARKit
import AVKit
import AVFoundation
class ViewController: UIViewController, ARSCNViewDelegate {
@IBOutlet var sceneView: ARSCNView!
private var planeNode: SCNNode?
private var imageNode: SCNNode?
private var animationInfo: AnimationInfo?
private var currentMediaName: String?
private var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
let scene = SCNScene()
sceneView.scene = scene
sceneView.delegate = self
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Load reference images to look for …Run Code Online (Sandbox Code Playgroud)