提交 3293991e 编写于 作者: M Mr.doob

Projector: Culling vertices on the x and y axis too.

However, this can create glitches on extreme cases when the polygon is inside the frustum but the vertices are not.
Maybe this can be achieved with Box3 in a performant way?
/ping @bhouston
上级 ea9ec29f
......@@ -60,6 +60,11 @@ THREE.SVGRenderer = function () {
};
// WebGLRenderer compatibility
this.supportsVertexTextures = function () {};
this.setFaceCulling = function () {};
this.setSize = function( width, height ) {
_svgWidth = width; _svgHeight = height;
......@@ -150,6 +155,10 @@ THREE.SVGRenderer = function () {
_v1 = element.v1; _v2 = element.v2; _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 *= _svgWidthHalf; _v1.positionScreen.y *= - _svgHeightHalf;
_v2.positionScreen.x *= _svgWidthHalf; _v2.positionScreen.y *= - _svgHeightHalf;
_v3.positionScreen.x *= _svgWidthHalf; _v3.positionScreen.y *= - _svgHeightHalf;
......@@ -166,6 +175,11 @@ THREE.SVGRenderer = function () {
_v1 = element.v1; _v2 = element.v2; _v3 = element.v3; _v4 = element.v4;
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;
if ( _v4.positionScreen.z < -1 || _v4.positionScreen.z > 1 ) continue;
_v1.positionScreen.x *= _svgWidthHalf; _v1.positionScreen.y *= -_svgHeightHalf;
_v2.positionScreen.x *= _svgWidthHalf; _v2.positionScreen.y *= -_svgHeightHalf;
_v3.positionScreen.x *= _svgWidthHalf; _v3.positionScreen.y *= -_svgHeightHalf;
......
......@@ -236,7 +236,9 @@ THREE.Projector = function() {
_vertex.positionScreen.y /= _vertex.positionScreen.w;
_vertex.positionScreen.z /= _vertex.positionScreen.w;
_vertex.visible = _vertex.positionScreen.z > -1 && _vertex.positionScreen.z < 1;
_vertex.visible = ! ( _vertex.positionScreen.x < -1 || _vertex.positionScreen.x > 1 ||
_vertex.positionScreen.y < -1 || _vertex.positionScreen.y > 1 ||
_vertex.positionScreen.z < -1 || _vertex.positionScreen.z > 1 );
}
......@@ -258,7 +260,7 @@ THREE.Projector = function() {
v2 = _vertexPool[ face.b ];
v3 = _vertexPool[ face.c ];
if ( v1.visible === true && v2.visible === true && v3.visible === true ) {
if ( v1.visible === true || v2.visible === true || v3.visible === true ) {
visible = ( ( v3.positionScreen.x - v1.positionScreen.x ) * ( v2.positionScreen.y - v1.positionScreen.y ) -
( v3.positionScreen.y - v1.positionScreen.y ) * ( v2.positionScreen.x - v1.positionScreen.x ) ) < 0;
......@@ -290,7 +292,7 @@ THREE.Projector = function() {
v3 = _vertexPool[ face.c ];
v4 = _vertexPool[ face.d ];
if ( v1.visible === true && v2.visible === true && v3.visible === true && v4.visible === true ) {
if ( v1.visible === true || v2.visible === true || v3.visible === true || v4.visible === true ) {
visible = ( v4.positionScreen.x - v1.positionScreen.x ) * ( v2.positionScreen.y - v1.positionScreen.y ) -
( v4.positionScreen.y - v1.positionScreen.y ) * ( v2.positionScreen.x - v1.positionScreen.x ) < 0 ||
......
......@@ -112,6 +112,11 @@ THREE.CanvasRenderer = function ( parameters ) {
}
// WebGLRenderer compatibility
this.supportsVertexTextures = function () {};
this.setFaceCulling = function () {};
this.setSize = function ( width, height ) {
_canvasWidth = width * this.devicePixelRatio;
......@@ -274,6 +279,10 @@ THREE.CanvasRenderer = function ( parameters ) {
_v1 = element.v1; _v2 = element.v2; _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 *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf;
_v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf;
_v3.positionScreen.x *= _canvasWidthHalf; _v3.positionScreen.y *= _canvasHeightHalf;
......@@ -298,6 +307,11 @@ THREE.CanvasRenderer = function ( parameters ) {
_v1 = element.v1; _v2 = element.v2; _v3 = element.v3; _v4 = element.v4;
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;
if ( _v4.positionScreen.z < -1 || _v4.positionScreen.z > 1 ) continue;
_v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf;
_v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf;
_v3.positionScreen.x *= _canvasWidthHalf; _v3.positionScreen.y *= _canvasHeightHalf;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册