scenekit

How to programmatically wrap png texture around cube in SceneKit

浪子不回头ぞ 提交于 2019-12-07 11:50:39
问题 I'm new to SceneKit... trying to get some basic stuff working without much success so far. For some reason when I try to apply a png texture to a CNBox I end up with nothing but blackness. Here is the simple code snippet I have in viewDidLoad: let sceneView = (view as SCNView) let scene = SCNScene() let boxGeometry = SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 1.0) let mat = SCNMaterial() mat.locksAmbientWithDiffuse = true mat.diffuse.contents = ["sofb.png","sofb.png","sofb

Move a specific node in SceneKit using touch

时光怂恿深爱的人放手 提交于 2019-12-07 09:31:55
问题 I have a scene with multiple nodes. I want to select a node by tapping it (if I tap nothing I want nothing to happen) and make him follow my finger only on XY axis (I know position on Z axis). Is there any method that converts location in view to SceneKit coords? After few researches I found this and it's exactly what I want, but I don't get the code. Can somebody explain me or help me figure how can I solve my problem? https://www.youtube.com/watch?v=xn9Bt2PFp0g 回答1: func CGPointToSCNVector3

How to put text over node in scenekit?

萝らか妹 提交于 2019-12-07 07:03:05
问题 Really simple question which for some reason I cannot find anywhere. How can I write 2D text on a 3D face of a SCNNode ? For example, on something like this: let geo = SCNBox(width: 20, height: 20, length: 20, chamferRadius: 0.0); //geo.writeFace(postion, text) let box = SCNNode(geometry: geo); Of course the comment is made up. Anything like it? 回答1: You'll need to create a texture of the desired font and text, then apply that as a part of the material on the object. Though I've not seen

SceneKit pass uniform vector to shader modifiers

我怕爱的太早我们不能终老 提交于 2019-12-07 06:52:00
问题 I'm trying to pass a GLKVector4 to a shader that should receive it as a vec4 . I'm using a fragment shader modifier: material.shaderModifiers = [ SCNShaderModifierEntryPoint.fragment: shaderModifier ] where shaderModifier is: // color changes uniform float colorModifier; uniform vec4 colorOffset; vec4 color = _output.color; color = color + colorOffset; color = color + vec4(0.0, colorModifier, 0.0, 0.0); _output.color = color; (I'm simply adding a color offset) I've tried: material.setValue

SceneKit: how to reproduce iOS 9 lighting color effect (one directional, one ambient) on iOS 10 without disabling PBR?

你说的曾经没有我的故事 提交于 2019-12-07 05:49:37
问题 As this thread on the Apple forums mentions, lights on iOS 10 are now weaker and change how scenes look. The thread suggests setting SCNDisableLinearSpaceRendering to YES, but this did not work. Put another way, using SCNDisableLinearSpaceRendering will not make your scene look the same on iOS 10 as on iOS 9 -- at least not in our testing. We also tried: floorNode.geometry?.firstMaterial?.lightingModel = SCNMaterial.LightingModel.blinn Screenshots below show the difference between the same

Can I get the SCNView camera position when using allowsCameraControl?

拥有回忆 提交于 2019-12-07 05:19:46
问题 The SCNView documentation says that setting allowsCameraControl to YES does not update the camera node position when the user changes the point of view. Is there any way to get the user-modified camera parameters when the user changes the point of view? 回答1: When you enable allowsCameraControl , SceneKit inserts its own camera node into the scene (as an immediate child of the scene's root node), and sets that node as the view's pointOfView. Read the properties of that node to find out the

Optimizing SceneKit performance with high-res textures

本小妞迷上赌 提交于 2019-12-07 04:27:37
问题 I'm a fairly experienced iOS developer but a total SceneKit newbie, trying to simulate some planets in a basic app. To that end, I'm using high-res normal and diffuse maps of Mars, Venus, etc, applied to basic spheres. And they work! They look awesome, exactly what I was going for. The problem is, I'm getting killed by the quality/memory tradeoff. I can scale down the dimensions of the textures to reduce the memory footprint, but below a certain resolution the results (especially the normal

SceneKit : SCNPhysicsBody get current velocity

落花浮王杯 提交于 2019-12-07 04:17:05
问题 How can I get the current velocity of a SCNPhyisicsBody? The velocity property does always return (0.0, 0.0, 0.0), and the physicsBody of the prensetationNode of my SCNNode is also nil. 回答1: You can get the "current" velocity with physicsBody.velocity But this is valid only within the "game loop" callbacks (updateAtTime, didApplyAnimations, didSimulatePhysics, will/didRenderScene). 回答2: ...in your view controller, you have to use SCNSceneRendererDelegate protocol like class GameViewController

Unwrapping SCNVector3/SCNVector4 values to print?

限于喜欢 提交于 2019-12-07 03:32:28
This should be an easy question import SceneKit import Accelerate var str:SCNVector3 = SCNVector3Make(1, 2, -8) println("vector \(str)" answer vector C.SCNVector3 How to unwrap and display the vector like [ 1, 2, -8]? Update for Swift 2: In Swift 2, structures are by default printed with all properties: let str = SCNVector3Make(1, 2, -8) print("vector \(str)") // Output: // vector SCNVector3(x: 1.0, y: 2.0, z: -8.0) You can customize the output by adopting the CustomStringConvertible protocol: extension SCNVector3 : CustomStringConvertible { public var description: String { return "[\(x), \(y)

SceneKit editor set custom class for node

↘锁芯ラ 提交于 2019-12-07 03:19:29
In the SpriteKit editor, I can assign a custom class to an SKNode, like so: However, I can't seem to find the equivalent functionality in the SceneKit editor. Does it even exist? And if I can't set a custom class for an SCNNode, is there a reason the feature isn't there, or has the Xcode team just not gotten around to it? (In other words, should I file a radar?) You can't do it in the scene editor. And you probably shouldn't do it at all. You'll have to implement your own serialization code (so that SCNScene loading works correctly). And all of the methods for searching nodes (by name, hit