multimaterial support, "preset"
each preset contains visibility, flags and material
This commit is contained in:
@@ -26,22 +26,12 @@
|
||||
// static int _count = 0;
|
||||
|
||||
ObjectBase::ObjectBase(Mesh * geom, Material * mat) {
|
||||
type_ = glMesh;
|
||||
prev_pass = rpSolid;
|
||||
parent_ = nullptr;
|
||||
color_ = Qt::white;
|
||||
is_root = is_init = selected_ = false;
|
||||
visible_ = accept_fog = accept_light = cast_shadow = rec_shadow = select_ = true;
|
||||
line_width = -1.;
|
||||
id_ = 0;
|
||||
blend_src = GL_SRC_ALPHA;
|
||||
blend_dest = GL_ONE_MINUS_SRC_ALPHA;
|
||||
type_ = glMesh;
|
||||
raw_matrix = selected_aim = false;
|
||||
blend_src = GL_SRC_ALPHA;
|
||||
blend_dest = GL_ONE_MINUS_SRC_ALPHA;
|
||||
mat_.setToIdentity();
|
||||
scene_ = nullptr;
|
||||
mesh_ = geom;
|
||||
material_ = mat;
|
||||
mesh_ = geom;
|
||||
setPreset(0);
|
||||
currentPreset().material = mat;
|
||||
// qDebug() << "ObjectBase, now" << ++_count;
|
||||
}
|
||||
|
||||
@@ -65,9 +55,8 @@ ObjectBase * ObjectBase::clone(bool withChildren) {
|
||||
ObjectBase * o = new ObjectBase();
|
||||
o->prev_pass = prev_pass;
|
||||
o->is_init = false;
|
||||
o->accept_light = accept_light;
|
||||
o->accept_fog = accept_fog;
|
||||
o->visible_ = visible_;
|
||||
o->presets = presets;
|
||||
o->cur_preset = cur_preset;
|
||||
o->color_ = color_;
|
||||
o->type_ = type_;
|
||||
o->raw_matrix = raw_matrix;
|
||||
@@ -80,7 +69,6 @@ ObjectBase * ObjectBase::clone(bool withChildren) {
|
||||
o->blend_src = blend_src;
|
||||
o->blend_dest = blend_dest;
|
||||
o->pos_h = pos_h;
|
||||
o->material_ = material_;
|
||||
o->mesh_ = mesh_;
|
||||
o->meta = meta;
|
||||
o->scene_ = nullptr;
|
||||
@@ -107,8 +95,8 @@ void ObjectBase::init() {
|
||||
|
||||
RenderPass ObjectBase::pass() const {
|
||||
RenderPass ret = rpSolid;
|
||||
if (material_)
|
||||
if (material_->hasTransparency()) ret = rpTransparent;
|
||||
if (currentPreset().material)
|
||||
if (currentPreset().material->hasTransparency()) ret = rpTransparent;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -206,11 +194,11 @@ ObjectBaseList ObjectBase::children(bool all_) {
|
||||
|
||||
|
||||
bool ObjectBase::isVisible(bool check_parents) const {
|
||||
if (!check_parents) return visible_;
|
||||
if (!visible_) return false;
|
||||
if (!check_parents) return currentPreset().visible;
|
||||
if (!currentPreset().visible) return false;
|
||||
ObjectBase * p = parent_;
|
||||
while (p) {
|
||||
if (!p->visible_) return false;
|
||||
if (!p->currentPreset().visible) return false;
|
||||
p = p->parent_;
|
||||
}
|
||||
return true;
|
||||
@@ -218,19 +206,116 @@ bool ObjectBase::isVisible(bool check_parents) const {
|
||||
|
||||
|
||||
void ObjectBase::setVisible(bool v) {
|
||||
visible_ = v;
|
||||
currentPreset().visible = v;
|
||||
setSceneTreeChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setReceiveShadows(bool on) {
|
||||
currentPreset().receive_shadow = on;
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setCastShadows(bool on) {
|
||||
cast_shadow = on;
|
||||
currentPreset().cast_shadow = on;
|
||||
if (type_ == glLight)
|
||||
((Light *)this)->apply();
|
||||
else
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
void ObjectBase::move(const QVector3D & dv) {
|
||||
trans.setTranslation(pos() + dv);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::moveTo(const QVector3D & dv) {
|
||||
trans.setTranslation(dv);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::move(GLfloat dx, GLfloat dy, GLfloat dz) {
|
||||
move(QVector3D(dx, dy, dz));
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::moveTo(GLfloat dx, GLfloat dy, GLfloat dz) {
|
||||
moveTo(QVector3D(dx, dy, dz));
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::moveX(GLfloat o) {
|
||||
trans.setTranslationX(posX() + o);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::moveY(GLfloat o) {
|
||||
trans.setTranslationY(posY() + o);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::moveZ(GLfloat o) {
|
||||
trans.setTranslationZ(posZ() + o);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setPosX(GLfloat o) {
|
||||
trans.setTranslationX(o);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setPosY(GLfloat o) {
|
||||
trans.setTranslationY(o);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setPosZ(GLfloat o) {
|
||||
trans.setTranslationZ(o);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setPos(GLfloat x, GLfloat y, GLfloat z) {
|
||||
trans.setTranslation(QVector3D(x, y, z));
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setPos(const QVector3D & p) {
|
||||
trans.setTranslation(p);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::resetPos() {
|
||||
trans.setTranslation(QVector3D());
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::rotateX(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationX(trans.rotationX() + a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::rotateY(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationY(trans.rotationY() + a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::rotateZ(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
@@ -242,6 +327,20 @@ void ObjectBase::rotateZ(GLfloat a) {
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setRotationX(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationX(a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setRotationY(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationY(a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setRotationZ(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationZ(a);
|
||||
@@ -252,6 +351,111 @@ void ObjectBase::setRotationZ(GLfloat a) {
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setRotation(const QVector3D & a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotation(a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::resetRotation() {
|
||||
raw_matrix = false;
|
||||
trans.setRotation(QVector3D());
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::scale(const QVector3D & sv) {
|
||||
raw_matrix = false;
|
||||
trans.setScale(trans.scale3D() * sv);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::scale(GLfloat sx, GLfloat sy, GLfloat sz) {
|
||||
raw_matrix = false;
|
||||
scale(QVector3D(sx, sy, sz));
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::scale(GLfloat sx, GLfloat sy) {
|
||||
raw_matrix = false;
|
||||
scale(QVector3D(sx, sy, sy));
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::scale(GLfloat sx) {
|
||||
raw_matrix = false;
|
||||
scale(QVector3D(sx, sx, sx));
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::scaleX(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleX(trans.scale3D().x() + a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::scaleY(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleY(trans.scale3D().y() + a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::scaleZ(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleZ(trans.scale3D().z() + a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setScale(const QVector3D & a) {
|
||||
raw_matrix = false;
|
||||
trans.setScale(a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setScale(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScale(a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setScaleX(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleX(a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setScaleY(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleY(a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setScaleZ(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleZ(a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::resetScale() {
|
||||
raw_matrix = false;
|
||||
trans.setScale(1.f);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setTransform(const Transform & t) {
|
||||
trans = t;
|
||||
buildTransform();
|
||||
@@ -308,6 +512,15 @@ void ObjectBase::removeProperty(const QString & pn) {
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setPreset(int preset) {
|
||||
if (preset < 0) preset = 0;
|
||||
if (presets.size() <= preset) presets.resize(preset + 1);
|
||||
cur_preset = preset;
|
||||
for (auto * c: children_)
|
||||
c->setPreset(preset);
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setMatrix(const QMatrix4x4 & t) {
|
||||
// raw_matrix = true;
|
||||
// mat_ = t;
|
||||
@@ -379,6 +592,18 @@ QGenericMatrix<3, 2, float> ObjectBase::textureGLMatrix() const {
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setAcceptLight(bool yes) {
|
||||
currentPreset().accept_light = yes;
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setAcceptFog(bool yes) {
|
||||
currentPreset().accept_fog = yes;
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
|
||||
bool ObjectBase::isSelected(bool check_parents) const {
|
||||
if (!check_parents) return selected_;
|
||||
if (selected_) return true;
|
||||
@@ -409,7 +634,7 @@ ObjectBase * ObjectBase::selectedParent() const {
|
||||
|
||||
|
||||
void ObjectBase::setMaterial(Material * m, bool with_children) {
|
||||
material_ = m;
|
||||
currentPreset().material = m;
|
||||
if (with_children)
|
||||
foreach(ObjectBase * i, children_)
|
||||
i->setMaterial(m, true);
|
||||
@@ -643,15 +868,24 @@ void Light::apply() {
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator<<(QDataStream & s, const ObjectBase::Preset & p) {
|
||||
ChunkStream cs;
|
||||
cs.add(1, p.visible).add(2, p.accept_light).add(3, p.accept_fog).add(4, p.cast_shadow).add(5, p.receive_shadow);
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
QDataStream & operator>>(QDataStream & s, ObjectBase::Preset & p) {
|
||||
ChunkStream cs(s);
|
||||
cs.readAll();
|
||||
cs.get(1, p.visible).get(2, p.accept_light).get(3, p.accept_fog).get(4, p.cast_shadow).get(5, p.receive_shadow);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator<<(QDataStream & s, const ObjectBase * p) {
|
||||
ChunkStream cs;
|
||||
// qDebug() << "place" << p->name() << "...";
|
||||
cs.add(1, int(p->type_))
|
||||
.add(2, p->accept_light)
|
||||
.add(3, p->accept_fog)
|
||||
.add(4, p->visible_)
|
||||
.add(5, p->cast_shadow)
|
||||
.add(6, p->rec_shadow)
|
||||
.add(7, p->raw_matrix)
|
||||
.add(8, p->line_width)
|
||||
.add(14, p->mat_)
|
||||
@@ -660,7 +894,8 @@ QDataStream & operator<<(QDataStream & s, const ObjectBase * p) {
|
||||
.add(18, p->meta)
|
||||
.add(19, p->color_)
|
||||
.add(20, p->trans)
|
||||
.add(21, p->trans_texture);
|
||||
.add(21, p->trans_texture)
|
||||
.add(22, p->presets);
|
||||
// qDebug() << "place self done";
|
||||
if (p->type_ == ObjectBase::glLight) {
|
||||
// qDebug() << "place light ...";
|
||||
@@ -721,19 +956,19 @@ QDataStream & operator>>(QDataStream & s, ObjectBase *& p) {
|
||||
if (p) p->type_ = type;
|
||||
} break;
|
||||
case 2:
|
||||
if (p) p->accept_light = cs.getData<bool>();
|
||||
if (p) p->currentPreset().accept_light = cs.getData<bool>();
|
||||
break;
|
||||
case 3:
|
||||
if (p) p->accept_fog = cs.getData<bool>();
|
||||
if (p) p->currentPreset().accept_fog = cs.getData<bool>();
|
||||
break;
|
||||
case 4:
|
||||
if (p) p->visible_ = cs.getData<bool>();
|
||||
if (p) p->currentPreset().visible = cs.getData<bool>();
|
||||
break;
|
||||
case 5:
|
||||
if (p) p->cast_shadow = cs.getData<bool>();
|
||||
if (p) p->currentPreset().cast_shadow = cs.getData<bool>();
|
||||
break;
|
||||
case 6:
|
||||
if (p) p->rec_shadow = cs.getData<bool>();
|
||||
if (p) p->currentPreset().receive_shadow = cs.getData<bool>();
|
||||
break;
|
||||
case 7:
|
||||
if (p) p->raw_matrix = cs.getData<bool>();
|
||||
@@ -762,6 +997,12 @@ QDataStream & operator>>(QDataStream & s, ObjectBase *& p) {
|
||||
case 21:
|
||||
if (p) p->trans_texture = cs.getData<Transform>();
|
||||
break;
|
||||
case 22:
|
||||
if (p) {
|
||||
p->presets = cs.getData<QVector<ObjectBase::Preset>>();
|
||||
if (p->presets.isEmpty()) p->presets.resize(1);
|
||||
}
|
||||
break;
|
||||
case 100:
|
||||
if (l) l->setAim(cs.getData<QVector3D>());
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user