-
Notifications
You must be signed in to change notification settings - Fork 16
Public API
Guillaume Sabran edited this page Dec 13, 2016
·
2 revisions
- All the logic should happen within a
DDDViewControllerthat holds a 3D scene - No DDDKit API should be called before the
DDDViewControllerdid load
-
DDDViewController: a UIViewController that holds the 3D scene -
DDDScene: holds the 3D scene elements -
DDDNode: a single element -
DDDGeometry: describes a shape, with position, normal, texture mapping etc. It can be used by several nodes. Some premade geometries include:-
DDDGeometry.Sphere: a sphere that maps an equirectangular texture -
DDDGeometry.Cube: a cube that maps a cubic texture
-
-
DDDMaterial: describe an aspect, with textures, shader program, properties etc. It can be used by several nodes. -
DDDProperty: a property that can be used by a shader. Some easy to use properties include:DDDBoolPropertyDDDFloatPropertyDDDImageTextureDDDMat4PropertyDDDVec2PropertyDDDVec3PropertyDDDVec4PropertyDDDVecs3PropertyDDDVecs4PropertyDDDVideoPlaneTexture
-
DDDShaderProgram: a vertex/fragment program that takes a bunch of inputs and computes the final aspect. -
DDDShader: one of the program shader. It should be either:DDDVertexShaderDDDFragmentShader
- Shader modifiers: some custom modifiers can be added within main shader structure.
import DDDKit
class ViewController: DDDViewController {
override func viewDidLoad() {
super.viewDidLoad()
guard let cgImage = UIImage(named: "foo.jpg")?.cgImage else { return }
// creates an element
let node = DDDNode()
// give it a shape
node.geometry = DDDGeometry.Sphere(radius: 20.0, orientation: .inward)
do {
// use a shader that sample from an image
let fShader = try DDDFragmentShader(from: "imageTexture", withExtention: "fsh")
let program = try DDDShaderProgram(fragment: fShader)
node.material.shaderProgram = program
// pass an image
let imageTexture = DDDImageTexture(image: cgImage)
node.material.set(property: imageTexture, for: "u_image")
} catch {
print("could not set shaders: \(error)")
}
// add the node to the scene
scene.add(node: node)
// move it
node.position = Vec3(v: (0, 0, -30))
}
}