MeshObjectNode Class Reference

MeshObject の Polygonデータを格納するクラス.リスト構造を取る..

#include <MeshObjectData.h>

Collaboration diagram for MeshObjectNode:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MeshObjectNode (void)
virtual ~MeshObjectNode (void)
void init (void)
void free (void)
void free_value (void)
void clear (void)
void set (int vertex, int polygon, int vcount=3)
bool getm (int vertex=0, int polygon=0, int vcount=0)
void setFacetNo (int no)
void setMaterialParam (MaterialParam param)
 ノードにマテリアルパラメータを設定し,他のノードに同じマテリアルが存在するかチャックする.
void delMaterialParam (void)
void setMaterialID (const char *str)
void * getMaterialID (void)
void execAffineTrans (UVMap< double > *uvmap=NULL, int num=-1)
UVMap< double > * generatePlanarUVMap (Vector< double > scale, UVMap< double > *uvmap=NULL)
bool computeVertexDirect (FacetBaseData *facetdata)
bool computeVertexDirect (Vector< double > *vtx, Vector< double > *nml, UVMap< double > *map, int num, int vcount=3)
bool computeVertexByBREP (Vector< double > *vtx, Vector< double > *nml, UVMap< double > *map, int num, int vcount=3)

Public Attributes

Buffer material_id
 マテリアルを識別するID
bool same_material
 他の Node が既に同じマテリアルを使用している.
int facet_no
 面番号
MaterialParam material_param
 マテリアルパラメータ
int num_index
 頂点の延べ数.num_polygon*MeshObjectDatanum_vcount(data_index の要素数)
int num_polygon
 ポリゴンの数
int num_vertex
 頂点のデータ数.(vertex_value, normal_value の要素数)
int num_texcrd
 テクスチャ画像の座標数.通常は num_vertex に等しい.(texcrd_value の要素数)
int * data_index
 インデックスデータ
Vector< double > * vertex_value
 頂点データの並び
Vector< double > * normal_value
 法線ベクトルエータの並び
UVMap< double > * texcrd_value
 テクスチャマップの並び
MeshObjectNodenext
MeshObjectNodeprev

Detailed Description

Definition at line 37 of file MeshObjectData.h.


Constructor & Destructor Documentation

MeshObjectNode ( void   )  [inline]

Definition at line 61 of file MeshObjectData.h.

References MeshObjectNode::init().

00061 { init();}

Here is the call graph for this function:

virtual ~MeshObjectNode ( void   )  [inline, virtual]

Definition at line 62 of file MeshObjectData.h.

00062 {}


Member Function Documentation

void clear ( void   ) 

Definition at line 138 of file MeshObjectData.cpp.

References MeshObjectNode::free(), and MeshObjectNode::init().

00139 {
00140     this->free();
00141     init();
00142 }

Here is the call graph for this function:

bool computeVertexByBREP ( Vector< double > *  impvtx,
Vector< double > *  impnrm,
UVMap< double > *  impmap,
int  impnum,
int  vcount = 3 
)

bool MeshObjectNode::computeVertexByBREP(Vector<double>* impvtx, Vector<double>* impnrm, UVMap<double>* impmap, int impnum, int vcount)

BREPを使用して,頂点データを処理する.頂点データは再インデックス化される

データがインデックス化されていない場合,重複頂点を削除するのでデータサイズが小さくなる.
法線ベクトルが計算されていない場合(ipnrmがNULLの場合),法線ベクトルを計算する.
頂点数が多い場合は,処理に時間が掛かる.

Parameters:
impvtx インポートする頂点の座標データ.(必須)
impnrm インポートする法線ベクトルデータ.NULLの場合,再計算が行われる.(オプション)
impmap インポートする頂点のUVマップデータ.(オプション)
impnum インポートするデータの数
vcount ポリゴンの頂点数.通常は 3
Returns:
インポートに成功したかどうか.

Definition at line 268 of file MeshObjectData.cpp.

References jbxl::BREP_SOLID, BREP_SOLID::contours, jbxl::CreateTriSolidFromVector(), MeshObjectNode::data_index, BREP_SOLID::facetno, MeshObjectNode::free(), jbxl::freeBrepSolid(), MeshObjectNode::getm(), jbxl::GetOctreeVertices(), BREP_VERTEX::index, BREP_WING::next, BREP_VERTEX::normal, MeshObjectNode::normal_value, MeshObjectNode::num_vertex, BREP_SOLID::octree, BREP_VERTEX::point, MeshObjectNode::texcrd_value, BREP_VERTEX::uvmap, BREP_WING::vertex, and MeshObjectNode::vertex_value.

Referenced by MeshObjectData::addNode().

00269 {
00270     if (impvtx==NULL) return false;
00271 
00272     BREP_SOLID* brep = new BREP_SOLID();
00273     if (brep==NULL) return false;
00274     CreateTriSolidFromVector(brep, impnum, impvtx, impnrm, impmap, false, false);   // 重複登録を許可しない.データチェックはしない.
00275 
00276     long int  vnum;
00277     BREP_VERTEX** vertex_data = GetOctreeVertices(brep->octree, &vnum);
00278     if (vertex_data==NULL) {
00279         freeBrepSolid(brep);
00280         return false;
00281     }
00282 
00283     // メモリの確保
00284     set((int)vnum, brep->facetno, vcount);
00285     if (!getm()) {
00286         ::free(vertex_data);
00287         freeBrepSolid(brep);
00288         return false;
00289     }
00290 
00291     // Vertex & Normal & Texcoord
00292     for (int i=0; i<num_vertex; i++) {
00293         vertex_value[i] = vertex_data[i]->point;
00294         normal_value[i] = vertex_data[i]->normal;
00295         texcrd_value[i] = vertex_data[i]->uvmap;
00296     }
00297 
00298     // Index
00299     int polyn = 0;
00300     BREP_CONTOUR_LIST::iterator icon;
00301     for (icon=brep->contours.begin(); icon!=brep->contours.end(); icon++){
00302         BREP_WING* wing = (*icon)->wing;
00303         for (int i=0; i<vcount; i++) {
00304             BREP_VERTEX* vertex = wing->vertex;
00305             if (vertex!=NULL) {
00306                 data_index[polyn*vcount+i] = vertex->index;
00307             }
00308             wing = wing->next;
00309         }
00310         polyn++;
00311     }
00312 
00313     ::free(vertex_data);
00314     freeBrepSolid(brep);
00315 
00316     return true;
00317 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool computeVertexDirect ( Vector< double > *  impvtx,
Vector< double > *  impnrm,
UVMap< double > *  impmap,
int  impnum,
int  vcount = 3 
)

整列化(インデックス化ではない)された頂点データを直接 MeshObjectのデータとしてインポートする.

元のデータの再現性が良い.処理時間が早い.
法線ベクトルが必須.データサイズは大きくなる.

Parameters:
impvtx インポートする頂点の座標データ(必須)
impnrm インポートする法線ベクトルデータ(必須)
impmap インポートする頂点のUVマップデータ(オプション)
impnum インポートするデータの数
vcount ポリゴンの頂点数.通常は 3
Returns:
インポートに成功したかどうか.

Definition at line 228 of file MeshObjectData.cpp.

References MeshObjectNode::data_index, MeshObjectNode::getm(), MeshObjectNode::normal_value, MeshObjectNode::num_vertex, MeshObjectNode::texcrd_value, and MeshObjectNode::vertex_value.

00229 {
00230     if (impvtx==NULL || impnrm==NULL) return false;
00231 
00232     set(impnum, impnum/vcount, vcount);
00233     if (!getm()) return false;
00234 
00235     for (int i=0; i<num_vertex; i++) {
00236         vertex_value[i] = impvtx[i];
00237         normal_value[i] = impnrm[i];
00238         data_index[i]   = i;
00239     }
00240 
00241     if (impmap!=NULL) {
00242         for (int i=0; i<num_vertex; i++) {
00243             texcrd_value[i] = impmap[i];
00244         }
00245     }
00246 
00247     return true;
00248 }

Here is the call graph for this function:

bool computeVertexDirect ( FacetBaseData facetdata  ) 

インデックス化された頂点データを直接 MeshObjectのデータとしてインポートする.

Definition at line 188 of file MeshObjectData.cpp.

References MeshObjectNode::data_index, MeshObjectNode::getm(), FacetBaseData::index, FacetBaseData::normal, MeshObjectNode::normal_value, FacetBaseData::num_data, FacetBaseData::num_index, MeshObjectNode::num_texcrd, MeshObjectNode::num_vertex, FacetBaseData::texcrd, MeshObjectNode::texcrd_value, FacetBaseData::vcount, FacetBaseData::vertex, and MeshObjectNode::vertex_value.

Referenced by MeshObjectData::addNode().

00189 {
00190     if (facetdata==NULL) return false;
00191     if (facetdata->index==NULL || facetdata->vertex==NULL || facetdata->normal==NULL) return false;
00192 
00193     set(facetdata->num_data, facetdata->num_index/facetdata->vcount, facetdata->vcount);
00194     if (!getm()) return false;
00195 
00196     for (int i=0; i<facetdata->num_index; i++) {
00197         data_index[i]   = facetdata->index[i];
00198     }
00199     for (int i=0; i<num_vertex; i++) {
00200         normal_value[i] = facetdata->normal[i];
00201         vertex_value[i] = facetdata->vertex[i];
00202     }
00203 
00204     if (facetdata->texcrd!=NULL) {
00205         for (int i=0; i<num_texcrd; i++) {
00206             texcrd_value[i] = facetdata->texcrd[i];
00207         }
00208     }
00209 
00210     return true;
00211 }

Here is the call graph for this function:

Here is the caller graph for this function:

void delMaterialParam ( void   )  [inline]

Definition at line 75 of file MeshObjectData.h.

References MaterialParam::clear(), and MeshObjectNode::material_param.

Referenced by MeshObjectNode::free().

00075 { material_param.clear();}

Here is the call graph for this function:

Here is the caller graph for this function:

void execAffineTrans ( UVMap< double > *  uvmap = NULL,
int  num = -1 
)

Definition at line 320 of file MeshObjectData.cpp.

References MaterialParam::execTrans(), MeshObjectNode::material_param, MeshObjectNode::num_texcrd, and MeshObjectNode::texcrd_value.

Referenced by ColladaXML::addTexcrdSource().

00321 {
00322     if (uvmap==NULL) uvmap = texcrd_value;
00323     if (uvnum==-1)   uvnum = num_texcrd;
00324 
00325     material_param.execTrans(uvmap, uvnum); 
00326 
00327     return;
00328 }

Here is the call graph for this function:

Here is the caller graph for this function:

void free ( void   ) 

Definition at line 118 of file MeshObjectData.cpp.

References MeshObjectNode::delMaterialParam(), free_Buffer(), MeshObjectNode::free_value(), and MeshObjectNode::material_id.

Referenced by MeshObjectNode::clear(), MeshObjectNode::computeVertexByBREP(), jbxl::freeMeshObjectNode(), and MeshObjectNode::getm().

00119 {
00120     delMaterialParam();
00121     free_Buffer(&material_id);
00122 
00123     free_value();
00124 }

Here is the call graph for this function:

Here is the caller graph for this function:

void free_value ( void   ) 

Definition at line 128 of file MeshObjectData.cpp.

References MeshObjectNode::data_index, jbxl::freeNull(), MeshObjectNode::normal_value, MeshObjectNode::texcrd_value, and MeshObjectNode::vertex_value.

Referenced by MeshObjectNode::free(), and MeshObjectNode::getm().

00129 {
00130     freeNull(data_index); 
00131     freeNull(vertex_value); 
00132     freeNull(normal_value); 
00133     freeNull(texcrd_value); 
00134 }

Here is the call graph for this function:

Here is the caller graph for this function:

UVMap< double > * generatePlanarUVMap ( Vector< double >  scale,
UVMap< double > *  uvmap = NULL 
)

頂点データから,各 nodeの Planar UVマップを生成する 頂点データ(vertex_value, normal_value) がインポート済みでなければならない.

Parameters:
scale オブジェクトのサイズ
uvmap 生成したオブジェクトを格納する UVMapへのポインタ(サイズは num_texcrd). NULLの場合は領域を新たに確保する.
Returns:
UVMap へのポインタ.サイズは num_texcrd. 失敗した場合は NULL
See also:
libopenmetaverse OpenMetaverse.Rendering.Meshmerizer:MeshmerizerR.cs

Definition at line 342 of file MeshObjectData.cpp.

References MeshObjectNode::normal_value, MeshObjectNode::num_texcrd, MeshObjectNode::num_vertex, Vector< T >::set(), UVMap< T >::u, UVMap< T >::v, MeshObjectNode::vertex_value, Vector< T >::x, Vector< T >::y, and Vector< T >::z.

Referenced by ColladaXML::addTexcrdSource().

00343 {
00344     if (num_texcrd!=num_vertex) return NULL;
00345 
00346     if (uvmap==NULL) {
00347         size_t len = num_texcrd*sizeof(UVMap<double>);
00348         uvmap = (UVMap<double>*)malloc(len);
00349     }
00350 
00351     for (int i=0; i<num_texcrd; i++) {
00352         //
00353         Vector<double> binormal;
00354 
00355         if (normal_value[i].x>=0.5 || normal_value[i].x<=-0.5) {
00356             binormal.set(0.0, 1.0, 0.0);
00357             if (normal_value[i].x<0.0) binormal = - binormal;
00358         }
00359         else {
00360             binormal.set(1.0, 0.0, 0.0);
00361             if (normal_value[i].y>0.0) binormal = - binormal;
00362         }
00363 
00364         Vector<double> tangent = binormal^normal_value[i];
00365         Vector<double> pos(vertex_value[i].x*scale.x, vertex_value[i].y*scale.y, vertex_value[i].z*scale.z);
00366 
00367         uvmap[i].u = 0.5 + (binormal*pos)*2.0;
00368         uvmap[i].v = 0.5 - (tangent *pos)*2.0;
00369     }
00370 
00371     return uvmap;
00372 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool getm ( int  vertex = 0,
int  polygon = 0,
int  vcount = 0 
)

bool MeshObjectNode::getm(int vertex, int polygon, int vcount)

必要なメモリを確保する. 失敗,成功に係らず,以前のメモリは開放される.

Return values:
true メモリの確保に成功.
false メモリの確保に失敗.
Parameters:
vertex 頂点の数
polygon ポリゴンの数
vcount 1ポリゴン当たりの頂点数(固定)

Definition at line 159 of file MeshObjectData.cpp.

References MeshObjectNode::data_index, MeshObjectNode::free(), MeshObjectNode::free_value(), MeshObjectNode::normal_value, MeshObjectNode::num_index, MeshObjectNode::num_polygon, MeshObjectNode::num_texcrd, MeshObjectNode::num_vertex, MeshObjectNode::texcrd_value, and MeshObjectNode::vertex_value.

Referenced by MeshObjectNode::computeVertexByBREP(), and MeshObjectNode::computeVertexDirect().

00160 {
00161     free_value();
00162 
00163     if (vertex >0) num_vertex  = vertex;
00164     if (polygon>0) num_polygon = polygon;
00165     if (vcount >0) num_index   = num_polygon*vcount;
00166 
00167     if (num_vertex<=0 || num_polygon<=0) return false;
00168     num_texcrd = num_vertex;
00169 
00170     vertex_value = (Vector<double>*)malloc(num_vertex*sizeof(Vector<double>));
00171     normal_value = (Vector<double>*)malloc(num_vertex*sizeof(Vector<double>));
00172     texcrd_value = (UVMap<double>*) malloc(num_texcrd*sizeof(UVMap<double>));
00173     data_index   = (int*)malloc(num_index*sizeof(int));
00174 
00175     if (data_index==NULL || vertex_value==NULL || normal_value==NULL || texcrd_value==NULL) {
00176         this->free();
00177         return false;
00178     }
00179 
00180     return true;
00181 }

Here is the call graph for this function:

Here is the caller graph for this function:

void* getMaterialID ( void   )  [inline]

Definition at line 78 of file MeshObjectData.h.

References _tochar, Buffer::buf, and MeshObjectNode::material_id.

00078 { return _tochar(material_id.buf);}

void init ( void   ) 
void set ( int  vertex,
int  polygon,
int  vcount = 3 
)

Definition at line 106 of file MeshObjectData.cpp.

References MeshObjectNode::num_index, MeshObjectNode::num_polygon, MeshObjectNode::num_texcrd, and MeshObjectNode::num_vertex.

00107 {
00108     num_vertex  = vertex;
00109     num_texcrd  = num_vertex;
00110     num_polygon = polygon;
00111     num_index   = num_polygon*vcount;
00112 
00113     return;
00114 }

void setFacetNo ( int  no  )  [inline]

Definition at line 73 of file MeshObjectData.h.

References MeshObjectNode::facet_no.

Referenced by MeshObjectData::addData().

00073 { if (no>=0) facet_no = no;}

Here is the caller graph for this function:

void setMaterialID ( const char *  str  ) 

Definition at line 76 of file MeshObjectData.cpp.

References cat_Buffer(), cat_s2Buffer, free_Buffer(), make_Buffer_randomstr, make_Buffer_str, MeshObjectNode::material_id, and MOBJN_MTERIALID_RAND_LEN.

Referenced by MeshObjectData::addNode(), and MeshObjectNode::setMaterialParam().

00077 {
00078     free_Buffer(&material_id);
00079     
00080     if (str!=NULL) {
00081         if (str[0]=='#') {
00082             material_id = make_Buffer_str(str);
00083         }
00084         else {
00085             Buffer randomstr = make_Buffer_randomstr(MOBJN_MTERIALID_RAND_LEN);
00086             material_id = make_Buffer_str("#MATERIAL_");
00087             cat_Buffer(&randomstr, &material_id);
00088             free_Buffer(&randomstr);
00089             cat_s2Buffer("_", &material_id);
00090             cat_s2Buffer(str, &material_id);
00091         }
00092     }
00093     //
00094     else {
00095         Buffer randomstr = make_Buffer_randomstr(MOBJN_MTERIALID_RAND_LEN);
00096         material_id = make_Buffer_str("#MATERIAL_");
00097         cat_Buffer(&randomstr, &material_id);
00098         free_Buffer(&randomstr);
00099     }
00100 
00101     return;
00102 }

Here is the call graph for this function:

Here is the caller graph for this function:

void setMaterialParam ( MaterialParam  param  ) 

Definition at line 45 of file MeshObjectData.cpp.

References _tochar, Buffer::buf, MaterialParam::dup(), MaterialParam::enable, MaterialParam::free(), jbxl::isSameMaterial(), MeshObjectNode::material_id, MeshObjectNode::material_param, MeshObjectNode::next, MeshObjectNode::prev, MeshObjectNode::same_material, and MeshObjectNode::setMaterialID().

Referenced by MeshObjectData::addData(), and MeshObjectData::setMaterialParam().

00046 {
00047     material_param.free();
00048     material_param.dup(mparam);
00049     material_param.enable = true;
00050 
00051     MeshObjectNode* node = prev;
00052     while (node!=NULL) {
00053         if (isSameMaterial(material_param, node->material_param)) {
00054             setMaterialID(_tochar(node->material_id.buf));
00055             same_material = true;
00056             return;
00057         }
00058         node = node->prev;
00059     }
00060 
00061     node = next;
00062     while (node!=NULL) {
00063         if (isSameMaterial(material_param, node->material_param)) {
00064             setMaterialID(_tochar(node->material_id.buf));
00065             same_material = true;
00066             return;
00067         }
00068         node = node->next;
00069     }
00070 
00071     return;
00072 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

int* data_index
int facet_no
Vector<double>* normal_value
int num_index
UVMap<double>* texcrd_value
Vector<double>* vertex_value

The documentation for this class was generated from the following files:

Generated on 15 Nov 2023 for JunkBox_Lib++ (for Windows) by  doxygen 1.6.1