scenekit

SceneKit Object between two points

给你一囗甜甜゛ 提交于 2019-12-04 15:56:49
问题 Given 2 points in 3D ( a , b ) and an SCNCapsule, SCNTorus, SCNTube etc., how to go about to position the object, so that the object starts at point a and ends at point b ? Code example in Swift or Objective-C would be appreciated. From Moustachs answer I managed to do a 2-dimension solution: var v1 = SCNVector3(x: Float(a.x), y: Float(a.y), z: 0.0) var v2 = SCNVector3(x: Float(b.x), y: Float(b.y), z: 0.0) let height = CGFloat(v1.distance(v2)) var capsule = SCNCapsule(capRadius: 0.1, height:

ARKit: Reproducing the Project Point function

两盒软妹~` 提交于 2019-12-04 15:47:42
I'm attempting to reproduce the ARCamera's project point function, but for some reason the values are not matching up properly. I am taking the ARCamera's projection matrix and view matrix and applying basic CG perspective transform math, (PV) * p, but the NDC values do not match the pixel values given from the ARCamera's project point function. Any ideas? Am I forgetting something? Some more detail: Basically, I'm trying to take an ARFrame a the click of a button, and then trying to replicate the functionality of https://developer.apple.com/documentation/arkit/arcamera/2923538-projectpoint .

SceneKit - What orthographicProjection to use for 1:1 points to SceneKit position ratio

半腔热情 提交于 2019-12-04 15:35:49
What orthographicProjection does one have to use to be able to make a 2D application in SceneKit with 1:1 SceneKit points to screen points/pixels ratio? Example: I want to position something at (200, 200) on the screen and I want to use a SCNVector with (200, 200, 0) for it. What orthographicProjection do I need for this? If you want an orthographic projection where a unit of scene space corresponds to a point of screen space, you need a projection where the left clipping plane is at zero and the right clipping plane is at whatever the screen's width in points is. (Ditto for top/bottom, and

Adding a spark particle sprite inside a view controller

戏子无情 提交于 2019-12-04 15:32:27
I created an .sks particle emitter based on the spark template. My app is a normal app (not a game). When a user clicks a button, I have a new View controller that shows modally over fullscreen so that I can blur the background. In this modal, I created a view and gave it a class of SCNView see image below: How can I load the particle .sks file to do the animation on that viewController on the Particles view? Update How to load a SceneKit particle systems in view controller? As mentioned by @mnuages, you can use .scnp file instead of .sks , which is a SceneKit Particle System. So the steps are

Is refraction in SceneKit possible?

余生颓废 提交于 2019-12-04 15:01:42
Is it possible to make a shape that passes through light so you can see through it with the light bent due to refraction? Like a lens or a glass (or water)? Yes, everything is possible with the amazing power of Physics ! You'll need to create your own shader though. From Wikipedia : In the field of computer graphics, a shader is a computer program that is used to do shading: the production of appropriate levels of color within an image, or, in the modern era, also to produce special effects or do video post-processing. A definition in layman's terms might be given as "a program that tells a

How to build a multilevel game in SceneKit

心已入冬 提交于 2019-12-04 14:11:59
I'm an iOS developer and have plenty of business apps done. Some time ago I decided to try and write a 3D game for iPad using SceneKit. I understand how to create SCNView and SCNScene instances and how to load my scene from .dae files, but I'm having trouble understanding scene transition logic. Could someone explain the logic of transitioning between different game levels in SceneKit. I haven't found any transition methods between SCNView and SCNScenes For example: I have 2 levels of game (SCNScene instances). After the player finishes playing the first level, I show the score view (SpriteKit

Importing .scn file to scene from URL with textures

南笙酒味 提交于 2019-12-04 12:53:25
问题 I am using ARKit for my application and I try to dynamically load .scn files from web-server Here is a part of my code let url = URL(string: "http://192.168.0.31:1234/5a27e09cbad20a7a03ad5d80/box/box.scn") if let objectScene = try? SCNScene(url: url!, options: [.overrideAssetURLs: true]) { print("load success") let node = SCNNode() for childNode in objectScene.rootNode.childNodes { node.addChildNode(childNode) } sceneView.scene.rootNode.addChildNode(node) } else { print("error loading") }

Using Vuforia provided Projection Matrix and Marker Pose in SceneKit

会有一股神秘感。 提交于 2019-12-04 12:25:10
Currently I'm trying to troubleshoot the use of the projection matrix and framemarker pose when rendering in SceneKit. The model in the scene and the camera image background appear without problems. However, once I change the projection matrix and framemarker pose matrix to match Vuforia everything is pushed offscreen. func didUpdateProjectionMatrix(projectionMatrix: matrix_float4x4) { let extrinsic = SCNMatrix4FromMat4(projectionMatrix) let camera = self.cameraNode?.camera camera?.setProjectionTransform(extrinsic) } func didUpdateFramemarkers(framemarkers: [Framemarker]?) { guard let

Passing Metal texture2d_array to SceneKit shader modifier

别等时光非礼了梦想. 提交于 2019-12-04 12:11:58
I want to create shader modifier for SCNMaterial (with SCNShaderModifierEntryPointSurface ) and pass Metal texture2d_array as custom input. To achieve that I try to use key-value coding setting parameter of type SCNMaterialProperty . From SceneKit manual on SCNMaterialProperty property contents : You can set a value for this property using any of the following types: ... A texture (SKTexture, MDLTexture, MTLTexture , or GLKTextureInfo) ... So, I construct MTLTexture : Create MTLTextureDescriptor with type MTLTextureType2DArray Create MTLTexture with MTLDevice 's newTextureWithDescriptor: Fill

Swift - How to change the Pivot of a SCNNode object

久未见 提交于 2019-12-04 11:52:13
问题 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? 回答1: 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: