SceneKit

RSS for tag

Create 3D games and add 3D content to apps using high-level scene descriptions using SceneKit.

SceneKit Documentation

Posts under SceneKit subtopic

Post

Replies

Boosts

Views

Activity

Scenekit spotlight with Gobo effect
I saw it's possible that you can use a gobo as light effect like in the real world, flag some lights off. Can someone help me to get the gobo effect to work? In the following example you will see a cube with a plane below it and a spotlight above it. I would like to load a pattern (image) in front off the spotlight-source which would flag (block) certain parts of the light. Expected behaviour would be that you will see part of the pattern on the top of the cube as you will see part of the blocked light pattern on the plane. Could anyone help me with solving this gobo puzzle? 	view.backgroundColor = .blue let sceneView = SCNView(frame: self.view.frame)     self.view.addSubview(sceneView)     view.bringSubviewToFront(sceneView)     sceneView.backgroundColor = .clear     sceneView.allowsCameraControl = true     let scene = SCNScene()     sceneView.scene = scene     // Add camera node     let camera = SCNCamera()     let cameraNode = SCNNode()     cameraNode.camera = camera     cameraNode.position = SCNVector3(x: 0, y: 0, z: 0)     scene.rootNode.addChildNode(cameraNode)     // Add a cube to the scene     let cubeGeometry = SCNBox(width: 0.5, height: 0.5, length: 0.5, chamferRadius: 0.0)     let cubeNode = SCNNode(geometry: cubeGeometry)     cubeNode.position = SCNVector3(x: 0.0, y: -0.5, z: -1.5)       // Make the cube white     let whiteMaterial = SCNMaterial()     whiteMaterial.diffuse.contents = UIColor.white     cubeGeometry.materials = [whiteMaterial]     scene.rootNode.addChildNode(cubeNode)     // Add a plane to the scene so we can see the lights & shadows     let planeGeometry = SCNPlane(width: 100.0, height: 100.0)     let lightGrayMaterial = SCNMaterial()     lightGrayMaterial.diffuse.contents = UIColor.lightGray     planeGeometry.materials = [lightGrayMaterial]     let planeNode = SCNNode(geometry: planeGeometry)     planeNode.eulerAngles = SCNVector3(x: GLKMathDegreesToRadians(-90), y: 0, z: 0)     planeNode.position = SCNVector3(x: 0, y: -15, z: 0)     scene.rootNode.addChildNode(planeNode)           // Create a spotlight     let light = SCNLight()     light.type = SCNLight.LightType.spot     light.castsShadow = true     // Create a Gobo mask: //    if let gobo = light.gobo //    { //      gobo.contents = UIImage(named: "gobo") //      gobo.intensity = 0.5 //      //light.categoryBitMask = -1 //    }           // Create al lightNode     let lightNode = SCNNode()     lightNode.light = light     lightNode.position = SCNVector3(x: 0, y: 10, z: -1.5)     let lightAngle = -90 * Float.pi / 180 // light facing down     lightNode.eulerAngles = SCNVector3(x: lightAngle, y: 0, z: 0)     scene.rootNode.addChildNode(lightNode)
1
0
997
May ’22
Bake lightprobes in Scenekit programmatically
I am facing issues baking lightprobes on iOS. The same logic bakes lightprobes on macOS successfully. iOS throws the following exception [MTLDebugCommandBuffer waitUntilCompleted]:201: failed assertion `waitUntilCompleted on uncommitted command buffer' Some specs : Runtime: iOS 15.4 - DeviceType: iPhone 13 Pro Max. I created two template apps from xcode (one for iOS and the other for macOS). Following is the code for lightprobe bake added in viewDidLoad SCNScene* scene = [SCNScene scene]; SCNNode *ambientLight = [SCNNode node]; ambientLight.light = [SCNLight light]; ambientLight.light.type = SCNLightTypeAmbient; ambientLight.light.color = [UIColor whiteColor]; ambientLight.light.intensity = 1000.0; [scene.rootNode addChildNode:ambientLight]; scene.background.contents = [UIColor whiteColor]; scene.background.intensity = 2000.; SCNNode *probe1 = [SCNNode node]; probe1.position = SCNVector3Make(-0.493530, 1.7285934, -0.150000); probe1.light = [SCNLight light]; probe1.light.type = SCNLightTypeProbe; [scene.rootNode addChildNode:probe1]; SCNRenderer* probeRenderer = [SCNRenderer rendererWithDevice:nil options:nil]; probeRenderer.scene = scene; NSArray<SCNNode*> *probes = [NSArray arrayWithObjects: probe1, nil]; [probeRenderer updateProbes: probes atTime:1.0]; The crash occurs at updateProbes. Also, I have logged and checked the 27 floats and they are not garbage for macOS so essentially the bake is working as expected on macOS. Any help would be really appreciated!
0
0
636
May ’22
Replacement for SCNLayer (deprecated)?
It appears SCNLayer is now deprecated, but I can't find the replacement for it. I'm just trying to get a SceneKit scene to render into a CALayer, without an SCNView attached. I actually want 3 different cameras from the same scene to render into 3 different layers inside the same NSView (not 3 separate SCNViews). Should we use CAMetalLayer for this now? If so, how do I set it up to render the scene? I'm using macOS 10.14 (but planning on using 10.15 when it's stable) with Xcode 11 Beta-3 BTW. Thank you if you can help with this.
1
0
1.1k
Apr ’22
Is SCNVector3 now 64 bit?
I'm having the most frustrating time trying to get SceneKit to render custom geometry on Monterey on an MBP M1Max. After some mucking about, I'm starting to suspect that the internal floating point representation has shifted to 64-bit?!? I'm wondering if this is also the case for element buffers, because rendering with UInt32 element arrays is FUBAR. Unfortunately, SceneKit won't allow me to create 64-bit element arrays.
1
0
691
Apr ’22
ARSCNView.pointOfView.position contains NaN in x, y, z
Hi, I'm building SceneKit app and run into a weird situation. From time to time, I can 't see any virtual objects in AR Scene, but it works perfectly in most cases. And in this moment I can't see any objects, sceneView.pointOfView.position.x or y or z is Nan, rotation is the same. guard let camera = sceneView?.pointOfView else {       print("Get phonePosition Fail")       return nil     }           // TODO: Don't know why sceneView?.pointOfView gets nothing (NaN). Should find out why.     if camera.position.x.isNaN {       if let session = sceneView?.session {         interrupted?(session)       }       return nil     } Did anyone handle this case before?
0
0
401
Apr ’22
Maya -> Dae -> SceneKit - import morph targets
Hey guys,Goal: export morph targets DMaya -&gt; Dae -&gt; SceneKitAE, with morph targets controllersIn Maya everything works fine, morphs with sliders work as intendedWhen exported to FBX/DAE and opened on Xcode, the morphs targets are there, but it places the entire avatar, instead of scaling the specific node (nose, arm, etc).https://gyazo.com/6f36a90ce5292b85a6f7a21b9a8918f2How can I export from Maya to DAE, keeping morphs for each node? Or any other Maya -&gt; Scenekit?Thanks!
2
0
1.3k
Mar ’22
Programatic use of Light Probes
When rendering a scene using environment lighting and the physically based lighting model, I have a need for an object to reflect another object. As I understand it, in this type of rendering, reflections are only based on the environment lighting and nothing else. As a solution I was intending to use a light probe placed between the object to be reflected and the reflecting object. My scene has been developed programatically and not through an XCode scene file. From Apple's WWDC 2016 presentation on SceneKit I could gather that light probes can be updated programatically through the use of the updateProbes method of the SCNRenderer class. I have the following code, where I am trying to initialize a light probe by using the updateProbes method:let sceneView = SCNView(frame: self.view.frame) self.view.addSubview(sceneView) let scene = SCNScene() sceneView.scene = scene let lightProbeNode = SCNNode() lightProbe = SCNLight() lightProbeNode.light = lightProbe lightProbe.type = .probe scene.rootNode.addChildNode(lightProbeNode) var initLightProbe = true func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { if initLightProbe { initLightProbe = false let scnRenderer = SCNRenderer(device: sceneView.device, options: nil) scnRenderer.scene = scene scnRenderer.updateProbes([lightProbeNode], atTime: time) print ("Initializing light probe") } }I don't seem to get any light coming from this light probe. My question is simple, can the updateProbes method be used to initialize a lightProbe? If not, how can you initialize a light probe programatically?
1
0
1.3k
Mar ’22
How does SceneKit preload assets?
Hi,I'm trying to understand what SceneKit does to load assets — when it loads them, where it loads them, etc..I cannot find detailed documentation on this but maybe I'm looking in the wrong place. The best I've found so faris the discussion sections in the API docs for SCNSceneRenderer.prepare(_:withCompletionHandler: ) and SCNSceneRenderer.prepare(_:shouldAbortBlock: ).Both of these methods have discussion sections that say the following:By default, SceneKit lazily loads resources onto the GPU for rendering. This approach uses memory and GPU bandwidth efficiently, but can lead to stutters in an otherwise smooth frame rate when you add large amounts of new content to an animated scene. To avoid such issues, use this method to prepare content for drawing before adding it to the scene. You can call this method on a secondary thread to prepare content asynchronously.SceneKit prepares all content associated with the object parameter you provide. If you provide an SCNMaterial object, SceneKit loads any texture images assigned to its material properties. If you provide an SCNGeometry object, SceneKit loads all materials attached to the geometry, as well as its vertex data. If you provide an SCNNode or SCNScene object, SceneKit loads all geometries and materials associated with the node and all its child nodes, or with the entire node hierarchy of the scene. ...You can observe the progress of this operation with the Progress class. For details, see Progress. This raises more questions for me, some of them probably pretty basic (I'm no expert in 3D graphics programming), and some maybe not so dumb:Does "loads resources onto the GPU" mean it is loading the assets into dedicated memroy separate from normal RAM? Or into normal RAM reserved for the GPU? Or into some kind of memory that's actually on the GPU? (This is the dumb question, I bet.)How many assets can be loaded ahead of time in this way?What happens if I try to load more than can fit?If SceneKit uses "a secondary thread to prepare content asynchronously", what happens if I try to access the content before the background loading operation completes? Does my access block or fail?If I can observe the operation with an NSProgress object, then how come these methods do not return NSProgress instances? Or how come the SCNSceneRenderer does not provide an accessor to get return an NSProgress instance?I'd appreciate any insight into these questions, or pointers to WWDC videos, documentation, or third-party books that go into enough detail that they would address these questions.Thanks!
4
0
3.6k
Feb ’22
My material is not affecting the mesh
I'm using a material with Physically based shading, and I'm trying to apply a .png texture to it in the diffuse field, in the preview of the material it looks fine, but already in the scene, it seems as if it's not affecting the mesh. the material looks like this: and the mesh: If you know that I could solve this error, it would help me a lot, thanks!
1
0
684
Feb ’22
Z-fighting with particles in SceneKit
In our AR app and appclip made with SceneKit, we experience z-fighting with particles and another transparent object (a transparent plane faking a bloom effect around one of our models). We tried to change the sorting mode without success. Moreover the z-fighting appears only on iPhone (tested with an iPhone X) and not on iPad (tested with an iPad Pro 2021). Here is a video showing the problem and a screenshot of our rendering settings for the particle system : https://drive.google.com/drive/folders/1fvyHRVfprw606qnQSRaLuDjtY1hN8_f2?usp=sharing
0
0
924
Feb ’22
Custom SCNGeometrySource does not produce correct geometry
I tried simplest example to use .polygon type: let vertices: [SCNVector3] = [ SCNVector3(-1,  0, 0),   SCNVector3( 0,  1, 0),   SCNVector3( 1,  0, 0) ] let indices: [Int32] = [3, 0, 1, 2] let indexData = NSData(bytes: indices, length: MemoryLayout<Int32>.size * indices.count) as Data let element = SCNGeometryElement(data: indexData, primitiveType: .polygon,    primitiveCount: 1,     bytesPerIndex: MemoryLayout<Int32>.size) Now when I try simple vertex source as let vertexSource = SCNGeometrySource(vertices: vertices) All works well. However when I use NSData it does not work: let data = NSData(bytes: vertices, length: MemoryLayout<SCNVector3>.size * vertices.count) as Data let vertexSource = SCNGeometrySource(data: data, semantic: .vertex,     vectorCount: vertices.count,     usesFloatComponents: true,    componentsPerVector: 3,     bytesPerComponent: MemoryLayout<CGFloat>.size,     dataOffset: 0,    dataStride: MemoryLayout<SCNVector3>.stride) I need to use NSData approach later on but I want to understand what is wrong in this simplest example. Any help is appreciated. Just to complete it: let geometry = SCNGeometry(sources: [vertexSource], elements: [element]) let node = SCNNode(geometry: geometry) // to ignore orientation problem node.geometry?.firstMaterial?.isDoubleSided = true
4
0
1.1k
Feb ’22
"SceneKit: error, missing buffer [-1/2]" when trying to pass uniforms to a metal shader
I've attached a SCNProgram to a SceneKit's geometry, and I'm trying to pass uniforms to the fragment shader. In my simple code snippet I just pass the output color to the fragment shader as a uniform, which returns it as an output value.I've already tested the shaders and they work, in the sense that I can succesfully rotate an object in the vertex shader, or draw an object in a different color in the fragment shader, etc... but the problem is when I pass the uniforms. This is my fragment shader:struct Uniform { float4 color; }; fragment float4 myFragment(MyVertexOutput in [[ stage_in ]], constant Uniforms&amp; uniforms [[buffer(2)]]) { return uniforms.color; }And this is how I try to pass the uniforms in my SceneKit+Swift code:SCNTransaction.begin() cube.geometry?.setValue(NSValue(SCNVector4:SCNVector4(0.0,1.0,0.0,1.0)), forKey: "uniforms.color") SCNTransaction.commit()But my object (it's a cube) is not even drawn (it's black), and I get this error: 2016-04-01 01:00:34.485 Shaded Cube[30266:12687154] SceneKit: error, missing buffer [-1/0]
1
0
1.2k
Jan ’22
How to perform scene updates after animations are evaluated?
I'm trying to overwrite some skeleton animation using : didApplyAnimationsAtTime time: TimeInterval) here is a link to the api. According to SCNSceneRendererDelegate : "SceneKit executes actions and performs animations attached to the scene graph. " before didApplyAnimationsAtTime is called. However, when I'm changing the animated node properties (for example position or eulerAngles). It seems like the animation continue to (somehow) change the nodes property, although it shouldn't. How can that be?
0
0
1.1k
Jan ’22
How to set defaultCameraController?
I have this code, and want to set the defaultCameraController.maximumVerticalAngle = 0.001 to disable up/down rotation of camera. How can this property be set in SwiftUI? import SwiftUI import SceneKit struct ContentView: View {     var scene = SCNScene(named: "LowPolyCopNew.usdz")     var body: some View {         VStack{             SceneView(scene: scene, options: [.allowsCameraControl, .autoenablesDefaultLighting])             .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height / 2)         Spacer(minLength: 0)         }     } }
0
0
438
Jan ’22
Main thread is blocked with __psynch_mutexwait
My app is using ARKit and Scenekit to render some animation for user interaction, at some points, it hangs with the below thread backtrace Anyway to tell what is blocking the main thread? (lldb) thread backtrace thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP frame #0: 0x00000001b1dd5204 libsystem_kernel.dylib`__psynch_mutexwait + 8 frame #1: 0x00000001cf935224 libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_wait + 92 frame #2: 0x00000001cf935174 libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_slow + 216 frame #3: 0x00000001b821e560 SceneKit`-[SCNRenderer _projectPoint:viewport:] + 220 frame #4: 0x00000001b82c8438 SceneKit`-[SCNView projectPoint:] + 124 frame #5: 0x000000010477d970 app`static OffScreenIndicator.updateOffScreenOn(displayView=0x00000001071c2b30, sceneView=0x00000001071d5820, target=0x0000000281a3c700, image=0x0000000281411050, color=0x0000000283c3d4c0, frame=0x000000015683e340, self=app.OffScreenIndicator) at OffScreenIndicator.swift:26:37 frame #6: 0x000000010458d5d8 app`ARViewController.phoneIsFar(camPosition=SceneKit.SCNVector3 @ 0x000000016db94730, frame=0x000000015683e340, isTutorial=true, self=0x000000010883bc00) at ARViewController.swift:2434:48 frame #7: 0x000000010458a0b4 app`ARViewController.scanUpdate(frame=0x000000015683e340, showTutorial=true, scanAllDoneAction=0x000000010459300c app`partial apply forwarder for closure #1 () - () in app.ARViewController.(stateUpdate_tutorial in _ED82BCD2A98A9516DA8B452F58022553)(frame: __C.ARFrame) - () at compiler-generated, self=0x000000010883bc00) at ARViewController.swift:2371:13 frame #8: 0x0000000104560e14 app`ARViewController.stateUpdate_tutorial(frame=0x000000015683e340, self=0x000000010883bc00) at ARViewController.swift:2692:9 frame #9: 0x00000001045609f4 app`implicit closure #22 in implicit closure #21 in ARViewController.bindStateFunctions(frame=0x000000015683e340, self=0x000000010883bc00) at ARViewController.swift:1048:34 frame #10: 0x00000001045506fc app`ARViewController.updateState(frame=0x000000015683e340, self=0x000000010883bc00) at ARViewController.swift:1108:31 frame #11: 0x0000000104550274 app`ARViewController.session(session=0x00000001568cbdd0, frame=0x000000015683e340, self=0x000000010883bc00) at ARViewController.swift:696:9 frame #12: 0x0000000104550778 app`@objc ARViewController.session(_:didUpdate:) at compiler-generated:0 frame #13: 0x00000001afa25248 ARKitCore`__36-[ARSession _sessionDidUpdateFrame:]_block_invoke + 128 frame #14: 0x0000000106f37bcc libdispatch.dylib`_dispatch_call_block_and_release + 32 frame #15: 0x0000000106f396c0 libdispatch.dylib`_dispatch_client_callout + 20 frame #16: 0x0000000106f48f34 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1000 frame #17: 0x0000000183e0111c CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 frame #18: 0x0000000183dfb120 CoreFoundation`__CFRunLoopRun + 2508 frame #19: 0x0000000183dfa21c CoreFoundation`CFRunLoopRunSpecific + 600 frame #20: 0x000000019b9c4784 GraphicsServices`GSEventRunModal + 164 frame #21: 0x000000018683aee8 UIKitCore`-[UIApplication _run] + 1072 frame #22: 0x000000018684075c UIKitCore`UIApplicationMain + 168 frame #23: 0x00000001022766b4 app`main at AppDelegate.swift:14:7 frame #24: 0x0000000183aba6b0 libdyld.dylib`start + 4 (lldb) (lldb) thread list Process 4264 stopped thread #1: tid = 0x131e7b, 0x00000001b1dd5204 libsystem_kernel.dylib`__psynch_mutexwait + 8, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP thread #6: tid = 0x131f75, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.uikit.eventfetch-thread' thread #9: tid = 0x131f7e, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'AVAudioSession Notify Thread' thread #11: tid = 0x131ffc, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.NSURLConnectionLoader' thread #14: tid = 0x132099, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.coreaudio.AQClient' thread #21: tid = 0x1320d9, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #27: tid = 0x132153, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.CoreMotion.MotionThread' thread #28: tid = 0x132157, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #46: tid = 0x1321ff, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #49: tid = 0x132202, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #53: tid = 0x13228c, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #58: tid = 0x132397, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.arkit.ardisplaylink.0x283d67a00' thread #59: tid = 0x132398, 0x00000001b1dd5f5c libsystem_kernel.dylib`__ulock_wait + 8, name = 'com.apple.scenekit.scnview-renderer', queue = 'com.apple.scenekit.renderingQueue.ARSCNView0x1071d5820' thread #60: tid = 0x1323a2, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'H11ANEServicesThread' thread #61: tid = 0x1323b3, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'H11ANEServicesThread' thread #62: tid = 0x13249f, 0x00000001b1db1324 libsystem_kernel.dylib`semaphore_timedwait_trap + 8 thread #65: tid = 0x1324a8, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #67: tid = 0x1324df, 0x00000001b1db1324 libsystem_kernel.dylib`semaphore_timedwait_trap + 8 thread #68: tid = 0x132505, 0x0000000198e9d150 libobjc.A.dylib`object_getClassName, queue = 'com.apple.libdispatch-manager' thread #69: tid = 0x132507, 0x0000000198e9d150 libobjc.A.dylib`object_getClassName thread #70: tid = 0x132537, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #71: tid = 0x132538, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread (lldb)
4
1
4.1k
Nov ’21
Scenekit spotlight with Gobo effect
I saw it's possible that you can use a gobo as light effect like in the real world, flag some lights off. Can someone help me to get the gobo effect to work? In the following example you will see a cube with a plane below it and a spotlight above it. I would like to load a pattern (image) in front off the spotlight-source which would flag (block) certain parts of the light. Expected behaviour would be that you will see part of the pattern on the top of the cube as you will see part of the blocked light pattern on the plane. Could anyone help me with solving this gobo puzzle? &#9;view.backgroundColor = .blue let sceneView = SCNView(frame: self.view.frame)     self.view.addSubview(sceneView)     view.bringSubviewToFront(sceneView)     sceneView.backgroundColor = .clear     sceneView.allowsCameraControl = true     let scene = SCNScene()     sceneView.scene = scene     // Add camera node     let camera = SCNCamera()     let cameraNode = SCNNode()     cameraNode.camera = camera     cameraNode.position = SCNVector3(x: 0, y: 0, z: 0)     scene.rootNode.addChildNode(cameraNode)     // Add a cube to the scene     let cubeGeometry = SCNBox(width: 0.5, height: 0.5, length: 0.5, chamferRadius: 0.0)     let cubeNode = SCNNode(geometry: cubeGeometry)     cubeNode.position = SCNVector3(x: 0.0, y: -0.5, z: -1.5)       // Make the cube white     let whiteMaterial = SCNMaterial()     whiteMaterial.diffuse.contents = UIColor.white     cubeGeometry.materials = [whiteMaterial]     scene.rootNode.addChildNode(cubeNode)     // Add a plane to the scene so we can see the lights & shadows     let planeGeometry = SCNPlane(width: 100.0, height: 100.0)     let lightGrayMaterial = SCNMaterial()     lightGrayMaterial.diffuse.contents = UIColor.lightGray     planeGeometry.materials = [lightGrayMaterial]     let planeNode = SCNNode(geometry: planeGeometry)     planeNode.eulerAngles = SCNVector3(x: GLKMathDegreesToRadians(-90), y: 0, z: 0)     planeNode.position = SCNVector3(x: 0, y: -15, z: 0)     scene.rootNode.addChildNode(planeNode)           // Create a spotlight     let light = SCNLight()     light.type = SCNLight.LightType.spot     light.castsShadow = true     // Create a Gobo mask: //    if let gobo = light.gobo //    { //      gobo.contents = UIImage(named: "gobo") //      gobo.intensity = 0.5 //      //light.categoryBitMask = -1 //    }           // Create al lightNode     let lightNode = SCNNode()     lightNode.light = light     lightNode.position = SCNVector3(x: 0, y: 10, z: -1.5)     let lightAngle = -90 * Float.pi / 180 // light facing down     lightNode.eulerAngles = SCNVector3(x: lightAngle, y: 0, z: 0)     scene.rootNode.addChildNode(lightNode)
Replies
1
Boosts
0
Views
997
Activity
May ’22
Bake lightprobes in Scenekit programmatically
I am facing issues baking lightprobes on iOS. The same logic bakes lightprobes on macOS successfully. iOS throws the following exception [MTLDebugCommandBuffer waitUntilCompleted]:201: failed assertion `waitUntilCompleted on uncommitted command buffer' Some specs : Runtime: iOS 15.4 - DeviceType: iPhone 13 Pro Max. I created two template apps from xcode (one for iOS and the other for macOS). Following is the code for lightprobe bake added in viewDidLoad SCNScene* scene = [SCNScene scene]; SCNNode *ambientLight = [SCNNode node]; ambientLight.light = [SCNLight light]; ambientLight.light.type = SCNLightTypeAmbient; ambientLight.light.color = [UIColor whiteColor]; ambientLight.light.intensity = 1000.0; [scene.rootNode addChildNode:ambientLight]; scene.background.contents = [UIColor whiteColor]; scene.background.intensity = 2000.; SCNNode *probe1 = [SCNNode node]; probe1.position = SCNVector3Make(-0.493530, 1.7285934, -0.150000); probe1.light = [SCNLight light]; probe1.light.type = SCNLightTypeProbe; [scene.rootNode addChildNode:probe1]; SCNRenderer* probeRenderer = [SCNRenderer rendererWithDevice:nil options:nil]; probeRenderer.scene = scene; NSArray<SCNNode*> *probes = [NSArray arrayWithObjects: probe1, nil]; [probeRenderer updateProbes: probes atTime:1.0]; The crash occurs at updateProbes. Also, I have logged and checked the 27 floats and they are not garbage for macOS so essentially the bake is working as expected on macOS. Any help would be really appreciated!
Replies
0
Boosts
0
Views
636
Activity
May ’22
Replacement for SCNLayer (deprecated)?
It appears SCNLayer is now deprecated, but I can't find the replacement for it. I'm just trying to get a SceneKit scene to render into a CALayer, without an SCNView attached. I actually want 3 different cameras from the same scene to render into 3 different layers inside the same NSView (not 3 separate SCNViews). Should we use CAMetalLayer for this now? If so, how do I set it up to render the scene? I'm using macOS 10.14 (but planning on using 10.15 when it's stable) with Xcode 11 Beta-3 BTW. Thank you if you can help with this.
Replies
1
Boosts
0
Views
1.1k
Activity
Apr ’22
Is SCNVector3 now 64 bit?
I'm having the most frustrating time trying to get SceneKit to render custom geometry on Monterey on an MBP M1Max. After some mucking about, I'm starting to suspect that the internal floating point representation has shifted to 64-bit?!? I'm wondering if this is also the case for element buffers, because rendering with UInt32 element arrays is FUBAR. Unfortunately, SceneKit won't allow me to create 64-bit element arrays.
Replies
1
Boosts
0
Views
691
Activity
Apr ’22
is it okay to work on Mac12.3.1 + Xcode 13.3
required: Xcode 13.3 on macOS 12.3 is it okay to run Mac version 12.3.1 not 12.3? playground book is not allowed to be submitted?
Replies
0
Boosts
0
Views
1k
Activity
Apr ’22
ARSCNView.pointOfView.position contains NaN in x, y, z
Hi, I'm building SceneKit app and run into a weird situation. From time to time, I can 't see any virtual objects in AR Scene, but it works perfectly in most cases. And in this moment I can't see any objects, sceneView.pointOfView.position.x or y or z is Nan, rotation is the same. guard let camera = sceneView?.pointOfView else {       print("Get phonePosition Fail")       return nil     }           // TODO: Don't know why sceneView?.pointOfView gets nothing (NaN). Should find out why.     if camera.position.x.isNaN {       if let session = sceneView?.session {         interrupted?(session)       }       return nil     } Did anyone handle this case before?
Replies
0
Boosts
0
Views
401
Activity
Apr ’22
Pan & Zoom Feature on AR/VR 3D SceneKIT
Can you develop the feature to pan & zoom simultaneously on the AR/VR SceneKit?
Replies
0
Boosts
0
Views
816
Activity
Mar ’22
Maya -> Dae -> SceneKit - import morph targets
Hey guys,Goal: export morph targets DMaya -&gt; Dae -&gt; SceneKitAE, with morph targets controllersIn Maya everything works fine, morphs with sliders work as intendedWhen exported to FBX/DAE and opened on Xcode, the morphs targets are there, but it places the entire avatar, instead of scaling the specific node (nose, arm, etc).https://gyazo.com/6f36a90ce5292b85a6f7a21b9a8918f2How can I export from Maya to DAE, keeping morphs for each node? Or any other Maya -&gt; Scenekit?Thanks!
Replies
2
Boosts
0
Views
1.3k
Activity
Mar ’22
Programatic use of Light Probes
When rendering a scene using environment lighting and the physically based lighting model, I have a need for an object to reflect another object. As I understand it, in this type of rendering, reflections are only based on the environment lighting and nothing else. As a solution I was intending to use a light probe placed between the object to be reflected and the reflecting object. My scene has been developed programatically and not through an XCode scene file. From Apple's WWDC 2016 presentation on SceneKit I could gather that light probes can be updated programatically through the use of the updateProbes method of the SCNRenderer class. I have the following code, where I am trying to initialize a light probe by using the updateProbes method:let sceneView = SCNView(frame: self.view.frame) self.view.addSubview(sceneView) let scene = SCNScene() sceneView.scene = scene let lightProbeNode = SCNNode() lightProbe = SCNLight() lightProbeNode.light = lightProbe lightProbe.type = .probe scene.rootNode.addChildNode(lightProbeNode) var initLightProbe = true func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) { if initLightProbe { initLightProbe = false let scnRenderer = SCNRenderer(device: sceneView.device, options: nil) scnRenderer.scene = scene scnRenderer.updateProbes([lightProbeNode], atTime: time) print ("Initializing light probe") } }I don't seem to get any light coming from this light probe. My question is simple, can the updateProbes method be used to initialize a lightProbe? If not, how can you initialize a light probe programatically?
Replies
1
Boosts
0
Views
1.3k
Activity
Mar ’22
How does SceneKit preload assets?
Hi,I'm trying to understand what SceneKit does to load assets — when it loads them, where it loads them, etc..I cannot find detailed documentation on this but maybe I'm looking in the wrong place. The best I've found so faris the discussion sections in the API docs for SCNSceneRenderer.prepare(_:withCompletionHandler: ) and SCNSceneRenderer.prepare(_:shouldAbortBlock: ).Both of these methods have discussion sections that say the following:By default, SceneKit lazily loads resources onto the GPU for rendering. This approach uses memory and GPU bandwidth efficiently, but can lead to stutters in an otherwise smooth frame rate when you add large amounts of new content to an animated scene. To avoid such issues, use this method to prepare content for drawing before adding it to the scene. You can call this method on a secondary thread to prepare content asynchronously.SceneKit prepares all content associated with the object parameter you provide. If you provide an SCNMaterial object, SceneKit loads any texture images assigned to its material properties. If you provide an SCNGeometry object, SceneKit loads all materials attached to the geometry, as well as its vertex data. If you provide an SCNNode or SCNScene object, SceneKit loads all geometries and materials associated with the node and all its child nodes, or with the entire node hierarchy of the scene. ...You can observe the progress of this operation with the Progress class. For details, see Progress. This raises more questions for me, some of them probably pretty basic (I'm no expert in 3D graphics programming), and some maybe not so dumb:Does "loads resources onto the GPU" mean it is loading the assets into dedicated memroy separate from normal RAM? Or into normal RAM reserved for the GPU? Or into some kind of memory that's actually on the GPU? (This is the dumb question, I bet.)How many assets can be loaded ahead of time in this way?What happens if I try to load more than can fit?If SceneKit uses "a secondary thread to prepare content asynchronously", what happens if I try to access the content before the background loading operation completes? Does my access block or fail?If I can observe the operation with an NSProgress object, then how come these methods do not return NSProgress instances? Or how come the SCNSceneRenderer does not provide an accessor to get return an NSProgress instance?I'd appreciate any insight into these questions, or pointers to WWDC videos, documentation, or third-party books that go into enough detail that they would address these questions.Thanks!
Replies
4
Boosts
0
Views
3.6k
Activity
Feb ’22
My material is not affecting the mesh
I'm using a material with Physically based shading, and I'm trying to apply a .png texture to it in the diffuse field, in the preview of the material it looks fine, but already in the scene, it seems as if it's not affecting the mesh. the material looks like this: and the mesh: If you know that I could solve this error, it would help me a lot, thanks!
Replies
1
Boosts
0
Views
684
Activity
Feb ’22
Z-fighting with particles in SceneKit
In our AR app and appclip made with SceneKit, we experience z-fighting with particles and another transparent object (a transparent plane faking a bloom effect around one of our models). We tried to change the sorting mode without success. Moreover the z-fighting appears only on iPhone (tested with an iPhone X) and not on iPad (tested with an iPad Pro 2021). Here is a video showing the problem and a screenshot of our rendering settings for the particle system : https://drive.google.com/drive/folders/1fvyHRVfprw606qnQSRaLuDjtY1hN8_f2?usp=sharing
Replies
0
Boosts
0
Views
924
Activity
Feb ’22
When will the Node of flexible objects be opened?
At present, the Node of Scenekit is for rigid objects. When will the Node of flexible objects be opened? Such as cloth, elastic balls, pillows, etc. Is there such a plan?
Replies
0
Boosts
0
Views
833
Activity
Feb ’22
Custom SCNGeometrySource does not produce correct geometry
I tried simplest example to use .polygon type: let vertices: [SCNVector3] = [ SCNVector3(-1,  0, 0),   SCNVector3( 0,  1, 0),   SCNVector3( 1,  0, 0) ] let indices: [Int32] = [3, 0, 1, 2] let indexData = NSData(bytes: indices, length: MemoryLayout<Int32>.size * indices.count) as Data let element = SCNGeometryElement(data: indexData, primitiveType: .polygon,    primitiveCount: 1,     bytesPerIndex: MemoryLayout<Int32>.size) Now when I try simple vertex source as let vertexSource = SCNGeometrySource(vertices: vertices) All works well. However when I use NSData it does not work: let data = NSData(bytes: vertices, length: MemoryLayout<SCNVector3>.size * vertices.count) as Data let vertexSource = SCNGeometrySource(data: data, semantic: .vertex,     vectorCount: vertices.count,     usesFloatComponents: true,    componentsPerVector: 3,     bytesPerComponent: MemoryLayout<CGFloat>.size,     dataOffset: 0,    dataStride: MemoryLayout<SCNVector3>.stride) I need to use NSData approach later on but I want to understand what is wrong in this simplest example. Any help is appreciated. Just to complete it: let geometry = SCNGeometry(sources: [vertexSource], elements: [element]) let node = SCNNode(geometry: geometry) // to ignore orientation problem node.geometry?.firstMaterial?.isDoubleSided = true
Replies
4
Boosts
0
Views
1.1k
Activity
Feb ’22
"SceneKit: error, missing buffer [-1/2]" when trying to pass uniforms to a metal shader
I've attached a SCNProgram to a SceneKit's geometry, and I'm trying to pass uniforms to the fragment shader. In my simple code snippet I just pass the output color to the fragment shader as a uniform, which returns it as an output value.I've already tested the shaders and they work, in the sense that I can succesfully rotate an object in the vertex shader, or draw an object in a different color in the fragment shader, etc... but the problem is when I pass the uniforms. This is my fragment shader:struct Uniform { float4 color; }; fragment float4 myFragment(MyVertexOutput in [[ stage_in ]], constant Uniforms&amp; uniforms [[buffer(2)]]) { return uniforms.color; }And this is how I try to pass the uniforms in my SceneKit+Swift code:SCNTransaction.begin() cube.geometry?.setValue(NSValue(SCNVector4:SCNVector4(0.0,1.0,0.0,1.0)), forKey: "uniforms.color") SCNTransaction.commit()But my object (it's a cube) is not even drawn (it's black), and I get this error: 2016-04-01 01:00:34.485 Shaded Cube[30266:12687154] SceneKit: error, missing buffer [-1/0]
Replies
1
Boosts
0
Views
1.2k
Activity
Jan ’22
How to perform scene updates after animations are evaluated?
I'm trying to overwrite some skeleton animation using : didApplyAnimationsAtTime time: TimeInterval) here is a link to the api. According to SCNSceneRendererDelegate : "SceneKit executes actions and performs animations attached to the scene graph. " before didApplyAnimationsAtTime is called. However, when I'm changing the animated node properties (for example position or eulerAngles). It seems like the animation continue to (somehow) change the nodes property, although it shouldn't. How can that be?
Replies
0
Boosts
0
Views
1.1k
Activity
Jan ’22
How to set defaultCameraController?
I have this code, and want to set the defaultCameraController.maximumVerticalAngle = 0.001 to disable up/down rotation of camera. How can this property be set in SwiftUI? import SwiftUI import SceneKit struct ContentView: View {     var scene = SCNScene(named: "LowPolyCopNew.usdz")     var body: some View {         VStack{             SceneView(scene: scene, options: [.allowsCameraControl, .autoenablesDefaultLighting])             .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height / 2)         Spacer(minLength: 0)         }     } }
Replies
0
Boosts
0
Views
438
Activity
Jan ’22
How to set the resolution?
How can you set the resolution in scenekit?I would like to render the scenekit view at half the resolution and then scale it up. (I'm hoping this will give a performance boost to my game at the cost of non retina graphics)
Replies
5
Boosts
0
Views
3.9k
Activity
Dec ’21
sceneView.projectPoint is incredibly slow?
I need to run sceneView.projectPoint a couple of 100 times in a loop, it freezes my app regularly... not always. Sometimes it freezes for a second sometimes for 10 seconds.Any ideas?
Replies
1
Boosts
0
Views
1k
Activity
Dec ’21
Main thread is blocked with __psynch_mutexwait
My app is using ARKit and Scenekit to render some animation for user interaction, at some points, it hangs with the below thread backtrace Anyway to tell what is blocking the main thread? (lldb) thread backtrace thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP frame #0: 0x00000001b1dd5204 libsystem_kernel.dylib`__psynch_mutexwait + 8 frame #1: 0x00000001cf935224 libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_wait + 92 frame #2: 0x00000001cf935174 libsystem_pthread.dylib`_pthread_mutex_firstfit_lock_slow + 216 frame #3: 0x00000001b821e560 SceneKit`-[SCNRenderer _projectPoint:viewport:] + 220 frame #4: 0x00000001b82c8438 SceneKit`-[SCNView projectPoint:] + 124 frame #5: 0x000000010477d970 app`static OffScreenIndicator.updateOffScreenOn(displayView=0x00000001071c2b30, sceneView=0x00000001071d5820, target=0x0000000281a3c700, image=0x0000000281411050, color=0x0000000283c3d4c0, frame=0x000000015683e340, self=app.OffScreenIndicator) at OffScreenIndicator.swift:26:37 frame #6: 0x000000010458d5d8 app`ARViewController.phoneIsFar(camPosition=SceneKit.SCNVector3 @ 0x000000016db94730, frame=0x000000015683e340, isTutorial=true, self=0x000000010883bc00) at ARViewController.swift:2434:48 frame #7: 0x000000010458a0b4 app`ARViewController.scanUpdate(frame=0x000000015683e340, showTutorial=true, scanAllDoneAction=0x000000010459300c app`partial apply forwarder for closure #1 () - () in app.ARViewController.(stateUpdate_tutorial in _ED82BCD2A98A9516DA8B452F58022553)(frame: __C.ARFrame) - () at compiler-generated, self=0x000000010883bc00) at ARViewController.swift:2371:13 frame #8: 0x0000000104560e14 app`ARViewController.stateUpdate_tutorial(frame=0x000000015683e340, self=0x000000010883bc00) at ARViewController.swift:2692:9 frame #9: 0x00000001045609f4 app`implicit closure #22 in implicit closure #21 in ARViewController.bindStateFunctions(frame=0x000000015683e340, self=0x000000010883bc00) at ARViewController.swift:1048:34 frame #10: 0x00000001045506fc app`ARViewController.updateState(frame=0x000000015683e340, self=0x000000010883bc00) at ARViewController.swift:1108:31 frame #11: 0x0000000104550274 app`ARViewController.session(session=0x00000001568cbdd0, frame=0x000000015683e340, self=0x000000010883bc00) at ARViewController.swift:696:9 frame #12: 0x0000000104550778 app`@objc ARViewController.session(_:didUpdate:) at compiler-generated:0 frame #13: 0x00000001afa25248 ARKitCore`__36-[ARSession _sessionDidUpdateFrame:]_block_invoke + 128 frame #14: 0x0000000106f37bcc libdispatch.dylib`_dispatch_call_block_and_release + 32 frame #15: 0x0000000106f396c0 libdispatch.dylib`_dispatch_client_callout + 20 frame #16: 0x0000000106f48f34 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1000 frame #17: 0x0000000183e0111c CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 frame #18: 0x0000000183dfb120 CoreFoundation`__CFRunLoopRun + 2508 frame #19: 0x0000000183dfa21c CoreFoundation`CFRunLoopRunSpecific + 600 frame #20: 0x000000019b9c4784 GraphicsServices`GSEventRunModal + 164 frame #21: 0x000000018683aee8 UIKitCore`-[UIApplication _run] + 1072 frame #22: 0x000000018684075c UIKitCore`UIApplicationMain + 168 frame #23: 0x00000001022766b4 app`main at AppDelegate.swift:14:7 frame #24: 0x0000000183aba6b0 libdyld.dylib`start + 4 (lldb) (lldb) thread list Process 4264 stopped thread #1: tid = 0x131e7b, 0x00000001b1dd5204 libsystem_kernel.dylib`__psynch_mutexwait + 8, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP thread #6: tid = 0x131f75, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.uikit.eventfetch-thread' thread #9: tid = 0x131f7e, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'AVAudioSession Notify Thread' thread #11: tid = 0x131ffc, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.NSURLConnectionLoader' thread #14: tid = 0x132099, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.coreaudio.AQClient' thread #21: tid = 0x1320d9, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #27: tid = 0x132153, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.CoreMotion.MotionThread' thread #28: tid = 0x132157, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #46: tid = 0x1321ff, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #49: tid = 0x132202, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #53: tid = 0x13228c, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #58: tid = 0x132397, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'com.apple.arkit.ardisplaylink.0x283d67a00' thread #59: tid = 0x132398, 0x00000001b1dd5f5c libsystem_kernel.dylib`__ulock_wait + 8, name = 'com.apple.scenekit.scnview-renderer', queue = 'com.apple.scenekit.renderingQueue.ARSCNView0x1071d5820' thread #60: tid = 0x1323a2, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'H11ANEServicesThread' thread #61: tid = 0x1323b3, 0x00000001b1db12d0 libsystem_kernel.dylib`mach_msg_trap + 8, name = 'H11ANEServicesThread' thread #62: tid = 0x13249f, 0x00000001b1db1324 libsystem_kernel.dylib`semaphore_timedwait_trap + 8 thread #65: tid = 0x1324a8, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #67: tid = 0x1324df, 0x00000001b1db1324 libsystem_kernel.dylib`semaphore_timedwait_trap + 8 thread #68: tid = 0x132505, 0x0000000198e9d150 libobjc.A.dylib`object_getClassName, queue = 'com.apple.libdispatch-manager' thread #69: tid = 0x132507, 0x0000000198e9d150 libobjc.A.dylib`object_getClassName thread #70: tid = 0x132537, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread thread #71: tid = 0x132538, 0x00000001cf938764 libsystem_pthread.dylib`start_wqthread (lldb)
Replies
4
Boosts
1
Views
4.1k
Activity
Nov ’21