3131 * using PrimMesher (http://forge.opensimulator.org/projects/primmesher).
3232 */
3333
34+ using PrimMesher ;
3435using System ;
3536using System . Collections . Generic ;
3637using OMV = OpenMetaverse ;
@@ -107,6 +108,95 @@ public OMVR.SimpleMesh GenerateSimpleSculptMesh(OMV.Primitive prim, System.Drawi
107108 return null ;
108109 }
109110
111+ public static FacetedMesh m_BasicBoxMesh = null ;
112+ private static readonly object m_BasicBoxMeshLock = new ( ) ;
113+ public static List < ushort > m_indexs_012213 = [ 0 , 1 , 2 , 2 , 1 , 3 ] ;
114+ public static FacetedMesh GetBasicBoxMesh ( )
115+ {
116+ if ( m_BasicBoxMesh == null )
117+ {
118+ lock ( m_BasicBoxMeshLock )
119+ {
120+ m_BasicBoxMesh ??= new ( )
121+ {
122+ Faces =
123+ [
124+ new Face ( )
125+ {
126+ Vertices =
127+ [
128+ new ( ) { Position = new ( - 0.5f , - 0.5f , 0.5f ) , Normal = Vector3 . UnitZ , TexCoord = new ( 0f , 0f ) } ,
129+ new ( ) { Position = new ( 0.5f , - 0.5f , 0.5f ) , Normal = Vector3 . UnitZ , TexCoord = new ( 1f , 0f ) } ,
130+ new ( ) { Position = new ( 0.5f , 0.5f , 0.5f ) , Normal = Vector3 . UnitZ , TexCoord = new ( 1f , 1f ) } ,
131+ new ( ) { Position = new ( - 0.5f , 0.5f , 0.5f ) , Normal = Vector3 . UnitZ , TexCoord = new ( 0f , 1f ) } ,
132+ ] ,
133+ Indices = [ 0 , 1 , 2 , 0 , 2 , 3 ] ,
134+ } ,
135+ new Face ( )
136+ {
137+ Vertices =
138+ [
139+ new ( ) { Position = new ( - 0.5f , - 0.5f , 0.5f ) , Normal = - Vector3 . UnitY , TexCoord = new ( 0f , 1f ) } ,
140+ new ( ) { Position = new ( - 0.5f , - 0.5f , - 0.5f ) , Normal = - Vector3 . UnitY , TexCoord = new ( 0f , 0f ) } ,
141+ new ( ) { Position = new ( 0.5f , - 0.5f , 0.5f ) , Normal = - Vector3 . UnitY , TexCoord = new ( 1f , 1f ) } ,
142+ new ( ) { Position = new ( 0.5f , - 0.5f , - 0.5f ) , Normal = - Vector3 . UnitY , TexCoord = new ( 1f , 0f ) } ,
143+ ] ,
144+ Indices = m_indexs_012213 ,
145+ } ,
146+ new Face ( )
147+ {
148+ Vertices =
149+ [
150+ new ( ) { Position = new ( 0.5f , - 0.5f , 0.5f ) , Normal = Vector3 . UnitX , TexCoord = new ( 0f , 1f ) } ,
151+ new ( ) { Position = new ( 0.5f , - 0.5f , - 0.5f ) , Normal = Vector3 . UnitX , TexCoord = new ( 0f , 0f ) } ,
152+ new ( ) { Position = new ( 0.5f , 0.5f , 0.5f ) , Normal = Vector3 . UnitX , TexCoord = new ( 1f , 1f ) } ,
153+ new ( ) { Position = new ( 0.5f , 0.5f , - 0.5f ) , Normal = Vector3 . UnitX , TexCoord = new ( 1f , 0f ) } ,
154+ ] ,
155+ Indices = m_indexs_012213 ,
156+ } ,
157+ new Face ( )
158+ {
159+ Vertices =
160+ [
161+ new ( ) { Position = new ( 0.5f , 0.5f , 0.5f ) , Normal = Vector3 . UnitY , TexCoord = new ( 0f , 1f ) } ,
162+ new ( ) { Position = new ( 0.5f , 0.5f , - 0.5f ) , Normal = Vector3 . UnitY , TexCoord = new ( 0f , 0f ) } ,
163+ new ( ) { Position = new ( - 0.5f , 0.5f , 0.5f ) , Normal = Vector3 . UnitY , TexCoord = new ( 1f , 1f ) } ,
164+ new ( ) { Position = new ( - 0.5f , 0.5f , - 0.5f ) , Normal = Vector3 . UnitY , TexCoord = new ( 1f , 0f ) } ,
165+ ] ,
166+ Indices = m_indexs_012213 ,
167+ } ,
168+ new Face ( )
169+ {
170+ Vertices =
171+ [
172+ new ( ) { Position = new ( - 0.5f , 0.5f , 0.5f ) , Normal = - Vector3 . UnitX , TexCoord = new ( 0f , 1f ) } ,
173+ new ( ) { Position = new ( - 0.5f , 0.5f , - 0.5f ) , Normal = - Vector3 . UnitX , TexCoord = new ( 0f , 0f ) } ,
174+ new ( ) { Position = new ( - 0.5f , - 0.5f , 0.5f ) , Normal = - Vector3 . UnitX , TexCoord = new ( 1f , 1f ) } ,
175+ new ( ) { Position = new ( - 0.5f , - 0.5f , - 0.5f ) , Normal = - Vector3 . UnitX , TexCoord = new ( 1f , 0f ) } ,
176+ ] ,
177+ Indices = m_indexs_012213 ,
178+ } ,
179+ new Face ( )
180+ {
181+ Vertices =
182+ [
183+ new ( ) { Position = new ( 0.5f , 0.5f , - 0.5f ) , Normal = - Vector3 . UnitZ , TexCoord = new ( 1f , 0f ) } ,
184+ new ( ) { Position = new ( 0.5f , - 0.5f , - 0.5f ) , Normal = - Vector3 . UnitZ , TexCoord = new ( 1f , 1f ) } ,
185+ new ( ) { Position = new ( - 0.5f , - 0.5f , - 0.5f ) , Normal = - Vector3 . UnitZ , TexCoord = new ( 0f , 1f ) } ,
186+ new ( ) { Position = new ( - 0.5f , 0.5f , - 0.5f ) , Normal = - Vector3 . UnitZ , TexCoord = new ( 0f , 0f ) } ,
187+ ] ,
188+ Indices = [ 0 , 1 , 2 , 3 , 0 , 2 ] ,
189+ } ,
190+ ]
191+ } ;
192+ }
193+ }
194+
195+ return m_BasicBoxMesh ;
196+ }
197+
198+
199+
110200 /// <summary>
111201 /// Generates a a series of faces, each face containing a mesh and
112202 /// metadata
@@ -116,6 +206,22 @@ public OMVR.SimpleMesh GenerateSimpleSculptMesh(OMV.Primitive prim, System.Drawi
116206 /// <returns>The generated mesh</returns >
117207 public OMVR . FacetedMesh GenerateFacetedMesh ( OMV . Primitive prim , OMVR . DetailLevel lod )
118208 {
209+ OMV . ProfileCurve profileCurve = ( OMV . ProfileCurve ) ( prim . PrimData . profileCurve & 0x07 ) ;
210+
211+ if ( profileCurve == OMV . ProfileCurve . Square && prim . PrimData . PathCurve == OMV . PathCurve . Line )
212+ {
213+ if ( prim . PrimData . ProfileHole == 0 &&
214+ prim . PrimData . ProfileBegin == 0f && prim . PrimData . ProfileEnd == 1f &&
215+ prim . PrimData . PathBegin == 0f && prim . PrimData . PathEnd == 1f &&
216+ prim . PrimData . PathScaleX == 1f && prim . PrimData . PathScaleY == 1f &&
217+ prim . PrimData . PathShearX == 0 && prim . PrimData . PathShearY == 0 &&
218+ prim . PrimData . PathRevolutions == 1f
219+ )
220+ {
221+ return GetBasicBoxMesh ( ) ;
222+ }
223+ }
224+
119225 PrimMesher . PrimMesh newPrim = GeneratePrimMesh ( prim , lod , true ) ;
120226 if ( newPrim == null )
121227 return null ;
@@ -322,16 +428,16 @@ public void TransformTexCoords(List<OMVR.Vertex> vertices, OMV.Vector3 center, O
322428
323429 private PrimMesher . PrimMesh GeneratePrimMesh ( Primitive prim , DetailLevel lod , bool viewerMode )
324430 {
325- OMV . Primitive . ConstructionData primData = prim . PrimData ;
326431 int sides = 4 ;
327432 int hollowsides = 4 ;
328433
329- float profileBegin = primData . ProfileBegin ;
330- float profileEnd = primData . ProfileEnd ;
434+ float profileBegin = prim . PrimData . ProfileBegin ;
435+ float profileEnd = prim . PrimData . ProfileEnd ;
331436
332437 bool isSphere = false ;
333438
334- if ( ( OMV . ProfileCurve ) ( primData . profileCurve & 0x07 ) == OMV . ProfileCurve . Circle )
439+ OMV . ProfileCurve profileCurve = ( OMV . ProfileCurve ) ( prim . PrimData . profileCurve & 0x07 ) ;
440+ if ( profileCurve == OMV . ProfileCurve . Circle )
335441 {
336442 switch ( lod )
337443 {
@@ -346,9 +452,9 @@ private PrimMesher.PrimMesh GeneratePrimMesh(Primitive prim, DetailLevel lod, bo
346452 break ;
347453 }
348454 }
349- else if ( ( OMV . ProfileCurve ) ( primData . profileCurve & 0x07 ) == OMV . ProfileCurve . EqualTriangle )
455+ else if ( profileCurve == OMV . ProfileCurve . EqualTriangle )
350456 sides = 3 ;
351- else if ( ( OMV . ProfileCurve ) ( primData . profileCurve & 0x07 ) == OMV . ProfileCurve . HalfCircle )
457+ else if ( profileCurve == OMV . ProfileCurve . HalfCircle )
352458 {
353459 // half circle, prim is a sphere
354460 isSphere = true ;
@@ -368,9 +474,9 @@ private PrimMesher.PrimMesh GeneratePrimMesh(Primitive prim, DetailLevel lod, bo
368474 profileEnd = 0.5f * profileEnd + 0.5f ;
369475 }
370476
371- if ( ( OMV . HoleType ) primData . ProfileHole == OMV . HoleType . Same )
477+ if ( ( OMV . HoleType ) prim . PrimData . ProfileHole == OMV . HoleType . Same )
372478 hollowsides = sides ;
373- else if ( ( OMV . HoleType ) primData . ProfileHole == OMV . HoleType . Circle )
479+ else if ( prim . PrimData . ProfileHole == OMV . HoleType . Circle )
374480 {
375481 switch ( lod )
376482 {
@@ -385,21 +491,21 @@ private PrimMesher.PrimMesh GeneratePrimMesh(Primitive prim, DetailLevel lod, bo
385491 break ;
386492 }
387493 }
388- else if ( ( OMV . HoleType ) primData . ProfileHole == OMV . HoleType . Triangle )
494+ else if ( prim . PrimData . ProfileHole == OMV . HoleType . Triangle )
389495 hollowsides = 3 ;
390496
391- PrimMesher . PrimMesh newPrim = new PrimMesher . PrimMesh ( sides , profileBegin , profileEnd , ( float ) primData . ProfileHollow , hollowsides ) ;
497+ PrimMesher . PrimMesh newPrim = new ( sides , profileBegin , profileEnd , prim . PrimData . ProfileHollow , hollowsides ) ;
392498 newPrim . viewerMode = viewerMode ;
393499 newPrim . sphereMode = isSphere ;
394- newPrim . holeSizeX = primData . PathScaleX ;
395- newPrim . holeSizeY = primData . PathScaleY ;
396- newPrim . pathCutBegin = primData . PathBegin ;
397- newPrim . pathCutEnd = primData . PathEnd ;
398- newPrim . topShearX = primData . PathShearX ;
399- newPrim . topShearY = primData . PathShearY ;
400- newPrim . radius = primData . PathRadiusOffset ;
401- newPrim . revolutions = primData . PathRevolutions ;
402- newPrim . skew = primData . PathSkew ;
500+ newPrim . holeSizeX = prim . PrimData . PathScaleX ;
501+ newPrim . holeSizeY = prim . PrimData . PathScaleY ;
502+ newPrim . pathCutBegin = prim . PrimData . PathBegin ;
503+ newPrim . pathCutEnd = prim . PrimData . PathEnd ;
504+ newPrim . topShearX = prim . PrimData . PathShearX ;
505+ newPrim . topShearY = prim . PrimData . PathShearY ;
506+ newPrim . radius = prim . PrimData . PathRadiusOffset ;
507+ newPrim . revolutions = prim . PrimData . PathRevolutions ;
508+ newPrim . skew = prim . PrimData . PathSkew ;
403509 switch ( lod )
404510 {
405511 case OMVR . DetailLevel . Low :
@@ -413,20 +519,20 @@ private PrimMesher.PrimMesh GeneratePrimMesh(Primitive prim, DetailLevel lod, bo
413519 break ;
414520 }
415521
416- if ( ( primData . PathCurve == OMV . PathCurve . Line ) || ( primData . PathCurve == OMV . PathCurve . Flexible ) )
522+ if ( ( prim . PrimData . PathCurve == OMV . PathCurve . Line ) || ( prim . PrimData . PathCurve == OMV . PathCurve . Flexible ) )
417523 {
418- newPrim . taperX = 1.0f - primData . PathScaleX ;
419- newPrim . taperY = 1.0f - primData . PathScaleY ;
420- newPrim . twistBegin = ( int ) ( 180 * primData . PathTwistBegin ) ;
421- newPrim . twistEnd = ( int ) ( 180 * primData . PathTwist ) ;
524+ newPrim . taperX = 1.0f - prim . PrimData . PathScaleX ;
525+ newPrim . taperY = 1.0f - prim . PrimData . PathScaleY ;
526+ newPrim . twistBegin = ( int ) ( 180 * prim . PrimData . PathTwistBegin ) ;
527+ newPrim . twistEnd = ( int ) ( 180 * prim . PrimData . PathTwist ) ;
422528 newPrim . ExtrudeLinear ( ) ;
423529 }
424530 else
425531 {
426- newPrim . taperX = primData . PathTaperX ;
427- newPrim . taperY = primData . PathTaperY ;
428- newPrim . twistBegin = ( int ) ( 360 * primData . PathTwistBegin ) ;
429- newPrim . twistEnd = ( int ) ( 360 * primData . PathTwist ) ;
532+ newPrim . taperX = prim . PrimData . PathTaperX ;
533+ newPrim . taperY = prim . PrimData . PathTaperY ;
534+ newPrim . twistBegin = ( int ) ( 360 * prim . PrimData . PathTwistBegin ) ;
535+ newPrim . twistEnd = ( int ) ( 360 * prim . PrimData . PathTwist ) ;
430536 newPrim . ExtrudeCircular ( ) ;
431537 }
432538
0 commit comments