render method
Implementation
void render(Scene scene, Camera camera){
Projector projector = Projector();
RenderData renderData = RenderData();
dynamic background = scene.background;
if(background != null && background.isColor){
removeChildNodes();
svg.style['background-color'] = background.getStyle();
}
else if(autoClear) {
clear();
}
info.vertices = 0;
info.faces = 0;
_viewMatrix.copy( camera.matrixWorldInverse );
_viewProjectionMatrix.multiplyMatrices( camera.projectionMatrix, _viewMatrix );
renderData = projector.projectScene( scene, camera, sortObjects, sortElements );
_elements = renderData.elements;
lights = renderData.lights;
_normalViewMatrix.getNormalMatrix( camera.matrixWorldInverse );
calculateLights(lights!); // reset accumulated path
_currentPath = '';
_currentStyle = '';
for (int e = 0; e < _elements.length; e ++ ) {
Object3D element = _elements[e];
Material? material = element.material;
if(material == null || material.opacity == 0) continue;
_elemBox.makeEmpty();
if(element is RenderableSprite){
RenderableSprite _v1 = element;
_v1.x *= widthHalf;
_v1.y *= - heightHalf;
renderSprite( _v1, element, material );
}
else if(element is RenderableLine){
RenderableVertex _v1 = element.v1;
RenderableVertex _v2 = element.v2;
_v1.positionScreen.x *= widthHalf;
_v1.positionScreen.y *= -heightHalf;
_v2.positionScreen.x *= widthHalf;
_v2.positionScreen.y *= -heightHalf;
_elemBox.setFromPoints([_v1.positionScreen.toVector2(), _v2.positionScreen.toVector2()]);
if (_clipBox.intersectsBox(_elemBox)) {
renderLine( _v1, _v2, material );
}
}
else if(element is RenderableFace){
RenderableVertex _v1 = element.v1;
RenderableVertex _v2 = element.v2;
RenderableVertex _v3 = element.v3;
if ( _v1.positionScreen.z < - 1 || _v1.positionScreen.z > 1 ) continue;
if ( _v2.positionScreen.z < - 1 || _v2.positionScreen.z > 1 ) continue;
if ( _v3.positionScreen.z < - 1 || _v3.positionScreen.z > 1 ) continue;
_v1.positionScreen.x *= widthHalf;
_v1.positionScreen.y *= - heightHalf;
_v2.positionScreen.x *= widthHalf;
_v2.positionScreen.y *= - heightHalf;
_v3.positionScreen.x *= widthHalf;
_v3.positionScreen.y *= - heightHalf;
if (overdraw > 0 && !edgeOnly) {
expand( _v1.positionScreen, _v2.positionScreen, overdraw );
expand( _v2.positionScreen, _v3.positionScreen, overdraw );
expand( _v3.positionScreen, _v1.positionScreen, overdraw );
}
_elemBox.setFromPoints([ _v1.positionScreen.toVector2(), _v2.positionScreen.toVector2(), _v3.positionScreen.toVector2()]);
if(_clipBox.intersectsBox(_elemBox)){
renderFace3( _v1, _v2, _v3, element, material );
}
}
}
flushPath(); // just to flush last svg:path
scene.traverseVisible((object){
if(object is SVGObject){
_vector3.setFromMatrixPosition( object.matrixWorld );
_vector3.applyMatrix4( _viewProjectionMatrix );
if ( _vector3.z < - 1 || _vector3.z > 1 ) return;
double x = _vector3.x * widthHalf;
double y = - _vector3.y * heightHalf;
SVGDocument node = object.node;
node.setAttribute('transform', 'translate($x,$y)');
svg.appendChild( node );
}
});
}