forked from jdarais/YafaRayforXSI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyafxsi_object.cpp
More file actions
213 lines (195 loc) · 8.1 KB
/
Copy pathyafxsi_object.cpp
File metadata and controls
213 lines (195 loc) · 8.1 KB
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
/*!
This file is part of YafXSI.
YafaRay Exporter for Autodesk(c) Softimage(c).
Copyright (C) 2010 2011 2012 Pedro Alcaide, aka povmaniaco
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma warning (disable : 4244)
//-
#include "include/yafxsi_main.h"
//--
using namespace XSI;
using namespace yafaray;
using namespace std;
using namespace MATH;
//--
extern Application app;
/*
This module write geometric shapes for preview scene materials and sphere_light, atm...
*/
//---
int yaf_geometry( yafrayInterface_t *yi, vector3d_t pos, float rad, std::string typeGeo, material_t *mat )
{
//--
unsigned int ID = 0;
yi->startGeometry();
//-----------------------
if ( typeGeo == "plane" )
//-----------------------
{
// a simple plane formule....
float pcentro = 0.0; //- center XY coord, always ( 0, 0 )
float size = rad; // prevent to use for 'area_liht' plane
float pxn, pxp, pyn, pyp, pz;
pxn = pcentro - size / 2; pxp = pcentro + size / 2;
pyn = pcentro - size / 2; pyp = pcentro + size / 2;
pz = pos.z ; // Z
//-- simple plane, uv {pxn, pyp, pz, pxn, pyn, pz, pxp, pyp, pz, pxp, pyn, pz };
double p_points [12] = {pxn, pyp, pz, pxn, pyn, pz, pxp, pyp, pz, pxp, pyn, pz };
double p_normals [12] = { 0, -0, 1, 0, -0, 1, 0, -0, 1, 0, -0, 1 };
int p_faces [6] = { 0, 1, 3, 0, 3, 2 }; // index
double p_uvs [8] = { 0, 1, 0, 0, 1, 0, 1, 1 };
int p_faces_uv [6] = { 0, 1, 2, 0, 2, 3 };
//--
// app.LogMessage(L"-line 69 -yafxsi_object -Shape is: plane ");
//--
ID = yi->getNextFreeID();
yi->startTriMesh(ID, 4, 2, false, false, 0);
//-- vertex
for ( LONG p = 0; p < 12; p += 3)
{
vector3d_t points_p( p_points[p], p_points[p+1], p_points[p+2]);
yi->addVertex( points_p[0], points_p[1], points_p[2]);
}
//-- normals
//for ( LONG n = 0; n < 12; n += 3)
//{
// vector3d_t normals( p_normals[n], p_normals[n + 1], p_normals[n+2]);
// yi->addVertex( normals[0], normals[1], normals[2]);
//}
//-- uvs
for ( LONG v = 0; v < 8; v +=2)
{
vector3d_t uvs(p_uvs[v], p_uvs[v + 1], 0);
yi->addUV(uvs[0], uvs[1]);
}
//-- faces + faces uv
for ( LONG f = 0; f < 6; f += 3)
{
vector3d_t faces_uv( p_faces_uv[f], p_faces_uv[f+1], p_faces_uv[f+2]);
vector3d_t faces_p( p_faces[f], p_faces[f+1], p_faces[f+2]);
//
yi->addTriangle( faces_p[0], faces_p[1], faces_p[2], faces_uv[0], faces_uv[1], faces_uv[2], mat);
}
yi->endTriMesh();
yi->smoothMesh(ID, 0); //-- delete if not need smooth?
}
//----------------------
if ( typeGeo == "cube" )
//----------------------
{
// cube with 1 x 1 x 1 units, placed in (0, 0, 0)
double points [24] = {-.5, .5, -.5, .5, .5, -.5, -.5, .5, .5, .5, .5, .5, -.5, -.5, -.5, .5, -.5, -.5, -.5, -.5, .5, .5, -.5, .5 };
int faces [36] = {0, 2, 3, 0, 3, 1, 0, 1, 5, 0, 5, 4, 0, 4, 6, 0, 6, 2, 1, 3, 7, 1, 7, 5, 2, 6, 7, 2, 7, 3, 4, 5, 7, 4, 7, 6 };
//-- generate ID for this mesh
ID = yi->getNextFreeID();
yi->startTriMesh(ID, 8, 12, false, false, 0);
//--
for ( LONG i = 0; i < 24; i += 3)
{
vector3d_t vertices( points[i], points[i+1], points[i+2] ); // 0 1 2, 3 4 5,....
yi->addVertex( vertices[0], vertices[1], vertices[2] );
}
//--
for ( LONG j = 0; j < 36; j += 3)
{
vector3d_t tris( faces[j], faces[j+1], faces[j+2] ); // 0 1 2, 3 4 5,....
yi->addTriangle( tris[0], tris[1], tris[2], mat );
}
yi->endTriMesh();
yi->smoothMesh(ID, 0);
}
//------------------------
if ( typeGeo == "sphere" )
//------------------------
{
//! This code create geometry for ;
// scene 'preview materials', shapes 'preview material' or 'sphere_light'
// with 'visible geometry' enable
//-- resolution (u,v) for sphere; 24 x 48
int nu = 24, nv = 48;
//-- generate ID for this mesh
ID = yi->getNextFreeID();
yi->startTriMesh(ID, 2 + (nu - 1) * nv, 2 * (nu - 1) * nv, false, false);
yi->addVertex(pos[0], pos[1], pos[2] + rad);
yi->addVertex(pos[0], pos[1], pos[2] - rad);
//--
for (LONG i = 0; i < nv; i++)
{
float t = i / float(nv);
float sin_v = sin(2.0 * PI * t);
float cos_v = cos(2.0 * PI * t);
//--
for (LONG j = 1; j < nu; j++)
{
float s = j / float(nu);
float sin_u = sin(PI * s);
float cos_u = cos(PI * s);
yi->addVertex(pos[0] + cos_v * sin_u * rad, pos[1] + sin_v * sin_u * rad, pos[2] + cos_u * rad);
}
}
//--
for ( LONG k = 0; k < nv; k++) // v = k
{
yi->addTriangle(0, 2 + k * (nu - 1), 2 + ((k + 1) % nv) * (nu - 1), mat);
yi->addTriangle(1, ((k + 1) % nv) * (nu - 1) + nu, k * (nu - 1) + nu, mat);
//--
for ( LONG l = 0; l < nu - 2; l++) // u = l
{
yi->addTriangle(2 + k * (nu - 1) + l, 2 + k * (nu - 1) + l + 1, 2 + ((k + 1) % nv) * (nu - 1) + l, mat);
yi->addTriangle(2 + k * (nu - 1) + l + 1, 2 + ((k + 1) % nv) * (nu - 1) + l + 1, 2 + ((k + 1) % nv) * (nu - 1) + l, mat);
}
}
//--
yi->endTriMesh();
yi->smoothMesh(ID, 181);
}
//--------------------------
if ( typeGeo == "cylinder" ) // experimental....
//--------------------------
{
//-- simple cylinder
double cilindr_v [54] = {0, -0, 0.0103531, 0, -0, 1.51035, -0.5, 6.12303e-017, 0.0103531, -0.5,
6.12303e-017, 1.51035, -0.353553, -0.353553, 0.0103531, -0.353553, -0.353553, 1.51035,
-1.38778e-016, -0.5, 0.0103531, -1.38778e-016, -0.5, 1.51035, 0.353553, -0.353553, 0.0103531,
0.353553, -0.353553, 1.51035, 0.5, -2.22045e-016, 0.0103531, 0.5, -2.22045e-016, 1.51035,
0.353553, 0.353553, 0.0103531, 0.353553, 0.353553, 1.51035, 3.33067e-016, 0.5, 0.0103531,
3.33067e-016, 0.5, 1.51035, -0.353553, 0.353553, 0.0103531, -0.353553, 0.353553, 1.51035 };
int cilindr_f [96] = {4, 2, 0, 2, 4, 5, 2, 5, 3, 3, 5, 1, 6, 4, 0, 4, 6, 7, 4, 7, 5, 5, 7, 1, 8, 6, 0,
6, 8, 9, 6, 9, 7, 7, 9, 1, 10, 8, 0, 8, 10, 11, 8, 11, 9, 9, 11, 1, 12, 10, 0, 10, 12, 13, 10, 13, 11,
11, 13, 1, 14, 12, 0, 12, 14, 15, 12, 15, 13, 13, 15, 1, 16, 14, 0, 14, 16, 17, 14, 17, 15, 15, 17, 1,
2, 16, 0, 16, 2, 3,16, 3, 17, 17, 3, 1 };
//-- generate ID for this mesh
ID = yi->getNextFreeID();
yi->startTriMesh(ID, 54, 96, false, false, 0);
//--
for (LONG i = 0; i < 54; i += 3)
{
//--
vector3d_t p_cylinder( cilindr_v[i], cilindr_v[i+1], cilindr_v[i+2]);
yi->addVertex( p_cylinder[0], p_cylinder[1], p_cylinder[2]);
}
//--
for ( LONG j = 0; j < 96; j += 3)
{
//--
vector3d_t f_cylinder( cilindr_f[j], cilindr_f[j+1], cilindr_f[j+2]);
yi->addTriangle( f_cylinder[0], f_cylinder[1], f_cylinder[2], mat);
}
//--
yi->endTriMesh();
yi->smoothMesh(ID, 181);
}
//--
yi->endGeometry();
return ID;
}