2014/12/15

How to use 3D data by Blender for Metal in Swift 2

Continuation of : How to use 3D data by Blender for Metal in Swift / iPhone App Development Memo

2 Insert Objective-C file

Swift file ← C data file
↑The first way failed, so I inserted Objective-C file between them :
Swift file ← Objective-C ← C data file

Its header file has just declarations, the implementation file is like this :
//ObjcRobot.m
#import "ObjcRobot.h"
#import "robot3.h"

@implementation ObjcRobot

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.vertices = robot3Vertices;
        self.positions = &robot3Positions[0];
    }
    return self;
}
@end
A Swift file use this like this :
{
    let objcRobot = ObjcRobot()
    println("objcRobot.vertices = \(objcRobot.vertices)")
    println("objcRobot.positions[0] = \(objcRobot.positions[0])")
    println("objcRobot.positions[1] = \(objcRobot.positions[1])")
    println("objcRobot.positions[2] = \(objcRobot.positions[2])”)
}
access C from Swift

↑Well, it seems to be successful to access them.
This allocation also seems succeed :
vertexBuffer = device.newBufferWithBytes(objcRobot.positions, length: dataSize, options: nil)
result screenshot

↑The result of build and run, which looks good, though the color is just white, because its fragment shader just return white color.

By the way, this way needs four files for one 3D object.
robot3.h , robot3.c , ObjcRobot.h , ObjcRobot.m
I love that I don’t have to write both a header file and an implementation file in Swift. This is really neat. Therefore I don’t think this 2nd way (insert Objective-C file) is proper.
So I want the other way… , next!


Continued : How to use 3D data by Blender for Metal in Swift 3 iPhone App Development Memo

Develop | Comments(0) | Trackback(0)
Comment

管理者のみに表示