我正在使用iOS上的SceneKit开发一些代码,在我的代码中我想确定全局z平面上的x和y坐标,其中z是0.0,x和y是通过点击手势确定的.我的设置如下:
override func viewDidLoad() {
super.viewDidLoad()
// create a new scene
let scene = SCNScene()
// create and add a camera to the scene
let cameraNode = SCNNode()
let camera = SCNCamera()
cameraNode.camera = camera
scene.rootNode.addChildNode(cameraNode)
// place the camera
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
// create and add an ambient light to the scene
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light.type = SCNLightTypeAmbient
ambientLightNode.light.color = UIColor.darkGrayColor()
scene.rootNode.addChildNode(ambientLightNode)
let triangleNode = SCNNode()
triangleNode.geometry = defineTriangle();
scene.rootNode.addChildNode(triangleNode) …Run Code Online (Sandbox Code Playgroud) 我有以下内容SCNNode:
let box = SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 0)
let boxNode = SCNNode(geometry: box)
boxNode.position = SCNVector3(x: 0, y: 0, z: 0)
Run Code Online (Sandbox Code Playgroud)
如果我申请:
boxNode.scale = SCNVector3(x: 0.5, y: 0.5, z: 0.5)
Run Code Online (Sandbox Code Playgroud)
它似乎对盒子的大小没有影响.我已经检查了这个boxNode.getBoundingBoxMin(&v1, max: &v2).它始终是相同的,并在屏幕上显示相同.
我错过了什么吗?文档暗示设置比例应该影响节点的几何形状,因此是不同的大小.
谢谢.J.
我正在为我的AR应用程序提供屏幕截图功能,我注意到我拍摄的截图(通过sceneView.snapshot())比我从相机看到的更暗.我正在使用Apple的ARKit示例代码,似乎这会影响它:
camera.wantsHDR = true
camera.wantsExposureAdaptation = true
camera.exposureOffset = -1
camera.minimumExposure = -1
camera.maximumExposure = 3
Run Code Online (Sandbox Code Playgroud)
当我删除曝光设置时,快照工作正常.有什么方法可以确保快照考虑那些曝光设置?
我对了解scenekit几何有问题.
我有Blender的默认立方体,我导出为collada(DAE),并且可以将它带入scenekit ....一切都很好.
现在我想看到立方体的顶点.在DAE中,我可以看到"Cube-mesh-positions-array"的以下内容,
"1 1 -1 1 -1 -1 -1 -0.9999998 -1 -0.9999997 1 -1 1 0.9999995 1 0.9999994 -1.000001 1 -1 -0.9999997 1 -1 1 1"
现在我想在scenekit中做的是使用以下内容返回顶点:
SCNGeometrySource *vertexBuffer = [[cubeNode.geometry geometrySourcesForSemantic:SCNGeometrySourceSemanticVertex] objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
如果我处理vertexBuffer(我已经尝试了很多查看数据的方法),它似乎不正确.
有人可以解释"SCNGeometrySourceSemanticVertex"给我的内容,以及如何正确提取顶点数据?我想看到的是:
X = "float"
Y = "float"
Z = "float"
Run Code Online (Sandbox Code Playgroud)
此外,我正在调查以下类/方法,这看起来很有前景(这里有一些好的数据值),但是来自gmpe的数据显示为空,是否有人能够解释"SCNGeometryElement"的数据属性包含什么?
SCNGeometryElement *gmpe = [theCurrentNode.geometry geometryElementAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
谢谢,非常感谢,
d
我正在尝试显示一个指向z轴的金字塔,然后绕z旋转.由于我的相机在z轴上,我期待从上面看到金字塔.我设法旋转金字塔以这种方式看到它,但是当我添加动画时,它似乎在多个轴上旋转.
这是我的代码:
// The following create the pyramid and place it how I want
let pyramid = SCNPyramid(width: 1.0, height: 1.0, length: 1.0)
let pyramidNode = SCNNode(geometry: pyramid)
pyramidNode.position = SCNVector3(x: 0, y: 0, z: 0)
pyramidNode.rotation = SCNVector4(x: 1, y: 0, z: 0, w: Float(M_PI / 2))
scene.rootNode.addChildNode(pyramidNode)
// But the animation seems to rotate aroun 2 axis and not just z
var spin = CABasicAnimation(keyPath: "rotation")
spin.byValue = NSValue(SCNVector4: SCNVector4(x: 0, y: 0, z: 1, w: 2*Float(M_PI)))
spin.duration …Run Code Online (Sandbox Code Playgroud) 嗨,我试图从我的Scenekit场景中删除所有节点,但我不能为我的生活找出一种方法.
对我来说似乎合乎逻辑,必须有一个自动执行此功能的功能,但我找不到它.
在上下文中,我试图删除所有节点,以便我可以重置我的场景,这将经常发生.也许有另一种方法可以做到这一点,我会很好,我不会被迫删除所有节点.
谢谢!
我使用的是Xcode 7.3.1,Swift 2.x,iOS目标是9.3.我可以init(MDLObject mdlObject: MDLObject)在Apple文档中找到方便初始化,但我没有在我的项目中看到它.我打开标准游戏项目启动器,导入SceneKit.我试过了:
import ModelIOMDLObject我可以看到所有的SceneKit类,我可以创建MDLAsset(ModelIO的一部分,可以返回MDLObjects)实例.任何想法,也许我忽略了一些明显的东西?
我添加一个节点并尝试使用SceneKit设置阴影模糊
这是我的轻配置,我确实尝试设置shadowRadius
light = [SCNLight light];
light.type = SCNLightTypeDirectional;
light.castsShadow = true;
light.shadowMode = SCNShadowModeForward;
light.shadowRadius = 5;
light.shadowMapSize=CGSizeMake(4000, 4000);
light.orthographicScale=25;
light.zNear=1;
light.zFar=1000;
Run Code Online (Sandbox Code Playgroud)
但结果并不像我shadowRadius
在这里设置时那样柔和:

我确实尝试添加samplecount
light = [SCNLight light];
light.type = SCNLightTypeDirectional;
light.castsShadow = true;
light.shadowMode = SCNShadowModeForward;
light.shadowRadius = 5;
// add samplecount
light.shadowSampleCount = 5;
light.shadowMapSize=CGSizeMake(4000, 4000);
light.orthographicScale=25;
light.zNear=1;
light.zFar=1000;
Run Code Online (Sandbox Code Playgroud)
阴影看起来很柔和,但这个阴影从节点的底部开始(z坐标为0).我花了很多时间只在节点的边缘设置软阴影,而不是从底部设置.但没有结果.
添加两个节点交叉(不仅仅是节点和几何体作为SCNFloor)时也会出现此问题
我的问题是如何使用方向光获得阴影模糊(柔和阴影).
任何帮助,将不胜感激!
我有一个CPU密集型任务,我希望它使用更少的CPU并占用更多时间.
我在启动时将大量SCNNodes加载到场景中.它占用了大量内存,我希望它以安全的速度工作,而不是滞后我的系统或可能导致它崩溃.
这是我用来加载节点的代码.
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void){
NSLog(@"Start Loading Level");
SCNNode *cameraNode = [SCNNode node];
cameraNode.camera = [SCNCamera camera];
cameraNode.camera.zFar = 5000;
cameraNode.position = SCNVector3Make(0, 3000, 0);
cameraNode.rotation = SCNVector4Make(1, 0, 0, -M_PI_2);
[scene.rootNode addChildNode:cameraNode];
for (int i = 0; i < 100000; i++)
{
int side = 3000;
SCNNode *node = [SCNNode node];
node.geometry = [SCNBox boxWithWidth:1 height:1 length:1 chamferRadius:0];
node.position = SCNVector3Make(arc4random_uniform(side) - side / 2.0,
0,
arc4random_uniform(side) - side / 2.0);
[scene.rootNode addChildNode:node];
}
dispatch_async(dispatch_get_main_queue(), ^(void){
NSLog(@"Finished"); …Run Code Online (Sandbox Code Playgroud) 我试图通过SceneKit和Model I/0在.obj 3d模型上应用.mtl文件纹理.
当我尝试在其上应用纹理的.jpg时,我的代码工作正常:
let url = NSBundle.mainBundle().URLForResource("chair", withExtension: "obj")
let asset = MDLAsset(URL: NSURL(string:url)!)
guard let object = asset.objectAtIndex(0) as? MDLMesh else {
//fatalError("Failed to get mesh from asset.")
return
}
if shouldApplyTexture == true {
var textureFileName = "chair.mtl"
// Create a material from the various textures
let scatteringFunction = MDLScatteringFunction()
let material = MDLMaterial(name: "baseMaterial", scatteringFunction: scatteringFunction)
material.setTextureProperties(textures: [
.BaseColor:textureFileName])
// Apply the texture to every submesh of the asset
for submesh in object.submeshes! {
if let …Run Code Online (Sandbox Code Playgroud)