Object constructor

Object({
  1. Vector3? position,
  2. Vector3? rotation,
  3. Vector3? scale,
  4. String? name,
  5. Mesh? mesh,
  6. Scene? scene,
  7. Object? parent,
  8. List<Object>? children,
  9. bool backfaceCulling = true,
  10. bool lighting = false,
  11. bool visiable = true,
  12. bool normalized = true,
  13. String? fileName,
  14. bool isAsset = true,
})

Implementation

Object({
  Vector3? position,
  Vector3? rotation,
  Vector3? scale,
  this.name,
  Mesh? mesh,
  Scene? scene,
  this.parent,
  List<Object>? children,
  this.backfaceCulling = true,
  this.lighting = false,
  this.visiable = true,
  bool normalized = true,
  String? fileName,
  bool isAsset = true,
}) {
  if (position != null) position.copyInto(this.position);
  if (rotation != null) rotation.copyInto(this.rotation);
  if (scale != null) scale.copyInto(this.scale);
  updateTransform();
  this.mesh = mesh ?? Mesh();
  this.children = children ?? <Object>[];
  for (Object child in this.children) {
    child.parent = this;
  }
  this.scene = scene;

  // load mesh from obj file
  if (fileName != null) {
    loadObj(fileName, normalized, isAsset: isAsset).then((List<Mesh> meshes) {
      if (meshes.length == 1) {
        this.mesh = meshes[0];
      } else if (meshes.length > 1) {
        // multiple objects
        for (Mesh mesh in meshes) {
          add(Object(name: mesh.name, mesh: mesh, backfaceCulling: backfaceCulling, lighting: lighting));
        }
      }
      this.scene?.objectCreated(this);
    });
  } else {
    this.scene?.objectCreated(this);
  }
}