projectObject method

void projectObject(
  1. Object3D object,
  2. Camera camera,
  3. int groupOrder,
  4. bool sortObjects,
)

Implementation

void projectObject(
    Object3D object, Camera camera, int groupOrder, bool sortObjects) {
  // print("projectObject object: ${object} name: ${object.name} tag: ${object.tag}  ${object.visible} ${object.scale.toJSON()} ${object.children.length}  ");

  if (object.visible == false) return;

  bool visible = object.layers.test(camera.layers);

  // print("projectObject object: ${object.type} ${object.id} visible: ${visible} groupOrder: ${groupOrder} sortObjects: ${sortObjects} ");

  if (visible) {
    if (object.type == "Group") {
      groupOrder = object.renderOrder;
    } else if (object.type == "LOD") {
      dynamic u = object;
      if (object.autoUpdate == true) u.update(camera);
    } else if (object is Light) {
      currentRenderState!.pushLight(object);

      if (object.castShadow) {
        currentRenderState!.pushShadow(object);
      }
    } else if (object.type == "Sprite") {
      if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
        if (sortObjects) {
          _vector3
              .setFromMatrixPosition(object.matrixWorld)
              .applyMatrix4(projScreenMatrix);
        }

        BufferGeometry geometry = objects.update(object);
        var material = object.material;

        if (material.visible) {
          currentRenderList!
              .push(object, geometry, material, groupOrder, _vector3.z, null);
        }
      }
    } else if (object is Mesh || object is Line || object is Points) {
      if (object is SkinnedMesh) {
        // update skeleton only once in a frame
        if (object.skeleton!.frame != info.render["frame"]) {
          object.skeleton!.update();
          object.skeleton!.frame = info.render["frame"]!;
        }
      }

      // print("object: ${object.type} ${!object.frustumCulled} ${_frustum.intersectsObject(object)} ");

      if (!object.frustumCulled || _frustum.intersectsObject(object)) {
        if (sortObjects) {
          _vector3
              .setFromMatrixPosition(object.matrixWorld)
              .applyMatrix4(projScreenMatrix);
        }

        var geometry = objects.update(object);

        var material = object.material;

        // TODO material 类型可能为 各种Material 或者各种List<Material>
        if (material is List) {
          var groups = geometry.groups;

          if (groups.isNotEmpty) {
            for (var i = 0, l = groups.length; i < l; i++) {
              Map<String, dynamic> group = groups[i];
              var groupMaterial = material[group["materialIndex"]];

              if (groupMaterial != null && groupMaterial.visible) {
                currentRenderList!.push(object, geometry, groupMaterial,
                    groupOrder, _vector3.z, group);
              }
            }
          } else {
            for (var element in material) {
              if (element.visible) {
                currentRenderList!.push(
                    object, geometry, element, groupOrder, _vector3.z, null);
              }
            }
          }
        } else if (material != null && material.visible) {
          currentRenderList!
              .push(object, geometry, material, groupOrder, _vector3.z, null);
        }
      }
    }
  }

  var children = object.children;

  for (var i = 0, l = children.length; i < l; i++) {
    projectObject(children[i], camera, groupOrder, sortObjects);
  }
}