multimaterial support, "preset"
each preset contains visibility, flags and material
This commit is contained in:
@@ -30,6 +30,7 @@ class QGLENGINE_CORE_EXPORT ObjectBase {
|
||||
friend class RendererSelection;
|
||||
friend QGLENGINE_CORE_EXPORT QDataStream & operator<<(QDataStream & s, const ObjectBase * p);
|
||||
friend QGLENGINE_CORE_EXPORT QDataStream & operator>>(QDataStream & s, ObjectBase *& p);
|
||||
friend QGLENGINE_CORE_EXPORT QDataStream & operator<<(QDataStream & s, const Scene * p);
|
||||
friend QGLENGINE_CORE_EXPORT QDataStream & operator>>(QDataStream & s, Scene *& p);
|
||||
|
||||
public:
|
||||
@@ -40,7 +41,7 @@ public:
|
||||
glParticlesSystem
|
||||
};
|
||||
|
||||
explicit ObjectBase(Mesh * geom = 0, Material * mat = 0);
|
||||
explicit ObjectBase(Mesh * geom = nullptr, Material * mat = nullptr);
|
||||
virtual ~ObjectBase();
|
||||
|
||||
virtual ObjectBase * clone(bool withChildren = true);
|
||||
@@ -82,66 +83,24 @@ public:
|
||||
void show() { setVisible(true); }
|
||||
void hide() { setVisible(false); }
|
||||
|
||||
bool isReceiveShadows() const { return rec_shadow; }
|
||||
bool isCastShadows() const { return cast_shadow; }
|
||||
void setReceiveShadows(bool on) {
|
||||
rec_shadow = on;
|
||||
setObjectsChanged();
|
||||
}
|
||||
bool isReceiveShadows() const { return currentPreset().receive_shadow; }
|
||||
bool isCastShadows() const { return currentPreset().cast_shadow; }
|
||||
void setReceiveShadows(bool on);
|
||||
void setCastShadows(bool on);
|
||||
|
||||
void move(const QVector3D & dv) {
|
||||
trans.setTranslation(pos() + dv);
|
||||
buildTransform();
|
||||
}
|
||||
void moveTo(const QVector3D & dv) {
|
||||
trans.setTranslation(dv);
|
||||
buildTransform();
|
||||
}
|
||||
void move(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {
|
||||
move(QVector3D(dx, dy, dz));
|
||||
buildTransform();
|
||||
}
|
||||
void moveTo(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {
|
||||
moveTo(QVector3D(dx, dy, dz));
|
||||
buildTransform();
|
||||
}
|
||||
void moveX(GLfloat o) {
|
||||
trans.setTranslationX(posX() + o);
|
||||
buildTransform();
|
||||
}
|
||||
void moveY(GLfloat o) {
|
||||
trans.setTranslationY(posY() + o);
|
||||
buildTransform();
|
||||
}
|
||||
void moveZ(GLfloat o) {
|
||||
trans.setTranslationZ(posZ() + o);
|
||||
buildTransform();
|
||||
}
|
||||
void setPosX(GLfloat o) {
|
||||
trans.setTranslationX(o);
|
||||
buildTransform();
|
||||
}
|
||||
void setPosY(GLfloat o) {
|
||||
trans.setTranslationY(o);
|
||||
buildTransform();
|
||||
}
|
||||
void setPosZ(GLfloat o) {
|
||||
trans.setTranslationZ(o);
|
||||
buildTransform();
|
||||
}
|
||||
void setPos(GLfloat x, GLfloat y, GLfloat z) {
|
||||
trans.setTranslation(QVector3D(x, y, z));
|
||||
buildTransform();
|
||||
}
|
||||
void setPos(const QVector3D & p) {
|
||||
trans.setTranslation(p);
|
||||
buildTransform();
|
||||
}
|
||||
void resetPos() {
|
||||
trans.setTranslation(QVector3D());
|
||||
buildTransform();
|
||||
}
|
||||
void move(const QVector3D & dv);
|
||||
void moveTo(const QVector3D & dv);
|
||||
void move(GLfloat dx, GLfloat dy, GLfloat dz = 0.);
|
||||
void moveTo(GLfloat dx, GLfloat dy, GLfloat dz = 0.);
|
||||
void moveX(GLfloat o);
|
||||
void moveY(GLfloat o);
|
||||
void moveZ(GLfloat o);
|
||||
void setPosX(GLfloat o);
|
||||
void setPosY(GLfloat o);
|
||||
void setPosZ(GLfloat o);
|
||||
void setPos(GLfloat x, GLfloat y, GLfloat z);
|
||||
void setPos(const QVector3D & p);
|
||||
void resetPos();
|
||||
|
||||
QVector3D pos() const { return trans.translation(); }
|
||||
float posX() const { return trans.translation().x(); }
|
||||
@@ -154,108 +113,32 @@ public:
|
||||
float rotationX() const { return rotation().x(); }
|
||||
float rotationY() const { return rotation().y(); }
|
||||
float rotationZ() const { return rotation().z(); }
|
||||
void rotateX(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationX(trans.rotationX() + a);
|
||||
buildTransform();
|
||||
}
|
||||
void rotateY(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationY(trans.rotationY() + a);
|
||||
buildTransform();
|
||||
}
|
||||
void rotateX(GLfloat a);
|
||||
void rotateY(GLfloat a);
|
||||
void rotateZ(GLfloat a);
|
||||
void setRotationX(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationX(a);
|
||||
buildTransform();
|
||||
}
|
||||
void setRotationY(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationY(a);
|
||||
buildTransform();
|
||||
}
|
||||
void setRotationX(GLfloat a);
|
||||
void setRotationY(GLfloat a);
|
||||
void setRotationZ(GLfloat a);
|
||||
void setRotation(const QVector3D & a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotation(a);
|
||||
buildTransform();
|
||||
}
|
||||
void resetRotation() {
|
||||
raw_matrix = false;
|
||||
trans.setRotation(QVector3D());
|
||||
buildTransform();
|
||||
}
|
||||
void setRotation(const QVector3D & a);
|
||||
void resetRotation();
|
||||
|
||||
QVector3D scale() { return trans.scale3D(); }
|
||||
float scaleX() { return trans.scale3D().x(); }
|
||||
float scaleY() { return trans.scale3D().y(); }
|
||||
float scaleZ() { return trans.scale3D().z(); }
|
||||
void scale(const QVector3D & sv) {
|
||||
raw_matrix = false;
|
||||
trans.setScale(trans.scale3D() * sv);
|
||||
buildTransform();
|
||||
}
|
||||
void scale(GLfloat sx, GLfloat sy, GLfloat sz) {
|
||||
raw_matrix = false;
|
||||
scale(QVector3D(sx, sy, sz));
|
||||
buildTransform();
|
||||
}
|
||||
void scale(GLfloat sx, GLfloat sy) {
|
||||
raw_matrix = false;
|
||||
scale(QVector3D(sx, sy, sy));
|
||||
buildTransform();
|
||||
}
|
||||
void scale(GLfloat sx) {
|
||||
raw_matrix = false;
|
||||
scale(QVector3D(sx, sx, sx));
|
||||
buildTransform();
|
||||
}
|
||||
void scaleX(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleX(trans.scale3D().x() + a);
|
||||
buildTransform();
|
||||
}
|
||||
void scaleY(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleY(trans.scale3D().y() + a);
|
||||
buildTransform();
|
||||
}
|
||||
void scaleZ(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleZ(trans.scale3D().z() + a);
|
||||
buildTransform();
|
||||
}
|
||||
void setScale(const QVector3D & a) {
|
||||
raw_matrix = false;
|
||||
trans.setScale(a);
|
||||
buildTransform();
|
||||
}
|
||||
void setScale(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScale(a);
|
||||
buildTransform();
|
||||
}
|
||||
void setScaleX(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleX(a);
|
||||
buildTransform();
|
||||
}
|
||||
void setScaleY(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleY(a);
|
||||
buildTransform();
|
||||
}
|
||||
void setScaleZ(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setScaleZ(a);
|
||||
buildTransform();
|
||||
}
|
||||
void resetScale() {
|
||||
raw_matrix = false;
|
||||
trans.setScale(1.f);
|
||||
buildTransform();
|
||||
}
|
||||
void scale(const QVector3D & sv);
|
||||
void scale(GLfloat sx, GLfloat sy, GLfloat sz);
|
||||
void scale(GLfloat sx, GLfloat sy);
|
||||
void scale(GLfloat sx);
|
||||
void scaleX(GLfloat a);
|
||||
void scaleY(GLfloat a);
|
||||
void scaleZ(GLfloat a);
|
||||
void setScale(const QVector3D & a);
|
||||
void setScale(GLfloat a);
|
||||
void setScaleX(GLfloat a);
|
||||
void setScaleY(GLfloat a);
|
||||
void setScaleZ(GLfloat a);
|
||||
void resetScale();
|
||||
|
||||
Transform transform() { return trans; }
|
||||
void setTransform(const Transform & t);
|
||||
@@ -273,17 +156,11 @@ public:
|
||||
QMatrix4x4 textureMatrix() const;
|
||||
QGenericMatrix<3, 2, float> textureGLMatrix() const;
|
||||
|
||||
bool isAcceptLight() const { return accept_light; }
|
||||
void setAcceptLight(bool yes) {
|
||||
accept_light = yes;
|
||||
setObjectsChanged();
|
||||
}
|
||||
bool isAcceptLight() const { return currentPreset().accept_light; }
|
||||
void setAcceptLight(bool yes);
|
||||
|
||||
bool isAcceptFog() const { return accept_fog; }
|
||||
void setAcceptFog(bool yes) {
|
||||
accept_fog = yes;
|
||||
setObjectsChanged();
|
||||
}
|
||||
bool isAcceptFog() const { return currentPreset().accept_fog; }
|
||||
void setAcceptFog(bool yes);
|
||||
|
||||
bool isSelected(bool check_parents = false) const;
|
||||
void setSelected(bool yes);
|
||||
@@ -302,7 +179,7 @@ public:
|
||||
void setDestAlpha(GLenum mode) { blend_dest = mode; }
|
||||
|
||||
void setMaterial(Material * m, bool with_children = false);
|
||||
Material * material() { return material_; }
|
||||
Material * material() { return currentPreset().material; }
|
||||
|
||||
void setColor(QColor c, bool with_children = false);
|
||||
QColor color() { return color_; }
|
||||
@@ -319,9 +196,22 @@ public:
|
||||
bool hasProperty(const QString & pn) const;
|
||||
void removeProperty(const QString & pn);
|
||||
|
||||
void setPreset(int preset);
|
||||
|
||||
QVector3D pos_h;
|
||||
|
||||
protected:
|
||||
struct Preset {
|
||||
bool visible = true;
|
||||
bool accept_light = true;
|
||||
bool accept_fog = true;
|
||||
bool cast_shadow = true;
|
||||
bool receive_shadow = true;
|
||||
Material * material = nullptr;
|
||||
};
|
||||
friend QGLENGINE_CORE_EXPORT QDataStream & operator<<(QDataStream & s, const ObjectBase::Preset & p);
|
||||
friend QGLENGINE_CORE_EXPORT QDataStream & operator>>(QDataStream & s, ObjectBase::Preset & p);
|
||||
|
||||
virtual void transformChanged() {}
|
||||
void addChildren(ObjectBaseList & list, ObjectBase * where);
|
||||
void buildTransform(bool force = false);
|
||||
@@ -330,24 +220,27 @@ protected:
|
||||
void setObjectsChanged();
|
||||
void localTransform(QMatrix4x4 & m);
|
||||
QMatrix4x4 worldMatrix(QMatrix4x4 parent) const;
|
||||
const Preset & currentPreset() const { return presets[cur_preset]; }
|
||||
Preset & currentPreset() { return presets[cur_preset]; }
|
||||
|
||||
int prev_pass; // Pass
|
||||
bool is_init, accept_light, accept_fog, visible_, cast_shadow, rec_shadow, select_, selected_, raw_matrix;
|
||||
bool is_root, selected_aim;
|
||||
float line_width;
|
||||
QColor color_;
|
||||
uint id_;
|
||||
Type type_;
|
||||
int prev_pass = rpSolid; // Pass
|
||||
int cur_preset = 0;
|
||||
bool is_init = false, select_ = true, selected_ = false, raw_matrix = false;
|
||||
bool is_root = false, selected_aim = false;
|
||||
float line_width = -1.f;
|
||||
QVector<Preset> presets;
|
||||
QColor color_ = Qt::white;
|
||||
uint id_ = 0;
|
||||
Type type_ = glMesh;
|
||||
Box3D bound;
|
||||
Transform trans, trans_texture;
|
||||
ObjectBaseList children_;
|
||||
QMatrix4x4 itransform_, mat_;
|
||||
QString name_;
|
||||
GLenum blend_src, blend_dest;
|
||||
ObjectBase * parent_;
|
||||
Scene * scene_;
|
||||
Material * material_;
|
||||
Mesh * mesh_;
|
||||
ObjectBase * parent_ = nullptr;
|
||||
Scene * scene_ = nullptr;
|
||||
Mesh * mesh_ = nullptr;
|
||||
QVariantMap meta;
|
||||
};
|
||||
|
||||
@@ -441,6 +334,8 @@ inline T globject_cast(const ObjectBase * object) {
|
||||
}
|
||||
|
||||
|
||||
QGLENGINE_CORE_EXPORT QDataStream & operator<<(QDataStream & s, const ObjectBase::Preset & p);
|
||||
QGLENGINE_CORE_EXPORT QDataStream & operator>>(QDataStream & s, ObjectBase::Preset & p);
|
||||
QGLENGINE_CORE_EXPORT QDataStream & operator<<(QDataStream & s, const ObjectBase * p);
|
||||
QGLENGINE_CORE_EXPORT QDataStream & operator>>(QDataStream & s, ObjectBase *& p);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user