scenekit

SceneKit: use transform or directly manipulate rotation/position properties if goal is to rotate camera and project node X units in front of camera?

大憨熊 提交于 2019-12-06 05:29:28
For a voxel art app, the goal is to let users move and rotate a camera in a SceneKit scene then tap to place a block. The code below lets a user rotate a camera by panning. After the gesture ends, we move an existing block so it is -X units on the camera's Z-axis (i.e., -X units in front of the camera). cameraNode is the scene's point of view and is a child of userNode . When the user moves a joystick, we update the position of userNode. Question: Other SO posts manipulate camera nodes by applying a transform instead of changing the rotation and position properties. Is one approach better than

Getting direction that SCNNode is facing

为君一笑 提交于 2019-12-06 05:03:30
问题 I am getting lost in how nodespace coordinates and rotation are handled in scenekit. How do I get the direction a node is facing after rotation so I can then apply force in that direction. I assumed that a force along the -z axis applied to the node would always move it forward relative to the node however this is not the case. 回答1: Negative z is the "facing" direction of a node only in its own coordinate space (i.e. the one its children and geometry are positioned in). When you apply a force

SCN shader modifier in metal - pass uniform to shader

*爱你&永不变心* 提交于 2019-12-06 02:58:23
I'm trying to use shaders modifiers with Metal. I cannot figure out to declare uniforms... So far my fragment modifier is: // color changes #pragma arguments float4x4 u_color_transformation; #pragma body _output.color.rgb = vec3(1.0) - (u_color_transformation * _output.color).rgb; This outputs a purple texture, with no log.. If I just have _output.color.rgb = (u_color_transformation * _output.color).rgb , things are ok. I think I'm following the doc but maybe not! The uniform is set with: material.shaderModifiers = [ SCNShaderModifierEntryPoint.fragment: theShaderAbove ] material.setValue

SceneKit load node with animation from separate scn file

浪尽此生 提交于 2019-12-06 01:11:39
问题 I have a view that creates SCNView dynamically. It's scene is empty, but when I press a button I would like to add a node from separate scn file. This file contains animation, and I would like it to animate in main scene. The problem is that after adding object to the scene it's not animating. When I use this file as SCNView scene it works. isPlaying and loops are enabled. What else do I need to do to import such node with animation? Sample code below: override func viewDidLoad() { super

Stop sharing node's geometry with its clone programmatically

纵然是瞬间 提交于 2019-12-05 23:58:29
问题 When you create a copy of an object, geometry and its properties (materials...) are shared with that object. In Xcode Scene Editor you can easily disable that by setting Geometry Sharing (under Attributes Inspector ) to Unshare . I want to achieve the same thing programmatically, but can't find any similar properties in SceneKit documentation. I have found a similar post where someone proposed copying the object, its geometry and its material. I tried doing so but had no success. This is the

Pausing a SceneKit animation

时光总嘲笑我的痴心妄想 提交于 2019-12-05 23:08:31
I'm trying to create a test app in which the user can pause an animation by clicking in the SceneView. The SceneView loads the animation from a .dae file created in a 3d app (Cinema 4D). The app successfully plays and loops the animation upon launch. To pause the animation, I used Technical Q&A QA1673 as a reference. In the case of this .dae file, the animation actually comes in as a hierarchy of animations, so I have tried reaching down to each underlying CAKeyframeAnimation and setting its speed to zero. My code currently looks like this: - (void)mouseDown:(NSEvent *)event { SCNNode

ARKit: How to tell if user's face is parallel to camera

故事扮演 提交于 2019-12-05 22:27:46
In my Swift / ARKit / SceneKit project, I need to tell if the user's face in front-facing camera is parallel to the camera. I was able to tell horizontal parallel by comparing the left and right eyes distance (using faceAnchor.leftEyeTransform and the worldPosition property) from the camera. But I am stuck on vertical parallel. Any ideas, how to achieve that? Assuming you are using ARFaceTrackingConfiguration in your app, you can actually retrieve the transforms of both the ARFaceAnchor and the camera to determine their orientations. You can get a simd_float4x4 matrix of the head's orientation

Render horizon silhouette using Metal in SceneKit

邮差的信 提交于 2019-12-05 22:19:27
I'm working on simple side project and small part of it is rendering a terrain. I'm rendering the terrain using height map information. But here is my problem: I would like to render just a silhouette/outline of the terrain/horizon. Here is screenshot from my app rendering height map: And here is screenshot similar to desired result from peakfinder.org: I would like to draw just lines representing silhouette of terrain with the rest transparent or solid colour. How can I solve it? Calculate local maximum somehow? I created sample project here , in case you want to help me. Thanks! 来源: https:/

SceneKit, 'hit' testing between camera orientation and geometry

我们两清 提交于 2019-12-05 21:45:18
I'm currently following David Roonqvist's 3D Graphics with SceneKit book. Chapter 5 deals with hit testing, no issues implementing it, but only deals with his testing from mouse events. Now, I know my camera's orientation will ALWAYS intersect a certain geometry. I need to obtain the texture coordinate of the intersecting point between the camera orientation and the geometry. Any pointers as how to go about it? I've been looking all over without much success. Any help is appreciated. I haven't tried this but... SCNHitTestResult returns, among other things, textureCoordinatesWithMappingChannel(

Metal shader in SceneKit to outline an object

≯℡__Kan透↙ 提交于 2019-12-05 21:17:38
I'm playing around and trying to implement Metal shader in SceneKit that will outline an object. The idea is to draw an outline (or silhouette) similar to this image found in this blogpost (the blogpost doesn't contain any code): I'm new to SceneKit and Metal shaders so I'm able just to draw some geometry and write simple vertex or fragment shader. I'm curious how can I achieve this kind of effect? Is it done in multiple passes? Cheers! The basic idea here is to clone the "selected" node and its geometry, then use a custom vertex and fragment shader to "push" the geometry out along the vertex