小编ARG*_*Geo的帖子

为什么iOS 8上的SceneKit无法编译我的自定义着色器?

我创建了一个基于游戏模板的新项目,其中SceneKit作为游戏技术,Swift作为语言.我尝试使用自定义着色器.这是设置代码:

var material = SCNMaterial()
var program = SCNProgram()

// Read the vertex shader file and set its content as our vertex shader
if let vertexShaderPath = NSBundle.mainBundle().pathForResource("VertexShader", ofType:"vsh") {
    let vertexShaderAsAString = NSString(contentsOfFile: vertexShaderPath, encoding: NSUTF8StringEncoding, error: nil)
    program.vertexShader = vertexShaderAsAString
}

// Read the fragment shader file and set its content as our fragment shader
if let fragmentShaderPath = NSBundle.mainBundle().pathForResource("FragmentShader", ofType:"fsh") {
    let fragmentShaderAsAString = NSString(contentsOfFile: fragmentShaderPath, encoding: NSUTF8StringEncoding, error: nil)
    program.fragmentShader = fragmentShaderAsAString
}

// Give a …
Run Code Online (Sandbox Code Playgroud)

opengl-es fragment-shader ios scenekit swift

2
推荐指数
1
解决办法
2105
查看次数

在纹理的SceneKit绘画与纹理坐标

我有一个Collada模型,我加载到SceneKit.当我在模型上执行hittest时,我能够检索被击中的模型的纹理坐标.

使用这些纹理坐标,我应该能够用颜色替换纹理坐标.所以这种方式我应该可以在模型上绘制

如果我错了,请纠正我.

到目前为止我读了很多文章,但我没有把我的着色器弄好.(虽然我确实得到了一些时髦的效果;-)

我的顶点着色器:

precision highp float;

attribute vec4 position;
attribute vec2 textureCoordinate;
attribute vec2 aTexureCoordForColor; //coordinates from the hittest

uniform mat4 modelViewProjection;

varying vec2 aTexureCoordForColorVarying; // passing to the fragment shader here
varying vec2 texCoord;

void main(void) {
    // Pass along to the fragment shader
    texCoord = textureCoordinate;
    aTexureCoordForColorVarying = aTexureCoordForColor; //assigning here
    // output the projected position
    gl_Position = modelViewProjection * position;
}
Run Code Online (Sandbox Code Playgroud)

我的片段着色器

precision highp float;

uniform sampler2D yourTexture;

uniform vec2 uResolution;
uniform int uTexureCoordsCount;

varying …
Run Code Online (Sandbox Code Playgroud)

shader opengl-es glsl scenekit ios8

2
推荐指数
1
解决办法
1660
查看次数

Tube Physics Body 像 SCNCylinder 一样工作,但如何让它像 SCNTube 一样工作?

我正在尝试在 SceneKit 中制作一个管子及其物理体。

let BoxGeometry = SCNTube(innerRadius: 5, outerRadius: 12.5, height: 4)
Box = SCNNode(geometry: BoxGeometry)
Box.pivot = SCNMatrix4MakeRotation(Float(M_PI_2/8), 0, 1, 0)
Box.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Static, shape: nil)
Box.physicsBody?.mass = 5
Box.categoryBitMask = colorCategory
scene.rootNode.addChildNode(Box)
Run Code Online (Sandbox Code Playgroud)

然而,当另一个物体落在这个物体上时,它不会通过中心。相反,它似乎悬浮在空气中。它的作用就像物理体是一个完整的圆柱体,而不是中间有孔的管子。我该如何解决这个问题,以便物体可以通过中心?管子外观符合预期。

谢谢!

scenekit swift scnnode

2
推荐指数
1
解决办法
1789
查看次数

纠正SCNCamera的"视野"

我试图找出ipad和iphone上场景工具包中视野的正确值.默认值60 degree对屏幕边缘的球体有不良影响.球体呈椭圆形.值34 degree使得天空盒变得像素化.iPad和iPhone的正确值是多少?

_cameraNode = [SCNNode node];
_cameraNode.position = SCNVector3Make(0, 0, 500);

[scene.rootNode addChildNode:_cameraNode];

_cameraNode.camera = [SCNCamera camera];
_cameraNode.camera.automaticallyAdjustsZRange = YES;

#if TARGET_OS_IPHONE
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    _cameraNode.camera.yFov = 55;

} else #endif {
    _cameraNode.camera.xFov = 34;
}

scnView.pointOfView = _cameraNode;
Run Code Online (Sandbox Code Playgroud)

camera ios scenekit scncamera

2
推荐指数
1
解决办法
2041
查看次数

SceneKit - SCNCamera自上而下的视图

我是来自2D SpriteKit的SceneKit的新手,并试图弄清楚如何调整相机,使其处于面向世界的顶端.我的位置部分是正确的,但是在旋转时我会卡住.如果我调整X,Y orZ axis, nothing seems to happen, however on the W axis the slightest change (even0.1"更高或更低",似乎将摄像机向未知方向移动.我究竟做错了什么?

cameraNode.position = SCNVector3Make(0, 10, 0)
cameraNode.rotation = SCNVector4Make(0, 0, 0, 0.5)
Run Code Online (Sandbox Code Playgroud)

objective-c quaternions ios scenekit swift

2
推荐指数
1
解决办法
2106
查看次数

立体声 ARSCNview 使 VR 和 AR 混合

我想混合virtual realityaugmented reality。目标是我有一个立体相机(每只眼睛)。

我试图将两个ARSCNView放入一个,viewCotnroller但 ARKit 似乎只能同时启用一个ARWorldTrackingSessionConfiguration。我怎样才能做到这一点?

我研究过将视图的图形表示复制到另一个视图,但无法找到。请帮我找到解决方案。

我找到了这个链接,也许它可以照亮我们: ARKit with multiple users

这是我的问题的示例:

https://www.youtube.com/watch?v=d6LOqNnYm5s

PS:之前不像我的帖子,评论为什么!

augmented-reality swift virtual-reality arkit arscnview

2
推荐指数
1
解决办法
1173
查看次数

ARKit中的变换中的不同列代表什么?

A ARAnchor有6列,其中最后3列代表x,y和z坐标.
我想知道其他(第一)3列代表什么?

augmented-reality scenekit swift arkit realitykit

2
推荐指数
2
解决办法
1637
查看次数

ARKit / ARCore开发中的3D模型基础

我是iOS和Android AR游戏开发的初学者。我有以下问题:

  1. ARKit(适用于iOS)和ARCore(适用于Android)分别支持哪种3D模型格式?(我尝试过.dae.obj得到ARkit的支持,但尚未测试ARCore。)

  2. 我们的3D模型供应商只能提供FBX格式。如何将其转换为ARKit和ARCore支持的格式?我尝试使用3D模型转换器,但是转换后的模型没有纹理。

augmented-reality scenekit arkit arcore sceneform

2
推荐指数
2
解决办法
3383
查看次数

ARKit – 在平面上投射 3D 物体的阴影

这是我用来在平面上显示对象的函数。

private func loadScene(path: String) -> SCNNode {

    let spotLight = SCNLight()
    spotLight.type = SCNLight.LightType.probe

    spotLight.spotInnerAngle = 30.0
    spotLight.spotOuterAngle = 80.0
    spotLight.castsShadow = true

    let result = SCNNode()
    result.light = spotLight
    result.position = SCNVector3(-10.0, 20.0, 10.5)
    result.addChildNode(result)

    let scene = SCNScene(named: path)!
    for node in scene.rootNode.childNodes {
        result.addChildNode(node)
    }       
    return result
}
Run Code Online (Sandbox Code Playgroud)

我想在平面上显示阴影,如下图所示。

平面上有阴影的图像

当我设置如下聚光灯类型时

spotLight.type = SCNLight.LightType.directional
Run Code Online (Sandbox Code Playgroud)

它用明暗阴影显示对象本身,并且不会将阴影落在表面上。

有人可以指导我如何实现如图所示的输出吗?

xcode augmented-reality scenekit swift arkit

2
推荐指数
1
解决办法
2380
查看次数

如何使用 ARKit 在 ARSCNView 中正确放置 3D 对象?

我很长时间试图将 3D 对象放置在 SceneView 中的正确位置,该对象正确添加到 SceneView 中,但其位置向右或向左转,

func addObject(x: Float = 0, y: Float = 0, z: Float = -0.5) {

    guard let shipScene = SCNScene(named: "art.scnassets/house.scn"),
        let shipNode = shipScene.rootNode.childNode(withName: "house", recursively: false)
    else {
        return
    }
    shipNode.scale = SCNVector3(0.01, 0.01, 0.01)
    shipNode.position = SCNVector3(x,y,z)
    sceneView.scene.rootNode.addChildNode(shipNode)
}
Run Code Online (Sandbox Code Playgroud)

这是我添加的代码,这个问题是否与相机位置有关,我也改变了,它似乎不起作用。例如,请参考附件图片。

在此处输入图片说明

如何正确放置对象?

scenekit swift arkit

2
推荐指数
1
解决办法
1564
查看次数