updateWireframeAttribute method

void updateWireframeAttribute(
  1. BufferGeometry geometry
)

Implementation

void updateWireframeAttribute(BufferGeometry geometry) {
  List<int> indices = [];

  var geometryIndex = geometry.index;
  var geometryPosition = geometry.attributes["position"];
  var version = 0;

  if (geometryIndex != null) {
    var array = geometryIndex.array;
    version = geometryIndex.version;
    for (var i = 0, l = array.length; i < l; i += 3) {
      var a = array[i + 0].toInt();
      var b = array[i + 1].toInt();
      var c = array[i + 2].toInt();

      indices.addAll([a, b, b, c, c, a]);
    }
  } else {
    var array = geometryPosition.array;
    version = geometryPosition.version;

    for (var i = 0, l = (array.length / 3) - 1; i < l; i += 3) {
      var a = i + 0;
      var b = i + 1;
      var c = i + 2;

      indices.addAll([a, b, b, c, c, a]);
    }
  }

  BufferAttribute attribute;
  final max = arrayMax(indices);
  if (max != null && max > 65535) {
    attribute = Uint32BufferAttribute(Uint32Array.from(indices), 1, false);
  } else {
    attribute = Uint16BufferAttribute(Uint16Array.from(indices), 1, false);
  }

  attribute.version = version;

  // Updating index buffer in VAO now. See WebGLBindingStates

  //

  var previousAttribute = wireframeAttributes.get(geometry);

  if (previousAttribute != null) attributes.remove(previousAttribute);

  //

  wireframeAttributes.add(key: geometry, value: attribute);
}