scenekit

Using existing opengl texture with scenekit

老子叫甜甜 提交于 2019-12-30 03:23:04
问题 According to Apple's documentation you can use NSColor, NSImage and CALayer to provide a texture to a SCNMaterialProperty. SCNMaterialProperty I am however wondering if there is a way to provide an existing OpenGL texture, which has been created with glGenTextures and rendered into separately. I can of course read the buffer of the texture, setup an NSImage, and provide that one to the SCNMaterialProperty; but for performance reasons that is obviously not optimal. It would make sense to

SceneKit - Draw 3D Parabola

送分小仙女□ 提交于 2019-12-29 11:40:32
问题 I'm given three points and need to draw a smooth 3D parabola. The trouble is that curved line is choppy and has some weird divots in it Here is my code... func drawJump(jump: Jump){ let halfDistance = jump.distance.floatValue/2 as Float let tup = CalcParabolaValues(0.0, y1: 0.0, x2: halfDistance, y2: jump.height.floatValue, x3: jump.distance.floatValue, y3: 0) println("tuple \tup") var currentX = 0 as Float var increment = jump.distance.floatValue / Float(50) while currentX < jump.distance

Cannot create a Screenshot of a SCNView

一个人想着一个人 提交于 2019-12-29 07:07:32
问题 Is it possible to get a screenshot of an SCNView? I'm trying with the below code, but it always comes out white... NSRect bounds = [window.contentView bounds]; NSImage *screenshot = [[NSImage alloc] initWithData:[window.contentView dataWithPDFInsideRect:bounds]]; It works fine when the view is a standard NSView... 回答1: SceneKit uses an OpenGL context to draw. You can't turn that into PDF data as easily as a Quartz based context (as used by "normal" AppKit views). But you can grab the

ARKit – Drag a node along a specific axis (not on a plane)

China☆狼群 提交于 2019-12-29 04:57:11
问题 I am trying to drag a node exactly where my finger is on the screen on the Y -axis. But I don't find any way to do it, here is my current code. Do you have any idea? var movedObject:SCNNode? @objc func handlePan(_ recognizer: UIPanGestureRecognizer) { if recognizer.state == .began { let tapPoint: CGPoint = recognizer.location(in: sceneView) let result = sceneView.hitTest(tapPoint, options: nil) if result.count == 0 { return } let hitResult: SCNHitTestResult? = result.first movedObject =

Drawing a line between two points using SceneKit

↘锁芯ラ 提交于 2019-12-28 05:16:27
问题 I have two points (let's call them pointA and pointB) of type SCNVector3. I want to draw a line between them. Seems like it should be easy, but can't find a way to do it. I see two options, both have issues: Use a SCNCylinder with a very small radius, with length |pointA-pointB| and then position it/rotate it. Use a custom SCNGeometry but not sure how; would have to define two triangles to form a very thin rectangle perhaps? It seems like there should be an easier way of doing this, but I can

Inefficient parsing of Vertex and Index data, looking for more efficient methods

狂风中的少年 提交于 2019-12-25 08:49:21
问题 I wrote a method to parse an array containing vertex data. The goal of the method was to produce a new array of unique vertices and a new index from that data. This is the struct I used to store the vertices in the array. struct Vertex: Hashable { var x, y, z, nx, ny, nz, s, t: Float var hashValue: Int { return "\(self.x),\(self.y),\(self.z),\(self.nx),\(self.ny),\(self.nz),\(self.s),\(self.t),".hashValue } static func ==(lhs: Vertex, rhs: Vertex) -> Bool { return lhs.hashValue == rhs

SceneKit with SpriteKit intersection of nodes

自作多情 提交于 2019-12-25 08:18:30
问题 Hi I want to have a selection box on my game. I assume that making with 'SpriteKit' overlay is the easiest way to do But is there any API to detect intersection of 'SKShapeNode' and 'SCNNode' (Ignoring the Z axis ofcourse) ? What have I tried to do: _unitsArray is an array of SCNNodes that I wish to have they're bounding boxes in a SKScene for (SCNNode * node in _unitsArray) { SCNVector3 min = SCNVector3Zero; SCNVector3 max = SCNVector3Zero; [node getBoundingBoxMin:&min max:&max]; NSLog(@"Min

How to create an array of SCNNode in swift

ぐ巨炮叔叔 提交于 2019-12-25 06:59:19
问题 I want to create a fund to create an array of nodes. My declaration is as follows: func createSphereNode () { var spheres = [SCNNode()] let sphereGeometry = SCNSphere(radius: 2.5) let sphereMaterial = SCNMaterial() sphereMaterial.diffuse.contents = UIColor.greenColor() sphereGeometry.materials = [sphereMaterial] for var i=0;i<15;i++ { let gravityFields = SCNPhysicsField.radialGravityField() gravityFields .strength = 0 spheres[i] = SCNNode(geometry: sphereGeometry) spheres[i].position =

Why iPhones XR, XS and XS Max, doesn't apply environment image to scene in ARKit?

会有一股神秘感。 提交于 2019-12-25 03:45:33
问题 After download everything from backend (textures, environment, 3D object) into the app, I created a new SCNScene programmatically, with all this stuff. It works perfectly on all devices, but on iPhones XR, XS and XS Max the textures of those models, that need environment image appear black. As if "None" environment was set. I can't post code nor images, it's not my project. I'd just like to know if anyone has experienced any problems of this kind, with iPhone XR, XS or XS Max and ARKit. It's

Cannot get locationInView: for this type of NSTouch assertion error when trying to retrieve location

南笙酒味 提交于 2019-12-25 01:29:51
问题 I'm trying to retrieve the mouse location after a user clicks on a specific SCNNode. I eventually want to perform a hit test to determine which SCNNode was clicked. I have the following code but once I run the project I get an assertion error stating: "Cannot get locationInView: for this type of NSTouch". Any help would be appreciated. override func touchesBegan(with event: NSEvent) { let touch = event.touches(for: self.view) if #available(OSX 10.12.2, *) { let location = touch.first?