小编Hal*_*ler的帖子

更改SCNNode/Geometry/Material的颜色

我是SceneKit的新手,正在开始测试应用程序.我有一个移动的小立方体.我想添加轴(X,Y,Z).我是这样创造的.

    SCNVector3 xPositions[] = {SCNVector3Make(-50, 0, 0), SCNVector3Make(50, 0, 0)};

    int indicies[] = {0, 1};
    NSData *indexData = [NSData dataWithBytes:indicies length:sizeof(indicies)];

// X axis
    SCNGeometrySource *xSource = [SCNGeometrySource geometrySourceWithVertices:xPositions count:2];
    SCNGeometryElement *xElement = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeLine primitiveCount:2 bytesPerIndex:sizeof(int)];
    SCNGeometry *xAxis = [SCNGeometry geometryWithSources:@[xSource] elements:@[xElement]];
    SCNNode *xNode = [SCNNode nodeWithGeometry:xAxis];
    [self.gameView.scene.rootNode addChildNode:xNode];

    // Y axis
    SCNVector3 yPositions[] = {SCNVector3Make(0, -50, 0), SCNVector3Make(0, 50, 0)};
    SCNGeometrySource *ySource = [SCNGeometrySource geometrySourceWithVertices:yPositions count:2];
    SCNGeometryElement *yElement = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeLine primitiveCount:2 bytesPerIndex:sizeof(int)];
    SCNGeometry *yAxis = …
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c scenekit

5
推荐指数
1
解决办法
5103
查看次数

iOS - 当字符串以算术运算符+ - */开头时,NSPredicate string.length总是求值为0

我有一个简单的方法,使用NSPredicate返回comments.length> 0的行数.

问题是,我发现当Comment列以+ - *或/开头时,length属性总是计算为0,因此该行被排除在计数之外.

我在SQLite浏览器中打开了表,并验证了该列是VARCHAR.使用SQLite查询检查字符串长度工作得很好(LENGTH(ZComments)> 0),所以这必须是CoreData问题.

这是我的功能......

-(int)getCommentsCount{
    NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
    [request setIncludesSubentities:YES];
    [request setEntity:[NSEntityDescription entityForName:@"InspectionRecord" inManagedObjectContext:managedObjectContext]];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(comments.length > 0)"];
    [request setPredicate:predicate];

    NSError *err;
    NSUInteger count = [managedObjectContext countForFetchRequest:request error:&err];

    //count is ALWAYS 0 if 'comments' starts with + - * or /     WHYYY???      
    return count;
}
Run Code Online (Sandbox Code Playgroud)

我能够通过检查空/空字符串而不是使用.length来解决这个问题,但是我真的很想知道.当字符串以某些字符开头时,.length会失败.

这发生在任何人身上吗?

core-data nspredicate

4
推荐指数
1
解决办法
3258
查看次数

SceneKit - 将立方体纹理映射到框

我有一个看起来像立方体的纹理

在此输入图像描述

我想在SceneKit视图中的立方体上使用它.我正在使用SceneKit几何体SCNBox.不幸的是,结果是纹理完全投射在每个面上,而不是仅使用相应的部分:

let videoGeometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0)
videoGeometry.firstMaterial?.isDoubleSided = true
videoGeometry.firstMaterial?.diffuse.contents = UIImage(named: "test")!
Run Code Online (Sandbox Code Playgroud)

我知道我可以在几何体上使用着色器修改器,但我不知道从哪里开始.由于纹理目前使用了六次,我的直觉是SCNBox几何可能不适合我的目标,但我真的不知道如何改变它.

opengl-es geometry-shader ios scenekit

4
推荐指数
1
解决办法
865
查看次数

如何在WatchOS 3中播放将在手表扬声器上播放的自定义声音

我已经读过,我们现在可以在watchos 3中的苹果手表上播放自定义声音.

根据苹果的声明显然有,但我没有一个例子来测试它:使用SCNAudioSource或SCNAudioPlayer实现的3D空间音频.相反,使用playAudioSource:waitForCompletion:或WatchKit声音或触觉API.在此处找到:https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewInwatchOS/Articles/watchOS3.html

有人可以举一个简单的例子.我没有在我的应用程序中使用SceneKit,因为我不需要它,但如果这是播放自定义声音的唯一方法,那么我想知道完成此操作所需的最少代码.最好是在目标c中,但我会把它带到任何形状.如果这也更容易,我可以使用SpriteKit.

这是我到目前为止所做的,但它不起作用:

SCNNode * audioNode = [[SCNNode alloc] init];

SCNAudioSource * audioSource = [SCNAudioSource audioSourceNamed:@"mysound.mp3"];
SCNAudioPlayer * audioPlayer = [SCNAudioPlayer audioPlayerWithSource:audioSource];  
[audioNode addAudioPlayer:audioPlayer];

SCNAction * play = [SCNAction playAudioSource:audioSource waitForCompletion:YES];
[audioNode runAction:play];
Run Code Online (Sandbox Code Playgroud)

audio sprite-kit watchos-3

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

获取节点scenekit中顶点的位置

我有一个以编程方式创建的平面,我想获得该平面所具有的一个顶点的坐标.像这样的东西:print(Plane.vertices[1].position)它可能会打印如下:(x:1,y:1),并print(Plane.vertices[2].position)打印(x - 1,y:1)

在此输入图像描述 这就是我创造飞机的方式:

let positions = [SCNVector3Make(  0, -0.1,  0),
                         SCNVector3Make(  0.3, -0.1,  0),

                         SCNVector3Make(  0,  0.1,  0),
                         SCNVector3Make(  0.3,  0.1,  0),
                         ]
        let indices :[UInt16] = [

            0, 1, 2,
            1, 3, 2,
            ]

        let vertexSource = SCNGeometrySource(vertices: positions, count: 4)
        let indexData = NSData(bytes: indices, length: MemoryLayout<CInt>.size * indices.count)


        let newElement = SCNGeometryElement(data: NSData(bytes: indices, length: indices.count * MemoryLayout<Int16>.size) as Data, primitiveType: .triangles , primitiveCount: 2, bytesPerIndex: MemoryLayout<Int16>.size)

        let geometry = SCNGeometry(sources: [vertexSource], …
Run Code Online (Sandbox Code Playgroud)

scenekit swift

4
推荐指数
1
解决办法
2460
查看次数

SCNCylinder diffuse.contents - 为半径和高度部分渲染不同的内容

有没有办法为半径和高度部分呈现不同的内容

我正在尝试使用圆柱形对象并使用SCMaterial实例的diffuse.contents在其上渲染图像

myCustomMaterial.diffuse.contents = UIImage(named: "image")
Run Code Online (Sandbox Code Playgroud)

它在圆柱体上渲染此图像,但是在高度和渲染部分上渲染相同的图像.

我想在高度部分上呈现与半径部分不同的图像.可能吗?

scenekit

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

UITextfield在UITableViewCells中 - 关闭键盘

UITextfields在每个表格单元格中都有几个.通过点击"完成"按钮或触摸键盘外部,键盘应该被解除.

我的问题:textFieldShouldEndEditing只有当我点击另一个文本字段并且键盘不会被解除时才调用该方法.我想我已经实现了必要的部分(委托和协议方法).

有谁知道我在这里失踪了....?

这是代码(相关部分):

class myVC: UIViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate  {...
Run Code Online (Sandbox Code Playgroud)

这是细胞设置......

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let tcell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "tbCell")

    let textfield: UITextField = UITextField(frame:...

    switch (indexPath.section) {
    case 0: ...
    case 1: 
            textfield.text = section2[indexPath.row]
            tcell.addSubview(textfield)
            textfield.delegate = self
            return tcell
Run Code Online (Sandbox Code Playgroud)

这个协议方法:

func textFieldShouldEndEditing(textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        print("method is called")
        return true
    }
Run Code Online (Sandbox Code Playgroud)

谢谢!

uitextfield ios uitextfielddelegate swift

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

更改SCNText上的字符串值不会产生任何更改

我正在阅读陀螺仪并将SCNText几何形状的弦更改为陀螺仪的偏航值.这种变化发生在陀螺仪处理器内部,每1/30秒调用一次.在SCNText几何与Interface Builder中创建.

我正在使用此代码来检索对文本的引用:

SCNNode *textNode = [scene.rootNode childNodeWithName:@"yawText" recursively:YES];
self.text = [textNode geometry]; 
//self.txt is declared as @property (strong, nonatomic) SCNText *text;
Run Code Online (Sandbox Code Playgroud)

稍后在陀螺仪手柄上我这样做:

CGFloat yaw = convertToDegrees(attitude.yaw);
[weakSelfText setString:[NSString stringWithFormat:@"%.1f", yaw]];
NSLog(@"yaw = %1f", yaw);

// I had to declare weakSelfText outside the gyro handler
// because Xcode was complaining
// weakSelfText is declared like this
// __weak typeof(self.text) weakSelfText = self.text;
Run Code Online (Sandbox Code Playgroud)

NSLog正确打印值但是没有变化SCNText.

是的,我试图更改主线程上的文本.没变.

ios scenekit scnnode scntext

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

快速球体结合星数据

我想构建一个观星应用程序。现在我已经构建了一个球体并用星图覆盖它(基于天体坐标)。(https://svs.gsfc.nasa.gov/cgi-bin/details.cgi?aid=3895

现在我有一个 json 文件,其中包含来自 YBS 的明星目录。(也基于天体坐标)。(http://tdc-www.harvard.edu/catalogs/bsc5.html

我想将数据与星图结合起来,希望每当我的相机节点转向那个地方时,地图都显示星座的名称。但我不知道如何将数据和领域结合起来。因为球体会因用户的纬度和时间而旋转。星体数据的坐标也必须改变。

有人有建议吗?

astronomy swift

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

我的 MacOS 应用程序的数据库位于哪里?

使用 Core Data 时,MacOS 应用程序的数据库位置是什么?

我在 Mac 上到处搜索,但没有找到。
我关闭了隐藏文件,并且确信我的数据库中有数据。另外我不使用应用程序沙箱。

macos cocoa core-data macos-sierra

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

试图在swift中声明一个自定义对象数组

这是我的代码

    var planetNames = ["mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"] //names of the planets

    for currentRing in 0..<orbitMarkers.count
    {
        var planetNames[currentRing] = planet(size: 1.2)

    }
Run Code Online (Sandbox Code Playgroud)

这是我的课

class planet
{
   var size: CGFloat
   init(size: CGFloat)
   {
     self.size = size
   }
}
Run Code Online (Sandbox Code Playgroud)

我试图弄清楚如何制作一组8个新的"行星"物体

arrays swift

0
推荐指数
1
解决办法
3867
查看次数