git-svn-id: svn://db.shs.com.ru/libs@421 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2018-09-07 08:37:44 +00:00
parent 38bb2244d5
commit b6bad7a921
12 changed files with 174 additions and 41 deletions

View File

@@ -40,6 +40,17 @@ GLObjectBase::GLObjectBase() {
}
GLObjectBase::~GLObjectBase() {
//qDebug() << "del" << name() << view_;
if (parent_) parent_->children_.removeAll(this);
if (view_) ((QGLView*)view_)->objectDeleted(this);
foreach (GLObjectBase * c, children_) {
c->parent_ = 0;
delete c;
}
}
GLObjectBase * GLObjectBase::clone(bool withChildren) {
GLObjectBase * o = new GLObjectBase();
o->pass_ = pass_;
@@ -104,16 +115,34 @@ void GLObjectBase::setView(QGLView * v) {
}
void GLObjectBase::addChild(GLObjectBase * o) {
if (o == this) return;
if (o->parent_)
o->parent_->children_.removeAll(o);
children_ << o;
o->parent_ = this;
o->setView((QGLView*)view_);
o->buildTransform();
if (view_) {
view_->collectLights();
QList<GLObjectBase*> cl = o->children(true);
cl << o;
foreach (GLObjectBase * i, cl) {
emit ((QGLView*)view_)->objectAdded(i);
}
}
}
void GLObjectBase::clearChildren(bool deleteAll) {
foreach (GLObjectBase * i, children_) {
i->setView(0);
i->view_ = 0;
i->parent_ = 0;
i->clearChildren(deleteAll);
if (deleteAll) {
i->clearChildren(true);
delete i;
} else {
i->buildTransform();
}
i->buildTransform();
}
children_.clear();
if (view_) view_->collectLights();
@@ -151,6 +180,27 @@ void GLObjectBase::calculateBoundingBox() {
}
void GLObjectBase::setProperty(const QString & pn, const QVariant & v) {
meta[pn] = v;
}
QVariant GLObjectBase::property(const QString & pn, bool * exists) const {
if (exists) *exists = meta.contains(pn);
return meta.value(pn);
}
bool GLObjectBase::hasProperty(const QString & pn) const {
return meta.contains(pn);
}
void GLObjectBase::removeProperty(const QString & pn) {
meta.remove(pn);
}
void GLObjectBase::setTransform(const QMatrix4x4 & t) {
raw_matrix = true;
mat_ = t;
@@ -171,7 +221,7 @@ void GLObjectBase::select() {
void GLObjectBase::buildTransform() {
itransform_.setToIdentity();
GLObjectBase * p = parent_;
if (p != 0)
if (p)
itransform_ = p->itransform_;
if (raw_matrix) {
itransform_.translate(pos_);
@@ -311,7 +361,7 @@ QDataStream & operator <<(QDataStream & s, const GLObjectBase * p) {
<< cs.chunk(5, p->cast_shadow) << cs.chunk(6, p->rec_shadow) << cs.chunk(7, p->raw_matrix) << cs.chunk(8, p->line_width)
<< cs.chunk(9, int(p->render_mode)) << cs.chunk(10, p->material_) << cs.chunk(11, p->pos_) << cs.chunk(12, p->angles_)
<< cs.chunk(13, p->scale_) << cs.chunk(14, p->mat_) << cs.chunk(15, p->vbo) << cs.chunk(16, p->children_.size())
<< cs.chunk(17, p->name_);
<< cs.chunk(17, p->name_) << cs.chunk(18, p->meta);
//qDebug() << "place self done";
if (p->type_ == GLObjectBase::glLight) {
//qDebug() << "place light ...";
@@ -370,6 +420,7 @@ QDataStream & operator >>(QDataStream & s, GLObjectBase *& p) {
case 15: if (p) p->vbo = cs.getData<GLVBO>(); break;
case 16: if (p) ccnt = cs.getData<int>(); break;
case 17: if (p) p->name_ = cs.getData<QString>(); break;
case 18: if (p) p->meta = cs.getData<QVariantMap>(); break;
case 100: if (l) l->direction = cs.getData<QVector3D>(); break;
case 101: if (l) l->angle_start = cs.getData<GLdouble>(); break;
case 102: if (l) l->angle_end = cs.getData<GLdouble>(); break;