mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 22:07:47 +02:00
more work on visible, registration point, and rotational velocity
This commit is contained in:
parent
fac7d20c8a
commit
53da483381
6 changed files with 149 additions and 102 deletions
|
@ -2909,6 +2909,9 @@ function handeMenuEvent(menuItem) {
|
|||
|
||||
array.push({ label: "Lifetime:", value: properties.lifetime.toFixed(decimals) });
|
||||
index++;
|
||||
|
||||
array.push({ label: "Visible:", value: properties.visible });
|
||||
index++;
|
||||
|
||||
if (properties.type == "Box" || properties.type == "Sphere") {
|
||||
array.push({ label: "Color:", type: "header" });
|
||||
|
@ -3038,7 +3041,8 @@ Window.nonBlockingFormClosed.connect(function() {
|
|||
properties.gravity.x = array[index++].value;
|
||||
properties.gravity.y = array[index++].value;
|
||||
properties.gravity.z = array[index++].value;
|
||||
properties.lifetime = array[index++].value; // give ourselves that many more seconds
|
||||
properties.lifetime = array[index++].value;
|
||||
properties.visible = array[index++].value;
|
||||
|
||||
if (properties.type == "Box" || properties.type == "Sphere") {
|
||||
index++; // skip header
|
||||
|
|
|
@ -214,27 +214,30 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args)
|
|||
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
EntityItem* entityItem = entityItems[i];
|
||||
// render entityItem
|
||||
AACube entityCube = entityItem->getAACube();
|
||||
|
||||
entityCube.scale(TREE_SCALE);
|
||||
|
||||
// TODO: some entity types (like lights) might want to be rendered even
|
||||
// when they are outside of the view frustum...
|
||||
float distance = distanceToCamera(entityCube.calcCenter(), *args->_viewFrustum);
|
||||
if (shouldRenderEntity(entityCube.getLargestDimension(), distance) &&
|
||||
args->_viewFrustum->cubeInFrustum(entityCube) != ViewFrustum::OUTSIDE) {
|
||||
if (entityItem->isVisible()) {
|
||||
// render entityItem
|
||||
AACube entityCube = entityItem->getAACube();
|
||||
|
||||
Glower* glower = NULL;
|
||||
if (entityItem->getGlowLevel() > 0.0f) {
|
||||
glower = new Glower(entityItem->getGlowLevel());
|
||||
entityCube.scale(TREE_SCALE);
|
||||
|
||||
// TODO: some entity types (like lights) might want to be rendered even
|
||||
// when they are outside of the view frustum...
|
||||
float distance = distanceToCamera(entityCube.calcCenter(), *args->_viewFrustum);
|
||||
if (shouldRenderEntity(entityCube.getLargestDimension(), distance) &&
|
||||
args->_viewFrustum->cubeInFrustum(entityCube) != ViewFrustum::OUTSIDE) {
|
||||
|
||||
Glower* glower = NULL;
|
||||
if (entityItem->getGlowLevel() > 0.0f) {
|
||||
glower = new Glower(entityItem->getGlowLevel());
|
||||
}
|
||||
entityItem->render(args);
|
||||
if (glower) {
|
||||
delete glower;
|
||||
}
|
||||
} else {
|
||||
args->_itemsOutOfView++;
|
||||
}
|
||||
entityItem->render(args);
|
||||
if (glower) {
|
||||
delete glower;
|
||||
}
|
||||
} else {
|
||||
args->_itemsOutOfView++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,9 @@ void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) {
|
|||
_gravity = DEFAULT_GRAVITY;
|
||||
_damping = DEFAULT_DAMPING;
|
||||
_lifetime = DEFAULT_LIFETIME;
|
||||
_registrationPoint = DEFAULT_REGISTRATION_POINT;
|
||||
_rotationalVelocity = DEFAULT_ROTATIONAL_VELOCITY;
|
||||
_visible = DEFAULT_VISIBLE;
|
||||
}
|
||||
|
||||
EntityItem::EntityItem(const EntityItemID& entityItemID) {
|
||||
|
@ -456,6 +459,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
|||
READ_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, glm::vec3, _registrationPoint);
|
||||
READ_ENTITY_PROPERTY_QUAT(PROP_ROTATIONAL_VELOCITY, _rotationalVelocity);
|
||||
READ_ENTITY_PROPERTY(PROP_VISIBLE, bool, _visible);
|
||||
qDebug() << "EntityItem::readEntityDataFromBuffer() ... _visible=" << _visible;
|
||||
|
||||
bytesRead += readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, propertyFlags, overwriteLocalData);
|
||||
|
||||
|
@ -617,25 +621,19 @@ EntityItemProperties EntityItem::getProperties() const {
|
|||
|
||||
properties._type = getType();
|
||||
|
||||
properties._position = getPosition() * (float) TREE_SCALE;
|
||||
properties.setDimensions(getDimensions() * (float) TREE_SCALE);
|
||||
properties._rotation = getRotation();
|
||||
|
||||
properties._mass = getMass();
|
||||
properties._velocity = getVelocity() * (float) TREE_SCALE;
|
||||
properties._gravity = getGravity() * (float) TREE_SCALE;
|
||||
properties._damping = getDamping();
|
||||
properties._lifetime = getLifetime();
|
||||
properties._script = getScript();
|
||||
|
||||
properties._positionChanged = false;
|
||||
properties._rotationChanged = false;
|
||||
properties._massChanged = false;
|
||||
properties._velocityChanged = false;
|
||||
properties._gravityChanged = false;
|
||||
properties._dampingChanged = false;
|
||||
properties._lifetimeChanged = false;
|
||||
properties._scriptChanged = false;
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(position, getPositionInMeters);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(dimensions, getDimensionsInMeters); // NOTE: radius is obsolete
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(rotation, getRotation);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(mass, getMass);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(velocity, getVelocityInMeters);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(gravity, getGravityInMeters);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(damping, getDamping);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(lifetime, getLifetime);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(script, getScript);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(registrationPoint, getRegistrationPoint);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(rotationalVelocity, getRotationalVelocity);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(glowLevel, getGlowLevel);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(visible, getVisible);
|
||||
|
||||
properties._defaultSettings = false;
|
||||
|
||||
|
@ -666,6 +664,7 @@ bool EntityItem::setProperties(const EntityItemProperties& properties, bool forc
|
|||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(registrationPoint, setRegistrationPoint);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(rotationalVelocity, setRotationalVelocity);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(glowLevel, setGlowLevel);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(visible, setVisible);
|
||||
|
||||
if (somethingChanged) {
|
||||
somethingChangedNotification(); // notify derived classes that something has changed
|
||||
|
|
|
@ -121,12 +121,14 @@ public:
|
|||
// attributes applicable to all entity types
|
||||
EntityTypes::EntityType getType() const { return _type; }
|
||||
const glm::vec3& getPosition() const { return _position; } /// get position in domain scale units (0.0 - 1.0)
|
||||
glm::vec3 getPositionInMeters() const { return _position * (float) TREE_SCALE; } /// get position in meters
|
||||
void setPosition(const glm::vec3& value) { _position = value; } /// set position in domain scale units (0.0 - 1.0)
|
||||
void setPositionInMeters(const glm::vec3& value) /// set position in meter units (0.0 - TREE_SCALE)
|
||||
{ setPosition(glm::clamp(value / (float) TREE_SCALE, 0.0f, 1.0f)); }
|
||||
|
||||
static const glm::vec3 DEFAULT_DIMENSIONS;
|
||||
const glm::vec3& getDimensions() const { return _dimensions; } /// get dimensions in domain scale units (0.0 - 1.0)
|
||||
glm::vec3 getDimensionsInMeters() const { return _dimensions * (float) TREE_SCALE; } /// get dimensions in meters
|
||||
float getDistanceToBottomOfEntity() const; /// get the distance from the position of the entity to its "bottom" in y axis
|
||||
float getLargestDimension() const { return glm::length(_dimensions); } /// get the largest possible dimension
|
||||
|
||||
|
@ -151,7 +153,8 @@ public:
|
|||
static const glm::vec3 DEFAULT_VELOCITY;
|
||||
static const glm::vec3 NO_VELOCITY;
|
||||
static const float EPSILON_VELOCITY_LENGTH;
|
||||
const glm::vec3& getVelocity() const { return _velocity; } /// velocity in domain scale units (0.0-1.0) per second
|
||||
const glm::vec3 getVelocity() const { return _velocity; } /// velocity in domain scale units (0.0-1.0) per second
|
||||
glm::vec3 getVelocityInMeters() const { return _velocity * (float) TREE_SCALE; } /// get velocity in meters
|
||||
void setVelocity(const glm::vec3& value) { _velocity = value; } /// velocity in domain scale units (0.0-1.0) per second
|
||||
bool hasVelocity() const { return _velocity != NO_VELOCITY; }
|
||||
|
||||
|
@ -159,6 +162,7 @@ public:
|
|||
static const glm::vec3 REGULAR_GRAVITY;
|
||||
static const glm::vec3 NO_GRAVITY;
|
||||
const glm::vec3& getGravity() const { return _gravity; } /// gravity in domain scale units (0.0-1.0) per second squared
|
||||
glm::vec3 getGravityInMeters() const { return _gravity * (float) TREE_SCALE; } /// get gravity in meters
|
||||
void setGravity(const glm::vec3& value) { _gravity = value; } /// gravity in domain scale units (0.0-1.0) per second squared
|
||||
bool hasGravity() const { return _gravity != NO_GRAVITY; }
|
||||
|
||||
|
@ -206,6 +210,8 @@ public:
|
|||
static const bool DEFAULT_VISIBLE;
|
||||
bool getVisible() const { return _visible; }
|
||||
void setVisible(bool value) { _visible = value; }
|
||||
bool isVisible() const { return _visible; }
|
||||
bool isInvisible() const { return !_visible; }
|
||||
|
||||
protected:
|
||||
virtual void initFromEntityItemID(const EntityItemID& entityItemID); // maybe useful to allow subclasses to init
|
||||
|
|
|
@ -90,65 +90,25 @@ void EntityItemProperties::debugDump() const {
|
|||
|
||||
EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
|
||||
EntityPropertyFlags changedProperties;
|
||||
if (_dimensionsChanged) {
|
||||
changedProperties += PROP_DIMENSIONS;
|
||||
}
|
||||
|
||||
if (_positionChanged) {
|
||||
changedProperties += PROP_POSITION;
|
||||
}
|
||||
|
||||
if (_rotationChanged) {
|
||||
changedProperties += PROP_ROTATION;
|
||||
}
|
||||
|
||||
if (_massChanged) {
|
||||
changedProperties += PROP_MASS;
|
||||
}
|
||||
|
||||
if (_velocityChanged) {
|
||||
changedProperties += PROP_VELOCITY;
|
||||
}
|
||||
|
||||
if (_gravityChanged) {
|
||||
changedProperties += PROP_GRAVITY;
|
||||
}
|
||||
|
||||
if (_dampingChanged) {
|
||||
changedProperties += PROP_DAMPING;
|
||||
}
|
||||
|
||||
if (_lifetimeChanged) {
|
||||
changedProperties += PROP_LIFETIME;
|
||||
}
|
||||
|
||||
if (_scriptChanged) {
|
||||
changedProperties += PROP_SCRIPT;
|
||||
}
|
||||
|
||||
if (_colorChanged) {
|
||||
changedProperties += PROP_COLOR;
|
||||
}
|
||||
|
||||
if (_modelURLChanged) {
|
||||
changedProperties += PROP_MODEL_URL;
|
||||
}
|
||||
|
||||
if (_animationURLChanged) {
|
||||
changedProperties += PROP_ANIMATION_URL;
|
||||
}
|
||||
|
||||
if (_animationIsPlayingChanged) {
|
||||
changedProperties += PROP_ANIMATION_PLAYING;
|
||||
}
|
||||
|
||||
if (_animationFrameIndexChanged) {
|
||||
changedProperties += PROP_ANIMATION_FRAME_INDEX;
|
||||
}
|
||||
|
||||
if (_animationFPSChanged) {
|
||||
changedProperties += PROP_ANIMATION_FPS;
|
||||
}
|
||||
|
||||
CHECK_PROPERTY_CHANGE(PROP_DIMENSIONS, dimensions);
|
||||
CHECK_PROPERTY_CHANGE(PROP_POSITION, position);
|
||||
CHECK_PROPERTY_CHANGE(PROP_ROTATION, rotation);
|
||||
CHECK_PROPERTY_CHANGE(PROP_MASS, mass);
|
||||
CHECK_PROPERTY_CHANGE(PROP_VELOCITY, velocity);
|
||||
CHECK_PROPERTY_CHANGE(PROP_GRAVITY, gravity);
|
||||
CHECK_PROPERTY_CHANGE(PROP_DAMPING, damping);
|
||||
CHECK_PROPERTY_CHANGE(PROP_LIFETIME, lifetime);
|
||||
CHECK_PROPERTY_CHANGE(PROP_SCRIPT, script);
|
||||
CHECK_PROPERTY_CHANGE(PROP_COLOR, color);
|
||||
CHECK_PROPERTY_CHANGE(PROP_MODEL_URL, modelURL);
|
||||
CHECK_PROPERTY_CHANGE(PROP_ANIMATION_URL, animationURL);
|
||||
CHECK_PROPERTY_CHANGE(PROP_ANIMATION_PLAYING, animationIsPlaying);
|
||||
CHECK_PROPERTY_CHANGE(PROP_ANIMATION_FRAME_INDEX, animationFrameIndex);
|
||||
CHECK_PROPERTY_CHANGE(PROP_ANIMATION_FPS, animationFPS);
|
||||
CHECK_PROPERTY_CHANGE(PROP_VISIBLE, visible);
|
||||
CHECK_PROPERTY_CHANGE(PROP_REGISTRATION_POINT, registrationPoint);
|
||||
CHECK_PROPERTY_CHANGE(PROP_ROTATIONAL_VELOCITY, rotationalVelocity);
|
||||
|
||||
return changedProperties;
|
||||
}
|
||||
|
@ -185,6 +145,14 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
|
|||
properties.setProperty("ageAsText", formatSecondsElapsed(getAge())); // gettable, but not settable
|
||||
properties.setProperty("script", _script);
|
||||
|
||||
QScriptValue registrationPoint = vec3toScriptValue(engine, _registrationPoint);
|
||||
properties.setProperty("registrationPoint", registrationPoint);
|
||||
|
||||
QScriptValue rotationalVelocity = quatToScriptValue(engine, _rotationalVelocity);
|
||||
properties.setProperty("rotationalVelocity", rotationalVelocity);
|
||||
|
||||
properties.setProperty("visible", _visible);
|
||||
|
||||
QScriptValue color = xColorToScriptValue(engine, _color);
|
||||
properties.setProperty("color", color);
|
||||
properties.setProperty("modelURL", _modelURL);
|
||||
|
@ -343,6 +311,52 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue registrationPoint = object.property("registrationPoint");
|
||||
if (registrationPoint.isValid()) {
|
||||
QScriptValue x = registrationPoint.property("x");
|
||||
QScriptValue y = registrationPoint.property("y");
|
||||
QScriptValue z = registrationPoint.property("z");
|
||||
if (x.isValid() && y.isValid() && z.isValid()) {
|
||||
glm::vec3 newValue;
|
||||
newValue.x = x.toVariant().toFloat();
|
||||
newValue.y = y.toVariant().toFloat();
|
||||
newValue.z = z.toVariant().toFloat();
|
||||
if (_defaultSettings || newValue != _registrationPoint) {
|
||||
_registrationPoint = newValue;
|
||||
_registrationPointChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue rotationalVelocity = object.property("rotationalVelocity");
|
||||
if (rotationalVelocity.isValid()) {
|
||||
QScriptValue x = rotationalVelocity.property("x");
|
||||
QScriptValue y = rotationalVelocity.property("y");
|
||||
QScriptValue z = rotationalVelocity.property("z");
|
||||
QScriptValue w = rotationalVelocity.property("w");
|
||||
if (x.isValid() && y.isValid() && z.isValid() && w.isValid()) {
|
||||
glm::quat newRotation;
|
||||
newRotation.x = x.toVariant().toFloat();
|
||||
newRotation.y = y.toVariant().toFloat();
|
||||
newRotation.z = z.toVariant().toFloat();
|
||||
newRotation.w = w.toVariant().toFloat();
|
||||
if (_defaultSettings || newRotation != _rotationalVelocity) {
|
||||
_rotationalVelocity = newRotation;
|
||||
_rotationalVelocityChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue visible = object.property("visible");
|
||||
if (visible.isValid()) {
|
||||
bool newValue;
|
||||
newValue = visible.toVariant().toBool();
|
||||
if (_defaultSettings || newValue != _visible) {
|
||||
_visible = newValue;
|
||||
_visibleChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue color = object.property("color");
|
||||
if (color.isValid()) {
|
||||
QScriptValue red = color.property("red");
|
||||
|
@ -548,7 +562,6 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
|
|||
// These items would go here once supported....
|
||||
// PROP_PAGED_PROPERTY,
|
||||
// PROP_CUSTOM_PROPERTIES_INCLUDED,
|
||||
// PROP_VISIBLE,
|
||||
|
||||
APPEND_ENTITY_PROPERTY(PROP_POSITION, appendPosition, properties.getPosition());
|
||||
APPEND_ENTITY_PROPERTY(PROP_DIMENSIONS, appendValue, properties.getDimensions()); // NOTE: PROP_RADIUS obsolete
|
||||
|
@ -565,6 +578,9 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
|
|||
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FPS, appendValue, properties.getAnimationFPS());
|
||||
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_FRAME_INDEX, appendValue, properties.getAnimationFrameIndex());
|
||||
APPEND_ENTITY_PROPERTY(PROP_ANIMATION_PLAYING, appendValue, properties.getAnimationIsPlaying());
|
||||
APPEND_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, appendValue, properties.getRegistrationPoint());
|
||||
APPEND_ENTITY_PROPERTY(PROP_ROTATIONAL_VELOCITY, appendValue, properties.getRotationalVelocity());
|
||||
APPEND_ENTITY_PROPERTY(PROP_VISIBLE, appendValue, properties.getVisible());
|
||||
}
|
||||
if (propertyCount > 0) {
|
||||
int endOfEntityItemData = packetData->getUncompressedByteOffset();
|
||||
|
@ -757,9 +773,9 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
|
|||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ANIMATION_FPS, float, setAnimationFPS);
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ANIMATION_FRAME_INDEX, float, setAnimationFrameIndex);
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ANIMATION_PLAYING, bool, setAnimationIsPlaying);
|
||||
// TODO: add PROP_REGISTRATION_POINT,
|
||||
// TODO: add PROP_ROTATIONAL_VELOCITY,
|
||||
// TODO: add PROP_VISIBLE,
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_REGISTRATION_POINT, glm::vec3, setRegistrationPoint);
|
||||
READ_ENTITY_PROPERTY_QUAT_TO_PROPERTIES(PROP_ROTATIONAL_VELOCITY, setRotationalVelocity);
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VISIBLE, bool, setVisible);
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
|
|
@ -215,6 +215,17 @@ public:
|
|||
const glm::vec3& getNaturalDimensions() const { return _naturalDimensions; }
|
||||
void setNaturalDimensions(const glm::vec3& value) { _naturalDimensions = value; }
|
||||
|
||||
const glm::vec3& getRegistrationPoint() const { return _registrationPoint; }
|
||||
void setRegistrationPoint(const glm::vec3& value) { _registrationPoint = value; _registrationPointChanged = true; }
|
||||
|
||||
const glm::quat& getRotationalVelocity() const { return _rotationalVelocity; }
|
||||
void setRotationalVelocity(const glm::quat& value) { _rotationalVelocity = value; _rotationalVelocityChanged = true; }
|
||||
|
||||
bool getVisible() const { return _visible; }
|
||||
void setVisible(bool value) { _visible = value; _visibleChanged = true; }
|
||||
|
||||
|
||||
|
||||
private:
|
||||
void setLastEdited(quint64 usecTime) { _lastEdited = usecTime; }
|
||||
|
||||
|
@ -389,5 +400,13 @@ void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemP
|
|||
somethingChanged = true; \
|
||||
}
|
||||
|
||||
#define COPY_ENTITY_PROPERTY_TO_PROPERTIES(M,G) \
|
||||
properties._##M = G(); \
|
||||
properties._##M##Changed = false;
|
||||
|
||||
#define CHECK_PROPERTY_CHANGE(P,M) \
|
||||
if (_##M##Changed) { \
|
||||
changedProperties += P; \
|
||||
}
|
||||
|
||||
#endif // hifi_EntityItemProperties_h
|
||||
|
|
Loading…
Reference in a new issue