renderBufferDirect method
void
renderBufferDirect()
Implementation
void renderBufferDirect(
Camera camera,
Object3D? scene,
BufferGeometry geometry,
Material material,
Object3D object,
Map<String, dynamic>? group,
) {
scene ??= _emptyScene;
final frontFaceCW = (object is Mesh && object.matrixWorld.determinant() < 0);
WebGLProgram program = setProgram(camera, scene, geometry, material, object);
state.setMaterial(material, frontFaceCW);
BufferAttribute? index = geometry.index;
BufferAttribute? position = geometry.attributes["position"];
if (index == null) {
if (position == null || position.count == 0) return;
}
else if (index.count == 0) {
return;
}
//
int rangeFactor = 1;
if (material.wireframe == true) {
index = geometries.getWireframeAttribute(geometry);
if(kIsWeb){
rangeFactor = 2;
}
}
if (geometry.morphAttributes["position"] != null || geometry.morphAttributes["normal"] != null) {
morphtargets.update(object, geometry, material, program);
}
bindingStates.setup(object, material, program, geometry, index);
Map<String, dynamic> attribute;
BaseWebGLBufferRenderer renderer = bufferRenderer;
if (index != null) {
attribute = attributes.get(index);
renderer = indexedBufferRenderer;
renderer.setIndex(attribute);
}
int dataCount = (index != null) ? index.count : position!.count;
final rangeStart = geometry.drawRange["start"]! * rangeFactor;
final rangeCount = geometry.drawRange["count"]! * rangeFactor;
final groupStart = group != null ? group["start"] * rangeFactor : 0;
final int groupCount = group != null ? group["count"] * rangeFactor : double.maxFinite.toInt();
final drawStart = math.max<int>(rangeStart, groupStart);
final drawEnd = math.min<int>(math.min(dataCount, rangeStart + rangeCount), groupStart + groupCount) - 1;
final drawCount = math.max(0, drawEnd - drawStart + 1);
if (drawCount == 0) return;
if (object is Mesh) {
if (material.wireframe) {
state.setLineWidth(material.wireframeLinewidth! * getTargetPixelRatio());
renderer.setMode(WebGL.LINES);
}
else {
renderer.setMode(WebGL.TRIANGLES);
}
}
else if (object is Line) {
double? lineWidth = material.linewidth;
lineWidth ??= 1; // Not using Line*Material
state.setLineWidth(lineWidth * getTargetPixelRatio());
if (object is LineSegments) {
renderer.setMode(WebGL.LINES);
}
else if (object is LineLoop) {
renderer.setMode(WebGL.LINE_LOOP);
}
else {
renderer.setMode(WebGL.LINE_STRIP);
}
}
else if (object is Points) {
renderer.setMode(WebGL.POINTS);
}
else if (object is Sprite) {
renderer.setMode(WebGL.TRIANGLES);
}
if (object is InstancedMesh) {
renderer.renderInstances(drawStart, drawCount, object.count!);
}
else if (geometry is InstancedBufferGeometry) {
final instanceCount = math.min(geometry.instanceCount!, geometry.maxInstanceCount!);
renderer.renderInstances(drawStart, drawCount, instanceCount);
}
else {
renderer.render(drawStart, drawCount);
}
}