public GeometryHitCollection Trace( GeometryBase Geometry, Ray WorldRay ) { if ( Geometry == null ) { throw new ArgumentNullException( "Geometry" ); } SimpleGeometryHit GeomHit = Geometry.Trace( WorldRay, ShapeHits, GeometryHits ); return new GeometryHitCollection( ShapeHits, GeomHit ); }
public SimpleObject( GeometryBase Geometry, IReadOnlyList<NormalBase> Normals, IReadOnlyList<EmissiveMaterialBase> Emissive, IReadOnlyList<DirectlyLitMaterialBase> Direct, IReadOnlyList<IndirectlyLitMaterialBase> Indirect, IReadOnlyList<TranslucentMaterialBase> Translucent ) { if ( Geometry == null ) { throw new ArgumentNullException( "Geometry" ); } int ShadableFaces = 0; if ( Emissive != null ) { ShadableFaces = Emissive.Count; } if ( Direct != null ) { ShadableFaces = Math.Max( ShadableFaces, Direct.Count ); } if ( Indirect != null ) { ShadableFaces = Math.Max( ShadableFaces, Indirect.Count ); } if ( ShadableFaces == 0 ) { throw new ArgumentNullException( "No Materials Provided" ); } PremultipliedGeometry PremulGeom = Geometry as PremultipliedGeometry; ModelGeometry ModelGeom = Geometry as ModelGeometry; bool TranslucentMaterialExists = false; bool IndirectMaterialExists = false; bool EmissiveMaterialExists = false; bool DirectMaterialExists = false; bool NormalExists = false; // Type RequiredShape = null; for ( int i = 0; i < ShadableFaces; i++ ) { TranslucentMaterialBase Tm = ( Translucent != null && i < Translucent.Count ) ? Translucent[i] : null; IndirectlyLitMaterialBase Im = ( Indirect != null && i < Indirect.Count ) ? Indirect[i] : null; EmissiveMaterialBase Em = ( Emissive != null && i < Emissive.Count ) ? Emissive[i] : null; DirectlyLitMaterialBase Dm = ( Direct != null && i < Direct.Count ) ? Direct[i] : null; NormalBase Normal = ( Normals != null && i < Normals.Count ) ? Normals[i] : null; /* if ( RequiredShape == null ) { if ( Tm != null && Tm.RequiresShape != null ) { RequiredShape = Tm.RequiresShape; } else if ( Im != null && Im.RequiresShape != null ) { RequiredShape = Im.RequiresShape; } else if ( Em != null && Em.RequiresShape != null ) { RequiredShape = Em.RequiresShape; } else if ( Dm != null && Dm.RequiresShape != null ) { RequiredShape = Dm.RequiresShape; } else if ( Normal != null && Normal.RequiresShape != null ) { RequiredShape = Normal.RequiresShape; } } if ( RequiredShape != null ) { if ( ( PremulGeom != null && RequiredShape != typeof( PremulGeom.Shape ) ) || ( ModelGeom != null && RequiredShape != typeof( ModelGeom.Shape ) )) { } else if ( ( Tm != null && Tm.RequiresShape != null && Tm.RequiresShape != RequiredShape ) || ( Em != null && Em.RequiresShape != null && Em.RequiresShape != RequiredShape ) || ( Dm != null && Dm.RequiresShape != null && Dm.RequiresShape != RequiredShape ) || ( Im != null && Im.RequiresShape != null && Im.RequiresShape != RequiredShape ) || ( Normal != null && Normal.RequiresShape != null && Normal.RequiresShape != RequiredShape ) ) { throw new ArgumentException( "A material or normal requires a shape that does not match the shape provided" ); } } */ this.Geometry = Geometry; if ( !TranslucentMaterialExists && Tm != null ) { TranslucentMaterialExists = true; } if ( !IndirectMaterialExists && Im != null ) { IndirectMaterialExists = true; } if ( !EmissiveMaterialExists && Em != null ) { EmissiveMaterialExists = true; } if ( !DirectMaterialExists && Dm != null ) { DirectMaterialExists = true; } if ( !NormalExists && Normal != null ) { NormalExists = true; } if ( Normal == null && ( Im != null || Dm != null ) ) { throw new ArgumentException( "A material at index " + i + " does not have a corresponding normal" ); } } if ( TranslucentMaterialExists ) { this.Translucent = new List<TranslucentMaterialBase>( Translucent ); } if ( IndirectMaterialExists ) { this.Indirect = new List<IndirectlyLitMaterialBase>( Indirect ); } if ( EmissiveMaterialExists ) { this.Emissive = new List<EmissiveMaterialBase>( Emissive ); } if ( DirectMaterialExists ) { this.Direct = new List<DirectlyLitMaterialBase>( Direct ); } if ( NormalExists ) { this.Normals = new List<NormalBase>( Normals ); } }