Skip to content

Public API

Guillaume Sabran edited this page Dec 13, 2016 · 2 revisions

Attention

  • All the logic should happen within a DDDViewController that holds a 3D scene
  • No DDDKit API should be called before the DDDViewController did load

Overview

  • 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:
    • DDDBoolProperty
    • DDDFloatProperty
    • DDDImageTexture
    • DDDMat4Property
    • DDDVec2Property
    • DDDVec3Property
    • DDDVec4Property
    • DDDVecs3Property
    • DDDVecs4Property
    • DDDVideoPlaneTexture
  • 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:
    • DDDVertexShader
    • DDDFragmentShader
  • Shader modifiers: some custom modifiers can be added within main shader structure.

Example

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))
  }
}
Clone this wiki locally