My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org • blog.papervision3d.org • osflash.org/papervision3d
*/

/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

// ______________________________________________________________________
// Face3D

package org.papervision3d.core.geom.renderables {
import org.papervision3d.core.math.Number3D;
import org.papervision3d.core.math.NumberUV;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.render.command.IRenderListItem;
import org.papervision3d.core.render.command.RenderTriangle;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.special.CompositeMaterial;
import org.papervision3d.objects.DisplayObject3D;

/**
* The Face3D class lets you render linear textured triangles. It also supports solid colour fill and hairline outlines.
*
*/
public class Triangle3D extends AbstractRenderable implements IRenderable
{
/**
* An array of Vertex3D objects for the three vertices of the triangle.
*/
public var vertices :Array;

/**
* A material id TODO
*/
public var _materialName :String;

/**
* A MaterialObject3D object that contains the material properties of the back of a single sided triangle.
*/
// public var materialBack :MaterialObject3D;

public var uv0:NumberUV;
public var uv1:NumberUV;
public var uv2:NumberUV;

public var _uvArray:Array;
// ______________________________________________________________________

/**
* [read-only] The average depth (z coordinate) of the transformed triangle. Also known as the distance from the camera. Used internally for z-sorting.
*/
public var screenZ :Number;

/**
* [read-only] A Boolean value that indicates that the face is visible, i.e. it's vertices are in front of the camera.
*/
public var visible :Boolean;

/**
* [read-only] Unique id of this instance.
*/
public var id :Number;

/**
* Used to store references to the vertices.
*/
public var v0:Vertex3D;
public var v1:Vertex3D;
public var v2:Vertex3D;

/**
* The face normal
*/
public var faceNormal:Number3D;

/**
* The transformed Face3DInstance
*/
//public var face3DInstance:Triangle3DInstance;

/**
* The do3d instance this triangle belongs too.
*/
//public var instance:DisplayObject3D;

/**
* stores the material for this face.
*/
public var material:MaterialObject3D;

//To be docced
public var renderCommand:RenderTriangle;

private static var _totalFaces:Number = 0;

/**
* The Face3D constructor lets you create linear textured or solid colour triangles.
*
* @param vertices An array of Vertex3D objects for the three vertices of the triangle.
* @param material A MaterialObject3D object that contains the material properties of the triangle.
* @param uv An array of {x,y} objects for the corresponding UV pixel coordinates of each triangle vertex.
*/
public function Triangle3D(do3dInstance:DisplayObject3D, vertices:Array, material:MaterialObject3D=null, uv:Array=null )
{
this.instance = do3dInstance;


//Setup this instance
//face3DInstance = new Triangle3DInstance(this, do3dInstance);

faceNormal = new Number3D();
// Vertices
if(vertices && vertices.length == 3){
this.vertices = vertices;
v0 = vertices[0];
v1 = vertices[1];
v2 = vertices[2];
createNormal();
}else{
vertices = new Array();
v0 = vertices[0] = new Vertex3D();
v1 = vertices[1] = new Vertex3D();
v2 = vertices[2] = new Vertex3D();
}

// Material, if passed from a materials list.
this.material = material;
this.uv = uv;
this.id = _totalFaces++;

this.renderCommand = new RenderTriangle(this);
}

public function reset(object:DisplayObject3D, vertices:Array, material:MaterialObject3D, uv:Array):void{

this.instance = object;
this.renderCommand.instance = object;
this.renderCommand.renderer = material;

this.vertices = vertices;
updateVertices();
//createNormal();

this.material = material;
this.uv = uv;

if(material is BitmapMaterial){

BitmapMaterial(material).uvMatrices[this.renderCommand] = null;

}

if(material is CompositeMaterial){
for each(var mat:MaterialObject3D in CompositeMaterial(material).materials){

if(mat is BitmapMaterial){

BitmapMaterial(mat).uvMatrices[this.renderCommand] = null;

}
}
}


}

public function createNormal():void
{
var vn0:Number3D = v0.getPosition();
var vn1:Number3D = v1.getPosition();
var vn2:Number3D = v2.getPosition();
vn1.minusEq(vn0);
vn2.minusEq(vn0);
faceNormal = Number3D.cross(vn1,vn2,faceNormal);
faceNormal.normalize();
}

override public function getRenderListItem():IRenderListItem
{
return renderCommand;
}

public function updateVertices():void
{
v0 = vertices[0];
v1 = vertices[1];
v2 = vertices[2];
}

/**
* An array of {x,y} objects for the corresponding UV pixel coordinates of each triangle vertex.
*/
public function set uv(uvs:Array):void
{
if(uvs && uvs.length == 3){

uv0 = NumberUV(uvs[0]);
uv1 = NumberUV(uvs[1]);
uv2 = NumberUV(uvs[2]);
}
_uvArray = uvs;
}

public function get uv():Array
{
return _uvArray;
}


}
}

Change log

r754 by azupko on Oct 13, 2008   Diff
QuadTree Support
Render Pipeline changes
Go to: 
Project members, sign in to write a code review

Older revisions

r741 by azupko on Sep 26, 2008   Diff
Speed Updates, Clipping
r708 by neoriley on Aug 25, 2008   Diff
Updating Trunk to 2.0 Beta
All revisions of this file

File info

Size: 7241 bytes, 239 lines
Powered by Google Project Hosting