renderBufferDirect method
void
renderBufferDirect()
Implementation
void renderBufferDirect(
Camera camera,
Object3D? scene,
BufferGeometry geometry,
Material material,
Object3D object,
Map<String, dynamic>? group,
) {
// print("renderBufferDirect .............material: ${material.runtimeType} ");
// renderBufferDirect second parameter used to be fog (could be null)
scene ??= _emptyScene;
var frontFaceCW = (object is Mesh && object.matrixWorld.determinant() < 0);
// print("renderBufferDirect object: ${object} name: ${object.name} tag: ${object.tag} frontFaceCW: ${frontFaceCW} ");
// print("${DateTime.now().millisecondsSinceEpoch} - ${DateTime.now().microsecondsSinceEpoch} WebGLRenderer.renderBufferDirect object: ${object.type} ${object.id} material: ${material.type} map: ${material.map} id: ${material.id} geometry: ${geometry.type} ${geometry.id} object.isMesh: ${object.isMesh} frontFaceCW: ${frontFaceCW} ");
WebGLProgram program =
setProgram(camera, scene, geometry, material, object);
state.setMaterial(material, frontFaceCW);
// print("renderBufferDirect - 0: ${DateTime.now().millisecondsSinceEpoch} - ${DateTime.now().microsecondsSinceEpoch} ");
BufferAttribute? index = geometry.index;
BufferAttribute? position = geometry.attributes["position"];
// print(" WebGLRenderer.renderBufferDirect geometry.index ${index?.count} - ${index} position: - ${position} ");
if (index == null) {
if (position == null || position.count == 0) return;
} else if (index.count == 0) {
return;
}
//
var rangeFactor = 1;
if (material.wireframe == true) {
index = geometries.getWireframeAttribute(geometry);
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;
var renderer = bufferRenderer;
if (index != null) {
attribute = attributes.get(index);
renderer = indexedBufferRenderer;
// print(index);
// print("WebGLRenderer.renderBufferDirect index attribute: ${attribute} ");
renderer.setIndex(attribute);
}
int dataCount = (index != null) ? index.count : position!.count;
var rangeStart = geometry.drawRange["start"]! * rangeFactor;
var rangeCount = geometry.drawRange["count"]! * rangeFactor;
var groupStart = group != null ? group["start"] * rangeFactor : 0;
var groupCount =
group != null ? group["count"] * rangeFactor : double.maxFinite;
var drawStart = Math.max<num>(rangeStart, groupStart);
var drawEnd =
Math.min3(dataCount, rangeStart + rangeCount, groupStart + groupCount) -
1;
var drawCount = Math.max(0, drawEnd - drawStart + 1);
if (drawCount == 0) return;
if (object is Mesh) {
if (material.wireframe == true) {
state
.setLineWidth(material.wireframeLinewidth! * getTargetPixelRatio());
renderer.setMode(_gl.LINES);
} else {
renderer.setMode(_gl.TRIANGLES);
}
} else if (object is Line) {
var lineWidth = material.linewidth;
lineWidth ??= 1; // Not using Line*Material
state.setLineWidth(lineWidth * getTargetPixelRatio());
if (object is LineSegments) {
renderer.setMode(_gl.LINES);
} else if (object is LineLoop) {
renderer.setMode(_gl.LINE_LOOP);
} else {
renderer.setMode(_gl.LINE_STRIP);
}
} else if (object is Points) {
renderer.setMode(_gl.POINTS);
} else if (object is Sprite) {
renderer.setMode(_gl.TRIANGLES);
}
if (object is InstancedMesh) {
renderer.renderInstances(drawStart, drawCount, object.count);
} else if (geometry is InstancedBufferGeometry) {
var instanceCount =
Math.min(geometry.instanceCount!, geometry.maxInstanceCount!);
renderer.renderInstances(drawStart, drawCount, instanceCount);
} else {
renderer.render(drawStart, drawCount);
}
// print("renderBufferDirect - 1: ${DateTime.now().millisecondsSinceEpoch} - ${DateTime.now().microsecondsSinceEpoch} ");
}