[Papervision3D] solved plane3D->2D (as2)
hsx
pv3d at frailform.com
Wed Oct 17 01:58:08 PDT 2007
That seems only to work when the plane is completely visible on screen. When
they reside outside the rendered view, the screen.x/screen.y values for the
invisible corners are not correct.
Is there a way to that - like to force all corners (do3d objects) to be
rendered?
gamera wrote:
>
> just did something similar.
> add to your plane 4 empty DO3D and place them in the 4 corner of the
> plane.
> get the screen.x and screen.y of these empty DO3D.
>
> On Oct 16, 2007, at 4:49 PM, hsx wrote:
>
>>
>> This is exactly what I would need in my current project
>> 1: Retrieve the 4 corners of a plane in 3d space
>> 2: Convert the corners to 2d coordinates
>>
>> Step 2 should be no problem with screen.x / screen.y.
>>
>> Unfortunately the code below doesn't seem to work anymore. Does
>> anyone have
>> a solution to get these points?
>>
>>
>>
>>
>>
>> JLM-2 wrote:
>>>
>>>
>>> Recently I have been trying to get the coordinates of a plane in 2D,
>>> finally
>>> I have found a solution. Maybe it would be worth optimising and
>>> adding to
>>> papervision?
>>>
>>>
>>> Concept
>>> =======
>>>
>>> 1) Store the papervision drawing coordinates in 'Face3D'.
>>> 2) in an extends 'Plane' I loop through the faces array and get
>>> the vertex
>>> that only occur once or twice (which implies they are corners).
>>> sort based
>>> on once or twice and then alternate them so that any lineTo's will
>>> be able
>>> to draw between the corners.
>>> 3) I store where I got them from to reduce future calculation
>>> overheads.
>>>
>>>
>>> Code Snipits
>>> =============
>>>
>>>
>>> So my solution is to modify face3D storing some lineTo parameters
>>> in the
>>> render method
>>>
>>> // store render positions!!!
>>> this.x0 = x0;
>>> this.y0 = y0;
>>> this.x1 = x1;
>>> this.y1 = y1;
>>> this.x2 = x2;
>>> this.y2 = y2;
>>>
>>>
>>> then extending plane with a getCorners method (and supporting code)
>>>
>>> class net.justinfront.PlaneJLM extends
>>> org.papervision3d.objects.Plane
>>>
>>>
>>> public function PlaneJLM( material:MaterialObject3D, width:Number,
>>> height:Number, segmentsW:Number, segmentsH:Number,
>>> initObject:Object )
>>> {
>>> super(material, width, height, segmentsW, segmentsH, initObject );
>>> }
>>>
>>> // additional code for getting corner info
>>>
>>> // variable: corners
>>> //
>>> private var corners: Array;
>>>
>>> // variable: vertexNo
>>> //
>>> private var vertexNo: Object;
>>>
>>> // method: findCorners
>>> //
>>> private function findCorners( arr: Array ):Array
>>> {
>>> var i: Number;
>>> var len: Number;
>>> var all: String;
>>> var vertex_obj: Object;
>>> var vertex_arr: Array;
>>> var curr: String;
>>> var no: Number;
>>> var arri: Object;
>>> vertexNo = {};
>>> vertex_obj = {};
>>> vertex_arr = [];
>>> i = -1;
>>> len = arr.length-1;
>>>
>>> // sort for all vertex that appear only once or twice in the
>>> list, as
>>> they are corner vertex.
>>> while( i++ < len )
>>> {
>>>
>>> arri = arr[i];
>>> curr = arri._x + '_' + arri._y;
>>>
>>> // fancy way to avoid if undefined
>>> vertexNo[ curr ] = vertexNo[ curr ]|0;
>>> no = vertexNo[ curr ]++;
>>>
>>>
>>> // internal or side vertex
>>> if( no > 1)
>>> {
>>>
>>> // remove internal vertex
>>> delete vertex_obj[ curr ];
>>>
>>> }
>>> else if(no == 0)
>>> {
>>>
>>> // store vertex
>>> vertex_obj[ curr ] = { _x: arri._x, _y:arri._y, no: no, face:
>>> arri.face, index:arri.index };
>>>
>>> } else {
>>>
>>> //increment vertex no
>>> vertex_obj[ curr ].no = no;
>>>
>>> }
>>>
>>> }
>>>
>>> // push the four corners left in the vertex_obj into an array
>>> for( all in vertex_obj )
>>> {
>>>
>>> vertex_arr.push( vertex_obj[ all ] )
>>>
>>> }
>>>
>>> // sort by vertex number
>>> vertex_arr.sort( sortVertexNo );
>>>
>>> // return alternate opposite sides so that lineto will be either
>>> clockwise or anti clockwise.
>>> return [ vertex_arr[0], vertex_arr[3], vertex_arr[1], vertex_arr
>>> [2] ];
>>>
>>> }
>>>
>>> // method sortVertexNo
>>> // sorts by number vertex repeated (opposite corners will have
>>> the same
>>> vertex repeat number (0 or 1) )
>>> private function sortVertexNo( a , b )
>>> {
>>> var ano = a.no;
>>> var bno = b.no;
>>> var abigger = Boolean( ano > bno );
>>> if( ano == bno )
>>> {
>>>
>>> return 0;
>>>
>>> }
>>> else if( abigger )
>>> {
>>>
>>> return -1;
>>>
>>> }
>>> else
>>> {
>>>
>>> return 1;
>>>
>>> }
>>>
>>> }
>>>
>>>
>>> // method: calculateCornerValues
>>> //
>>> private function calculateCornersValues(): Array
>>> {
>>>
>>> var i: Number;
>>> var c: Object;
>>> var out: Array = [];
>>>
>>> for( i = 0; i < 4; i++ )
>>> {
>>>
>>> c = corners[ i ];
>>> out.push( { _x: c.face['x'+c.index], _y: c.face['y'+c.index] } )
>>>
>>> }
>>>
>>> return out
>>>
>>> }
>>>
>>> // method: getCorners
>>> public function getCorners():Array
>>> {
>>> // if we already know which vertex are corners then get them
>>> if( corners != undefined )
>>> {
>>>
>>> // after first time of running getCorners
>>> // already know the corners just need to return thier current
>>> values
>>>
>>> } else {
>>>
>>> // first time getCorners need to find the applicable corner
>>> vertex's
>>>
>>> var all: String;
>>> var out: Array;
>>> var points: Array;
>>> var face_: Array;
>>>
>>> points = [];
>>>
>>> for( all in faces )
>>> {
>>>
>>> face_ = faces[all]
>>> points.push({_x:face_.x0, _y:face_.y0, face: face_, index: '0'});
>>> points.push({_x:face_.x1, _y:face_.y1, face: face_, index: '1'});
>>> points.push({_x:face_.x2, _y:face_.y2, face: face_, index: '2'});
>>>
>>> }
>>>
>>> corners = findCorners( points );
>>>
>>> }
>>>
>>> return calculateCornersValues();
>>>
>>> }
>>>
>>> }
>>>
>>> Please feel free to help optimise I will try to post an example of
>>> its use
>>> after work.
>>>
>>>
>>> Enjoy
>>>
>>> ;J
>>>
>>>
>>>
>>> _______________________________________________
>>> Papervision3D mailing list
>>> Papervision3D at osflash.org
>>> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>>>
>>>
>>
>> --
>> View this message in context: http://www.nabble.com/solved-plane3D-%
>> 3E2D-%28as2%29-tf4111615.html#a13232831
>> Sent from the Papervision3D mailing list archive at Nabble.com.
>>
>>
>> _______________________________________________
>> Papervision3D mailing list
>> Papervision3D at osflash.org
>> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>>
>
>
> _______________________________________________
> Papervision3D mailing list
> Papervision3D at osflash.org
> http://osflash.org/mailman/listinfo/papervision3d_osflash.org
>
>
--
View this message in context: http://www.nabble.com/solved-plane3D-%3E2D-%28as2%29-tf4111615.html#a13249553
Sent from the Papervision3D mailing list archive at Nabble.com.
More information about the Papervision3D
mailing list