mrdoob/three.js — Issue #633: Size of object on screen
Author: florianf
Created: 2011-10-08 14:39:49+00:00
State: open

So I'm still fiddling with my quadtile Google Earth - like terrain generator. Currently i try to calculate which tiles should be high-res and which low-res.

I managed to extract the frustum culling from the projector class, so only the visible tiles are loaded. Now I tried to get the texture resolution depending on the distance from the camera and the center of the plane. That doesn't work the way I like, because it doesn't take the look target and look angle into account.

Now my idea was, that the screen size of each tile (PlaneGeometry) is computed, and the larger the tile is on screen the more detailed is the texture. I think something similar is done here: http://spidergl.org/example.php?id=7.

I cannot figure it out completly when looking at the Projector code, in fact I would need to transform the edge vertices into screen coordinates and then compute the area of the resulting quadrangle.

What I was thinking about (based on THREE.Projector):

var projScreenMatrix = new THREE.Matrix4();
projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );

//This is done for every edge vertex
var renderVert = new THREE.RenderableVertex();
renderVert.positionWorld.copy( edgeVertex1.position );

//Mesh is the plane mesh which the vertex was taken from
mesh.matrixWorld.multiplyVector3( vertex.positionWorld );

renderVert.positionScreen.copy( renderVert.positionWorld );

//Take depth into account, divided for perspective projection
projScreenMatrix.multiplyVector4( renderVert.positionScreen );
renderVert.positionScreen.x /= renderVert.positionScreen.w;
renderVert.positionScreen.y /= renderVert.positionScreen.w;

//finally compute area, Formula: A=(1/2)|[(x3-x1)(y4-y2) +(x4-x2)(y1-y3)]|
computeSize(renderVert1, renderVert2, renderVert3, renderVert4);

Is this the right way, thoughts?