public SceneBrep Clone()
        {
            SceneBrep tmp = new SceneBrep();

            tmp.geometry = new List <Vector3>(geometry);
            if (normals != null)
            {
                tmp.normals = new List <Vector3>(normals);
            }
            if (colors != null)
            {
                tmp.colors = new List <Vector3>(colors);
            }
            if (txtCoords != null)
            {
                tmp.txtCoords = new List <Vector2>(txtCoords);
            }
            if (vertexPtr != null)
            {
                tmp.vertexPtr = new List <int>(vertexPtr);
            }
            if (oppositePtr != null)
            {
                tmp.oppositePtr = new List <int>(oppositePtr);
            }
            tmp.BuildCornerTable();
            return(tmp);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generic OBJ-loading scene definition routine.
        /// </summary>
        /// <param name="dir">Viewing direction of a camera.</param>
        /// <param name="FoVy">Field of View in degrees.</param>
        /// <param name="correction">Value less than 1.0 brings camera nearer.</param>
        /// <param name="name">OBJ file-name.</param>
        /// <param name="names">Substitute file-name[s].</param>
        /// <returns>Number of triangles.</returns>
        protected static long SceneObj( IRayScene sc, Vector3d dir, double FoVy, double correction, string name, string[] names, double[] surfaceColor )
        {
            Debug.Assert( sc != null );

              Vector3 center = Vector3.Zero;   // center of the mesh
              dir.Normalize();                 // normalized viewing vector of the camera
              float diameter = 2.0f;           // default scene diameter
              int faces = 0;

              // CSG scene:
              CSGInnerNode root = new CSGInnerNode( SetOperation.Union );

              // OBJ file to read:
              if ( names.Length == 0 ||
               names[ 0 ].Length == 0 )
            names = new string[] { name };

              string[] paths = Scenes.SmartFindFiles( names );
              if ( paths[ 0 ] == null || paths[ 0 ].Length == 0 )
              {
            for ( int i = 0; i < names.Length; i++ )
              if ( names[ i ].Length > 0 )
            names[ i ] += ".gz";
            paths = Scenes.SmartFindFiles( names );
              }
              if ( paths[ 0 ] == null || paths[ 0 ].Length == 0 )
            root.InsertChild( new Sphere(), Matrix4d.Identity );
              else
              {
            // B-rep scene construction:
            WavefrontObj objReader = new WavefrontObj();
            objReader.MirrorConversion = false;
            SceneBrep brep = new SceneBrep();
            faces = objReader.ReadBrep( paths[ 0 ], brep );
            brep.BuildCornerTable();
            diameter = brep.GetDiameter( out center );
            TriangleMesh m = new TriangleMesh( brep );
            root.InsertChild( m, Matrix4d.Identity );
              }

              root.SetAttribute( PropertyName.REFLECTANCE_MODEL, new PhongModel() );
              root.SetAttribute( PropertyName.MATERIAL, new PhongMaterial( surfaceColor, 0.2, 0.5, 0.4, 32 ) );
              root.SetAttribute( PropertyName.COLOR, surfaceColor );
              sc.Intersectable = root;

              // Background color:
              sc.BackgroundColor = new double[] { 0.0, 0.05, 0.07 };

              // Camera:
              double dist = (0.5 * diameter * correction) / Math.Tan( MathHelper.DegreesToRadians( (float)(0.5 * FoVy) ) );
              Vector3d cam = (Vector3d)center - dist * dir;
              sc.Camera = new StaticCamera( cam, dir, FoVy );

              // Light sources:
              sc.Sources = new LinkedList<ILightSource>();
              sc.Sources.Add( new AmbientLightSource( 0.8 ) );
              Vector3d lightDir = Vector3d.TransformVector( dir, Matrix4d.CreateRotationY( -2.0 ) );
              lightDir = Vector3d.TransformVector( lightDir, Matrix4d.CreateRotationZ( -0.8 ) );
              sc.Sources.Add( new PointLightSource( (Vector3d)center + diameter * lightDir, 1.0 ) );

              return faces;
        }
Ejemplo n.º 3
0
 public SceneBrep Clone()
 {
     SceneBrep tmp = new SceneBrep();
       tmp.geometry = new List<Vector3>( geometry );
       if ( normals != null ) tmp.normals = new List<Vector3>( normals );
       if ( colors != null ) tmp.colors = new List<Vector3>( colors );
       if ( txtCoords != null ) tmp.txtCoords = new List<Vector2>( txtCoords );
       if ( vertexPtr != null ) tmp.vertexPtr = new List<int>( vertexPtr );
       if ( oppositePtr != null ) tmp.oppositePtr = new List<int>( oppositePtr );
       tmp.BuildCornerTable();
       return tmp;
 }