scenekit

SceneKit - how to get animations for a .dae model?

我的梦境 提交于 2019-12-03 09:56:50
问题 Ok, I am working with ARKit and scene kit here and I am having trouble looking at the other questions dealing with just scene kit trying to have a model in .dae format and load in various animations to have that model run - now that we're in iOS11 seems that some solutions don't work. Here is how I get my model - from a base .dae scene where no animations are applied. I am importing these with Maya - var modelScene = SCNScene(named: "art.scnassets/ryderFinal3.dae")! if let d = modelScene

SceneKit - Map cube texture to box

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've a texture for a cube that looks like I'd like to use it on a cube in a SceneKit view. I'm using the SceneKit geometry SCNBox for that. Unfortunately, the result is that the texture is projected entirely on each face, instead of using only the corresponding part: let videoGeometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0) videoGeometry.firstMaterial?.isDoubleSided = true videoGeometry.firstMaterial?.diffuse.contents = UIImage(named: "test")! I know I can use shader modifiers on the geometry but I'm not sure where to get

Creating a custom SCNGeometry polygon plane with SCNGeometryPrimitiveType polygon crash/error

僤鯓⒐⒋嵵緔 提交于 2019-12-03 08:31:42
I'm trying to create a custom SCNGeometry in the form of a plane with custom shape, which could be placed in an ARKit session. I'm using the option SCNGeometryPrimitiveTypePolygon in the following method which seems to work fine: extension SCNGeometry { static func polygonPlane(vertices: [SCNVector3]) -> SCNGeometry { var indices: [Int32] = [Int32(vertices.count)] var index: Int32 = 0 for _ in vertices { indices.append(index) index += 1 } let vertexSource = SCNGeometrySource(vertices: vertices) let indexData = Data(bytes: indices, count: indices.count * MemoryLayout<Int32>.size) let element =

How to use SceneKit to display a colorful point cloud using custom SCNGeometry?

拥有回忆 提交于 2019-12-03 08:14:50
I'm current working on developing OS X software using Swift to display a point cloud reading from a PLY file. The file is converted to an array of PointCloudVertex which is defined as follows: struct PointCloudVertex { let x: Double, y: Double, z: Double let r: Double, g: Double, b: Double } Then I try to build a SCNGeometry from the array: var vertices = [PointCloudVertex]() for p in points { let v = PointCloudVertex(x: p[0], y: p[1], z: p[2], r: p[3], g: p[4], b: p[5]) vertices.append(v) } let vertexData = NSData(bytes: &vertices, length: sizeof(PointCloudVertex) * points.count) let

How to use multiple cameras for the same scene in Scene Kit

拟墨画扇 提交于 2019-12-03 07:59:17
I have 2 SCNViews next to each other and both should show the same scene but through different cameras. It seems to me that Scene Kit uses that node with a camera that is highest in the node hierarchy so I tried something like that leftSceneView.scene?.rootNode.addChildNode(scene.rootNode) rightSceneView.scene?.rootNode.addChildNode(scene.rootNode) leftSceneView.scene?.rootNode.addChildNode(cameraNodeLeft) rightSceneView.scene?.rootNode.addChildNode(cameraNodeRight) but I got the error message [SCNKit ERROR] removing the root node of a scene from its scene is not allowed and it did not work at

ARKit vs SceneKit coordinates

一曲冷凌霜 提交于 2019-12-03 07:25:56
I'm trying to understand the difference between the different element introduced in ArKit and their maybe equivalents in SceneKit: SCNNode.simdTransform vs SCNNode.transform . In ARKit, it seems that people use SCNNode.simdTransform instead of SCNNode.transform . How do they differ? simdTransform seems to use column major order, while transform (SCNMatrix4) is row major. How do I convert one to the other? Just transpose? I've the impression that the tracking doesn't work as well if I use transform instead of simdTransform . Is that expected or just an impression? If I set one property, what

How to add SCNNodes without blocking main thread?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 07:16:43
I'm creating and adding a large number of SCNNodes to a SceneKit scene, which causes the app to freeze for a second or two. I thought I could fix this by putting all the action in a background thread using DispatchQueue.global(qos: .background).async() , but no dice. It behaves exactly the same. I saw this answer and put the nodes through SCNView.prepare() before adding them, hoping it would slow down the background thread and prevent blocking. It didn't. Here's a test function that reproduces the problem: func spawnNodesInBackground() { // put all the action in a background thread

Swift - How to change the Pivot of a SCNNode object

微笑、不失礼 提交于 2019-12-03 07:09:05
I've been playing with the SCNNode object for a while now and I'm lost with the Pivot. How can I change the pivot of a SCNNode (SCNBox as a bar) and place the pivot on one of the edge of the bar? A node's pivot is a transformation matrix, the inverse of which is applied to the node before its transform property takes effect. For example, take a look at this bit from the default SceneKit Game template in Xcode: let boxNode = SCNNode() boxNode.geometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0.02) If you set the boxNode 's position , that point corresponds to the center of the

Tap / Select Node in SceneKit (Swift)

淺唱寂寞╮ 提交于 2019-12-03 06:48:16
I'm new to SceneKit and 3D spaces in iOS. I'm currently working on a simple game that shows a cube of 28 segments ("mini cubes" if you want). I want to move the mini cubes by tapping them, but I can't get my head around how to select specific nodes (childnodes of the big cube). Can anybody help me or post a link to SceneKit tutorials for dummies? I've been looking for days now, and haven't found what I'm looking for. Cheers You can hit test the scene view (for example from the location of a tap gesture recognizer), which will give you a list of hit test results. From each result you can get

Set CALayer as SCNMaterial's diffuse contents

不问归期 提交于 2019-12-03 06:27:45
I've been searching all over the internet over the past couple of days to no avail. Unfortunately, the apple documentation about this specific issue is vague and no sample code is available (at least thats what I found out). What seems to be the issue you may ask... I'm trying to set a uiview's layer as the contents of the material that is used to render an iPhone model's screen (Yep, trippy :P ). The iPhone's screen's UV mapping is set from 0 to 1 so that no issue persists in mapping the texture/layer onto the texels. So, instead of getting this layer to appear rendered on the iPhone, same as