1 /* Copyright 2004, 2005 Nicholas Bishop
2 *
3 * This file is part of SharpConstruct.
4 *
5 * SharpConstruct is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * SharpConstruct is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with SharpConstruct; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
19 #include "config.h"
20 #include "Render.h"
21 #ifdef HAVE_AQSIS_RI_H
22 #include <aqsis/ri.h>
23 #include <cstdlib>
24 #endif
25
Render(Mesh & m)26 void SharpConstruct::ExternalRender::Render( Mesh& m )
27 {
28 #ifdef HAVE_AQSIS_RI_H
29 // Temp c strings
30 char* in = new char[ ImageName.length() ];
31 strcpy( in, ImageName.c_str() );
32 char* rn = new char[ RIBName.length() ];
33 strcpy( rn, RIBName.c_str() );
34
35 // This code is largely based on the RI2RIB tutorial on the Aqsis website
36
37 RtFloat fov = 40;
38
39 RtFloat light1_Int = 0.05;
40 RtFloat light2_Int = 1.5;
41 RtFloat light3_Int = 1;
42 RtPoint light2_From = { 5, 5, 5 };
43 RtPoint light2_To = { 0, 0, 0 };
44 RtPoint light3_From = { 5, 5,-5 };
45 RtPoint light3_To = { 0, 0, 0 };
46
47 RtColor colorPlane = { 0.515, 0.509, 0.520 };
48 RiBegin( rn );
49 RiDisplay( in, "file", RI_RGBA, RI_NULL );
50 RiFormat( Width, Height, 1 );
51 RiProjection( RI_PERSPECTIVE, "fov", &fov, RI_NULL );
52 RiPixelSamples( 2, 2 );
53 RiTranslate( 0, 0, 4 );
54 RiRotate( 180, 1, 0, 0 );
55 RiRotate( 180, 0, 0, 1 );
56 RiWorldBegin();
57 // Lights
58 RiLightSource( "ambientlight","intensity",&light1_Int,RI_NULL);
59 RiLightSource( "distantlight","intensity",&light2_Int,"from",light2_From,"to",light2_To,RI_NULL);
60 RiLightSource( "distantlight","intensity",&light3_Int,"from",light3_From,"to",light3_To,RI_NULL);
61 //RiSurface( "metal", "uniform float thickness", (RtPointer)&shaderVar,RI_NULL );
62 RiTransformBegin();
63 RiColor( colorPlane );
64 //RiScale(4,4,4);
65 //RiTranslate(-0.5,-0.5, 0);
66 for( unsigned i = 0; i < m._triangles.size(); i += 3 )
67 {
68 RtPoint planePoint[ 3 ] = { m._vertex_locations[ m._triangles[ i ].V[ 0 ] ].X(),
69 m._vertex_locations[ m._triangles[ i ].V[ 0 ] ].Y(),
70 m._vertex_locations[ m._triangles[ i ].V[ 0 ] ].Z(),
71 m._vertex_locations[ m._triangles[ i ].V[ 1 ] ].X(),
72 m._vertex_locations[ m._triangles[ i ].V[ 1 ] ].Y(),
73 m._vertex_locations[ m._triangles[ i ].V[ 1 ] ].Z(),
74 m._vertex_locations[ m._triangles[ i ].V[ 2 ] ].X(),
75 m._vertex_locations[ m._triangles[ i ].V[ 2 ] ].Y(),
76 m._vertex_locations[ m._triangles[ i ].V[ 2 ] ].Z() };
77
78 RiPolygon(3, RI_P,(RtPointer)planePoint, RI_NULL);
79 }
80
81 RiTransformEnd();
82
83 RiWorldEnd();
84 RiEnd();
85
86 std::string tmp = "aqsis " + RIBName;
87 system( tmp.c_str() );
88 #endif
89 }
90