reading oddb3dsolid, oddbbody decomposeforsave
reading oddb3dsolid, oddbbody decomposeforsave
dear oda users,
i have this problem for a long long time without any solution yet ....
i can't display dwg files with complex objects.
i would like to explode 3dsolid or body into someything i can display like a face array (mesh) for ex..
this would be nice.
/////////////////////////////////////////////////////
every thread about this discussion are using decomposeforsave
oddbobjectptr pnewobj = psolid->decomposeforsave(oddb::vac12, replaceid, exchangexdata);
// and next
((oddbentityptr )pnewobj)->explode(entityset);
// so you get oddbpolyfacemesh. if you use explode again you obtain oddbface . this is what i want indeed at the end > n faces
i also know the code in odamfcapp\dwgview.cpp
cdwgview:

neditacisconversion()
/////////////////////////////////////////////////////
but my database is in read mode since i'm traversing it to read the file.
how can i use decomposeforsave since i don't really want to save something.
decomposeforsave returns an error since my database is not in write mode.
can i save while reading ?
must i create a copy of initial file tempory file and write inside it ?
any idea or even better code will be greatly appreciated
philippe
philippe,
i dont know if this helps, but i have created two different vectorizers, one is my outline vectorizer, the other is my shaded vectorizer.
the i store the details in a "3d object" container and use this to draw, save, intersect test, etc with.
the main reason i did it this way was for performance, i have many drawings where using the decompose for save took a very long to load the data, this version below is much faster (i suppose it is because the decompose for save is creating brand new objects etc.. but i am only guessing)
example code as belows :
note: i have copied and pasted direct out of my engine, and some items are specific to my very own objects, you will simply need to use common sense to replace these with appropriate items, or do it in a totally different way then myself. also note that since you are parsing the file yourself (which is how i have done it), that the vertices below are in there base form, ie if the 3dsolid is inside of a block, you will need to ensure the matrix manipulations are done as well, this is the reason for addpnt2ent functions, as they have the current matrix stack and will adjust the vertex to the correct location.
class vectorizer : public odgigeometrysimplifier, public odgsbasevectorizeview {
public:
vectorizer() {
};
virtual void polylineout(odint32 n, const odgepoint3d* pts);
virtual void polygonout(odint32 nbpoints, const odgepoint3d *pvertexlist, const odgevector3d *pnormal = 0);
void setgmtryent(csmplptr apgmtry) { m_apgmtry = apgmtry;};
void setldr(copendwgptr apldr) { m_apldr = apldr;};
private:
csmplptr m_apgmtry;
copendwgptr m_apldr;
};
void vectorizer

lylineout(odint32 n, const odgepoint3d* pts) {
if( m_apldr.valid() && m_apgmtry.valid() ) {
m_apldr->bgnaddpnts(m_apgmtry);
const odgepoint3d *curpnt = pts;
for( int i = 0; i < n; i++ ) {
m_apldr->addpnt2ent(m_apgmtry, odgepoint3d(curpnt->x, curpnt->y, curpnt->z));
curpnt++;
}
m_apldr->endaddpnts(m_apgmtry);
}
}
void vectorizer

lygonout(odint32 nbpoints, const odgepoint3d *pvertexlist, const odgevector3d *pnormal) {
if( m_apldr.valid() && m_apgmtry.valid() ) {
m_apldr->bgnaddpnts(m_apgmtry);
const odgepoint3d *curpnt = pvertexlist;
for( int i = 0; i < nbpoints; i++ ) {
m_apldr->addpnt2ent(m_apgmtry, odgepoint3d(curpnt->x, curpnt->y, curpnt->z));
curpnt++;
}
m_apldr->endaddpnts(m_apgmtry);
}
}
and i call the above with code like :
/////////////////////////////////////////////////////////////////////////////////////////
// first get the polyline representation
/////////////////////////////////////////////////////////////////////////////////////////
{
odstaticrxobject<vectorizer> dv;
dv.setgmtryent(ap3dsolid);
dv.setldr(this);
odstaticrxobject<odgicontextfordbdatabase> gicontext;
gicontext.setdatabase(od3dsolidptr->database());
dv.setdrawcontext(&dv);
dv.setcontext(&gicontext);
dv.output().setdestgeometry(dv);
dv.beginviewvectorization();
dv.draw(od3dsolidptr);
dv.endviewvectorization();
}
next i do the shaded view with :
//---------------------------------------------------------------------------------
class shadedvectorizer : public odgigeometrysimplifier, public odgsbasevectorizeview {
public:
shadedvectorizer() {
odgsbasevectorizeview::setmode(kgouraudshaded);
};
virtual void triangleout(const odint32* vertices, const odgevector3d* pnormal);
void settrisets(ctrisets *ptrisets) {m_ptrisets = ptrisets;};
void setldr(copendwgptr apldr) { m_apldr = apldr;};
private:
ctrisets *m_ptrisets;
copendwgptr m_apldr;
};
void shadedvectorizer::triangleout(const odint32* vertices, const odgevector3d* pnormal) {
const odgepoint3d *pvtces = vertexdatalist();
const odgepoint3d pv1 = pvtces[vertices[0]];
const odgepoint3d pv2 = pvtces[vertices[1]];
const odgepoint3d pv3 = pvtces[vertices[2]];
cvctr nrmls[3];
if( vertexdata() ) { // m_bisvertsnormals ) {
odgiorientationtype ornt = vertexdata()->orientationflag();
for( int i = 0; i < 3; i++ ) {
const odgevector3d *podnrml = vertexdata()->normals() + vertices[i];
switch( ornt ) {
case kodgicounterclockwise:
{
nrmls[i] = cvctr(podnrml->x, podnrml->y, podnrml->z);
}
break;
case kodgiclockwise:
{
nrmls[i] = cvctr(-podnrml->x, -podnrml->y, -podnrml->z);
}
break;
default:
{
if( vertexdata()->normals() ) {
odgevector3d normal = vertexdata()->normals()[ vertices[i] ];
if( pnormal ) {
if( normal.dotproduct(*pnormal) < 0.0) {
normal *= -1.0;
}
nrmls[i] = cvctr(normal.x, normal.y, normal.z);
}
}
}
}
}
} else if( pnormal ){
//nrmls[0] = cvctr(pnormal->x, pnormal->y, pnormal->z);
nrmls[0] = get3dnorm(cpnt(pv1.x, pv1.y, pv1.z), cpnt(pv2.x, pv2.y, pv2.z), cpnt(pv3.x, pv3.y, pv3.z));
nrmls[1] = nrmls[0];
nrmls[2] = nrmls[0];
} else {
// should do our own calc here
nrmls[0] = get3dnorm(cpnt(pv1.x, pv1.y, pv1.z), cpnt(pv2.x, pv2.y, pv2.z), cpnt(pv3.x, pv3.y, pv3.z));
nrmls[1] = nrmls[0];
nrmls[2] = nrmls[0];
}
m_apldr->addtriset(m_ptrisets, pv1, pv2, pv3, nrmls[0], nrmls[1], nrmls[2]);
}
/////////////////////////////////////////////////////////////////////////////////////////
// no get the gourade shading of the solid
/////////////////////////////////////////////////////////////////////////////////////////
{
odstaticrxobject<shadedvectorizer> dvs;
dvs.settrisets(dynamic_cast<ctrisets*>( ap3dsolid.get()) );
dvs.setldr(this);
odstaticrxobject<odgicontextfordbdatabase> gicontext;
gicontext.setdatabase(od3dsolidptr->database());
dvs.setdrawcontext(&dvs);
dvs.setcontext(&gicontext);
dvs.output().setdestgeometry(dvs);
dvs.beginviewvectorization();
dvs.draw(od3dsolidptr);
dvs.endviewvectorization();
}
hope this helps
cheers
jason
last edited by janderssen; 29th march 2007 at 06:50 pmfff">.
very nice! i've been looking for a small piece of code like this.
but one problem remains for me:
i only get polyline representations out of my database. if i use the shadedvectorizer simply nothing is returned.
i really need those vertices in modelspace coordinates as i have to import the geometry to my own mesh format.
1) did you setup some view options except the gouraudshading?
2) did you supply specific transformation matrices for world2eye etc?
any hints are appreciated.
p.s. i've played around with the exvectorizer ... same problem here. i guess it's related to the layout chosen.
where do we set mode (odgsview::kgouraudshaded) ???
janderssen,
thanks for your help. with your help and \msvc6\examples\odvectorizeex\odvectorizeex.dsp
i finally find a solution to get faces but i don't know why one code fails and one succeed :
this code wil output polyline
odgsviewptr exgssimpledevice::createview(const odgsclientviewinfo* pinfo, bool benablelayervisibilityperview)
{
odgsviewptr pview = exsimpleview::createobject();
exsimpleview* pmyview = static_cast<exsimpleview*>(pview.get());
pmyview->setmode(odgsview::kgouraudshaded);
...
}
this code works will output faces :
void exsimpleview::draw(const odgidrawable* pdrawable)
{
...
odgsbasevectorizeview::setmode(kgouraudshaded);
odgsbasevectorizeview::draw(pdrawable);
..
}
phillipe,
sorry for the delay, i have just returned from holidays.
my shaded vectorizer is as follows :
//---------------------------------------------------------------------------------
class shadedvectorizer : public odgigeometrysimplifier, public odgsbasevectorizeview {
public:
shadedvectorizer() {
odgsbasevectorizeview::setmode(kgouraudshaded);
};
virtual void triangleout(const odint32* vertices, const odgevector3d* pnormal);
void settrisets(ctrisets *ptrisets) {m_ptrisets = ptrisets;};
void setldr(copendwgptr apldr) { m_apldr = apldr;};
private:
ctrisets *m_ptrisets;
copendwgptr m_apldr;
};
take note of the setmode call in the constructor.
hope this helps
cheers
jason