From 62c64479c28841ab6cf241f5d261111544c648a2 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 15:58:12 -0800 Subject: [PATCH 01/13] first cut at text entity --- interface/src/entities/EntityTreeRenderer.cpp | 2 + interface/src/entities/EntityTreeRenderer.h | 3 +- .../src/entities/RenderableTextEntityItem.cpp | 113 ++++++++++++++++++ .../src/entities/RenderableTextEntityItem.h | 44 +++++++ .../entities/src/EntityItemProperties.cpp | 113 +++++++++++++----- libraries/entities/src/EntityItemProperties.h | 16 ++- .../entities/src/EntityItemPropertiesMacros.h | 20 ++++ libraries/entities/src/EntityTypes.cpp | 2 + libraries/entities/src/EntityTypes.h | 3 +- libraries/entities/src/TextEntityItem.cpp | 113 ++++++++++++++++++ libraries/entities/src/TextEntityItem.h | 81 +++++++++++++ 11 files changed, 475 insertions(+), 35 deletions(-) create mode 100644 interface/src/entities/RenderableTextEntityItem.cpp create mode 100644 interface/src/entities/RenderableTextEntityItem.h create mode 100644 libraries/entities/src/TextEntityItem.cpp create mode 100644 libraries/entities/src/TextEntityItem.h diff --git a/interface/src/entities/EntityTreeRenderer.cpp b/interface/src/entities/EntityTreeRenderer.cpp index 2209a992c1..2b657979f4 100644 --- a/interface/src/entities/EntityTreeRenderer.cpp +++ b/interface/src/entities/EntityTreeRenderer.cpp @@ -34,6 +34,7 @@ #include "RenderableLightEntityItem.h" #include "RenderableModelEntityItem.h" #include "RenderableSphereEntityItem.h" +#include "RenderableTextEntityItem.h" QThread* EntityTreeRenderer::getMainThread() { @@ -50,6 +51,7 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts) : REGISTER_ENTITY_TYPE_WITH_FACTORY(Box, RenderableBoxEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Sphere, RenderableSphereEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Light, RenderableLightEntityItem::factory) + REGISTER_ENTITY_TYPE_WITH_FACTORY(Text, RenderableTextEntityItem::factory) _currentHoverOverEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID _currentClickingOnEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID diff --git a/interface/src/entities/EntityTreeRenderer.h b/interface/src/entities/EntityTreeRenderer.h index 66107b368a..c94eb78b77 100644 --- a/interface/src/entities/EntityTreeRenderer.h +++ b/interface/src/entities/EntityTreeRenderer.h @@ -56,7 +56,8 @@ public: void processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode); virtual void init(); - virtual void render(RenderArgs::RenderMode renderMode = RenderArgs::DEFAULT_RENDER_MODE, RenderArgs::RenderSide renderSide = RenderArgs::MONO); + virtual void render(RenderArgs::RenderMode renderMode = RenderArgs::DEFAULT_RENDER_MODE, + RenderArgs::RenderSide renderSide = RenderArgs::MONO); virtual const FBXGeometry* getGeometryForEntity(const EntityItem* entityItem); virtual const Model* getModelForEntityItem(const EntityItem* entityItem); diff --git a/interface/src/entities/RenderableTextEntityItem.cpp b/interface/src/entities/RenderableTextEntityItem.cpp new file mode 100644 index 0000000000..601cbb347a --- /dev/null +++ b/interface/src/entities/RenderableTextEntityItem.cpp @@ -0,0 +1,113 @@ +// +// RenderableTextEntityItem.cpp +// interface/src +// +// Created by Brad Hefta-Gaub on 8/6/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include "InterfaceConfig.h" + +#include +#include + +#include "Menu.h" +#include "EntityTreeRenderer.h" +#include "RenderableTextEntityItem.h" + +const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 }; +const float DEFAULT_MARGIN = 0.1f; +const int FIXED_FONT_POINT_SIZE = 40; +const float LINE_SCALE_RATIO = 1.2f; + +EntityItem* RenderableTextEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { + return new RenderableTextEntityItem(entityID, properties); +} + +void RenderableTextEntityItem::render(RenderArgs* args) { + PerformanceTimer perfTimer("RenderableTextEntityItem::render"); + assert(getType() == EntityTypes::Text); + glm::vec3 position = getPositionInMeters(); + glm::vec3 center = getCenter() * (float)TREE_SCALE; + glm::vec3 dimensions = getDimensions() * (float)TREE_SCALE; + glm::vec3 halfDimensions = dimensions / 2.0f; + glm::quat rotation = getRotation(); + float leftMargin = 0.1f; + float rightMargin = 0.1f; + float topMargin = 0.1f; + float bottomMargin = 0.1f; + + //qDebug() << "RenderableTextEntityItem::render() id:" << getEntityItemID() << "text:" << getText(); + + glPushMatrix(); + { + glTranslatef(position.x, position.y, position.z); + glm::vec3 axis = glm::axis(rotation); + glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); + + const float MAX_COLOR = 255.0f; + xColor backgroundColor = { 255, 0, 0 }; //getBackgroundColorX(); + float alpha = 1.0f; //getBackgroundAlpha(); + glColor4f(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, alpha); + + const float SLIGHTLY_BEHIND = -0.005f; + + glBegin(GL_QUADS); + glVertex3f(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); + glVertex3f(halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); + glVertex3f(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); + glVertex3f(-halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); + glEnd(); + + const int FIXED_FONT_SCALING_RATIO = FIXED_FONT_POINT_SIZE * 40.0f; // this is a ratio determined through experimentation + + // Same font properties as textWidth() + TextRenderer* textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE); + float maxHeight = (float)textRenderer->calculateHeight("Xy") * LINE_SCALE_RATIO; + + float scaleFactor = (maxHeight / FIXED_FONT_SCALING_RATIO) * _lineHeight; + + glTranslatef(-(halfDimensions.x - leftMargin), halfDimensions.y - topMargin, 0.0f); + + glm::vec2 clipMinimum(0.0f, 0.0f); + glm::vec2 clipDimensions((dimensions.x - (leftMargin + rightMargin)) / scaleFactor, + (dimensions.y - (topMargin + bottomMargin)) / scaleFactor); + + glScalef(scaleFactor, -scaleFactor, 1.0); + enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipDimensions.x); + enableClipPlane(GL_CLIP_PLANE1, 1.0f, 0.0f, 0.0f, -clipMinimum.x); + enableClipPlane(GL_CLIP_PLANE2, 0.0f, -1.0f, 0.0f, clipMinimum.y + clipDimensions.y); + enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y); + + xColor textColor = getTextColorX(); + glColor3f(textColor.red / MAX_COLOR, textColor.green / MAX_COLOR, textColor.blue / MAX_COLOR); + QStringList lines = _text.split("\n"); + int lineOffset = maxHeight; + float textAlpha = 1.0f; // getTextAlpha() + foreach(QString thisLine, lines) { + textRenderer->draw(0, lineOffset, qPrintable(thisLine), textAlpha); + lineOffset += maxHeight; + } + + glDisable(GL_CLIP_PLANE0); + glDisable(GL_CLIP_PLANE1); + glDisable(GL_CLIP_PLANE2); + glDisable(GL_CLIP_PLANE3); + + } + glPopMatrix(); +} + +void RenderableTextEntityItem::enableClipPlane(GLenum plane, float x, float y, float z, float w) { + GLdouble coefficients[] = { x, y, z, w }; + glClipPlane(plane, coefficients); + glEnable(plane); +} + + + diff --git a/interface/src/entities/RenderableTextEntityItem.h b/interface/src/entities/RenderableTextEntityItem.h new file mode 100644 index 0000000000..8760cb9df7 --- /dev/null +++ b/interface/src/entities/RenderableTextEntityItem.h @@ -0,0 +1,44 @@ +// +// RenderableTextEntityItem.h +// interface/src/entities +// +// Created by Brad Hefta-Gaub on 8/6/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_RenderableTextEntityItem_h +#define hifi_RenderableTextEntityItem_h + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +class RenderableTextEntityItem : public TextEntityItem { +public: + static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + + RenderableTextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + TextEntityItem(entityItemID, properties) + { } + + virtual void render(RenderArgs* args); + +private: + void enableClipPlane(GLenum plane, float x, float y, float z, float w); + +}; + + +#endif // hifi_RenderableTextEntityItem_h diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 75fa05032a..d173558711 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -20,6 +20,7 @@ #include "EntityItem.h" #include "EntityItemProperties.h" #include "ModelEntityItem.h" +#include "TextEntityItem.h" EntityItemProperties::EntityItemProperties() : @@ -108,6 +109,11 @@ EntityItemProperties::EntityItemProperties() : _lockedChanged(false), _texturesChanged(false), + CONSTRUCT_PROPERTY(text, TextEntityItem::DEFAULT_TEXT), + CONSTRUCT_PROPERTY(lineHeight, TextEntityItem::DEFAULT_LINE_HEIGHT), + CONSTRUCT_PROPERTY(textColor, TextEntityItem::DEFAULT_TEXT_COLOR), + CONSTRUCT_PROPERTY(backgroundColor, TextEntityItem::DEFAULT_BACKGROUND_COLOR), + _defaultSettings(true), _naturalDimensions(1.0f, 1.0f, 1.0f) { @@ -226,6 +232,10 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_LOCKED, locked); CHECK_PROPERTY_CHANGE(PROP_TEXTURES, textures); CHECK_PROPERTY_CHANGE(PROP_USER_DATA, userData); + CHECK_PROPERTY_CHANGE(PROP_TEXT, text); + CHECK_PROPERTY_CHANGE(PROP_LINE_HEIGHT, lineHeight); + CHECK_PROPERTY_CHANGE(PROP_TEXT_COLOR, textColor); + CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_COLOR, backgroundColor); return changedProperties; } @@ -280,6 +290,10 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons COPY_PROPERTY_TO_QSCRIPTVALUE(locked); COPY_PROPERTY_TO_QSCRIPTVALUE(textures); COPY_PROPERTY_TO_QSCRIPTVALUE(userData); + COPY_PROPERTY_TO_QSCRIPTVALUE(text); + COPY_PROPERTY_TO_QSCRIPTVALUE(lineHeight); + COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(textColor, getTextColor()); + COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(backgroundColor, getBackgroundColor()); // Sitting properties support QScriptValue sittingPoints = engine->newObject(); @@ -355,6 +369,10 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE_BOOL(locked, setLocked); COPY_PROPERTY_FROM_QSCRIPTVALUE_STRING(textures, setTextures); COPY_PROPERTY_FROM_QSCRIPTVALUE_STRING(userData, setUserData); + COPY_PROPERTY_FROM_QSCRIPTVALUE_STRING(text, setText); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(lineHeight, setLineHeight); + COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(textColor, setTextColor); + COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(backgroundColor, setBackgroundColor); _lastEdited = usecTimestampNow(); } @@ -494,30 +512,43 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_LIFETIME, appendValue, properties.getLifetime()); APPEND_ENTITY_PROPERTY(PROP_SCRIPT, appendValue, properties.getScript()); APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, properties.getColor()); - APPEND_ENTITY_PROPERTY(PROP_MODEL_URL, appendValue, properties.getModelURL()); - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_URL, appendValue, properties.getAnimationURL()); - 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_ANGULAR_VELOCITY, appendValue, properties.getAngularVelocity()); APPEND_ENTITY_PROPERTY(PROP_ANGULAR_DAMPING, appendValue, properties.getAngularDamping()); APPEND_ENTITY_PROPERTY(PROP_VISIBLE, appendValue, properties.getVisible()); APPEND_ENTITY_PROPERTY(PROP_IGNORE_FOR_COLLISIONS, appendValue, properties.getIgnoreForCollisions()); APPEND_ENTITY_PROPERTY(PROP_COLLISIONS_WILL_MOVE, appendValue, properties.getCollisionsWillMove()); - APPEND_ENTITY_PROPERTY(PROP_IS_SPOTLIGHT, appendValue, properties.getIsSpotlight()); - APPEND_ENTITY_PROPERTY(PROP_DIFFUSE_COLOR, appendColor, properties.getDiffuseColor()); - APPEND_ENTITY_PROPERTY(PROP_AMBIENT_COLOR, appendColor, properties.getAmbientColor()); - APPEND_ENTITY_PROPERTY(PROP_SPECULAR_COLOR, appendColor, properties.getSpecularColor()); - APPEND_ENTITY_PROPERTY(PROP_CONSTANT_ATTENUATION, appendValue, properties.getConstantAttenuation()); - APPEND_ENTITY_PROPERTY(PROP_LINEAR_ATTENUATION, appendValue, properties.getLinearAttenuation()); - APPEND_ENTITY_PROPERTY(PROP_QUADRATIC_ATTENUATION, appendValue, properties.getQuadraticAttenuation()); - APPEND_ENTITY_PROPERTY(PROP_EXPONENT, appendValue, properties.getExponent()); - APPEND_ENTITY_PROPERTY(PROP_CUTOFF, appendValue, properties.getCutoff()); APPEND_ENTITY_PROPERTY(PROP_LOCKED, appendValue, properties.getLocked()); - APPEND_ENTITY_PROPERTY(PROP_TEXTURES, appendValue, properties.getTextures()); - APPEND_ENTITY_PROPERTY(PROP_ANIMATION_SETTINGS, appendValue, properties.getAnimationSettings()); APPEND_ENTITY_PROPERTY(PROP_USER_DATA, appendValue, properties.getUserData()); + + if (properties.getType() == EntityTypes::Text) { + APPEND_ENTITY_PROPERTY(PROP_TEXT, appendValue, properties.getText()); + APPEND_ENTITY_PROPERTY(PROP_LINE_HEIGHT, appendValue, properties.getLineHeight()); + APPEND_ENTITY_PROPERTY(PROP_TEXT_COLOR, appendColor, properties.getTextColor()); + APPEND_ENTITY_PROPERTY(PROP_BACKGROUND_COLOR, appendColor, properties.getBackgroundColor()); + } + + if (properties.getType() == EntityTypes::Model) { + APPEND_ENTITY_PROPERTY(PROP_MODEL_URL, appendValue, properties.getModelURL()); + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_URL, appendValue, properties.getAnimationURL()); + 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_TEXTURES, appendValue, properties.getTextures()); + APPEND_ENTITY_PROPERTY(PROP_ANIMATION_SETTINGS, appendValue, properties.getAnimationSettings()); + } + + if (properties.getType() == EntityTypes::Light) { + APPEND_ENTITY_PROPERTY(PROP_IS_SPOTLIGHT, appendValue, properties.getIsSpotlight()); + APPEND_ENTITY_PROPERTY(PROP_DIFFUSE_COLOR, appendColor, properties.getDiffuseColor()); + APPEND_ENTITY_PROPERTY(PROP_AMBIENT_COLOR, appendColor, properties.getAmbientColor()); + APPEND_ENTITY_PROPERTY(PROP_SPECULAR_COLOR, appendColor, properties.getSpecularColor()); + APPEND_ENTITY_PROPERTY(PROP_CONSTANT_ATTENUATION, appendValue, properties.getConstantAttenuation()); + APPEND_ENTITY_PROPERTY(PROP_LINEAR_ATTENUATION, appendValue, properties.getLinearAttenuation()); + APPEND_ENTITY_PROPERTY(PROP_QUADRATIC_ATTENUATION, appendValue, properties.getQuadraticAttenuation()); + APPEND_ENTITY_PROPERTY(PROP_EXPONENT, appendValue, properties.getExponent()); + APPEND_ENTITY_PROPERTY(PROP_CUTOFF, appendValue, properties.getCutoff()); + } } if (propertyCount > 0) { int endOfEntityItemData = packetData->getUncompressedByteOffset(); @@ -705,30 +736,43 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LIFETIME, float, setLifetime); READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_SCRIPT,setScript); READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_COLOR, setColor); - READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_MODEL_URL, setModelURL); - READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_ANIMATION_URL, setAnimationURL); - 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); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_REGISTRATION_POINT, glm::vec3, setRegistrationPoint); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ANGULAR_VELOCITY, glm::vec3, setAngularVelocity); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_ANGULAR_DAMPING, float, setAngularDamping); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VISIBLE, bool, setVisible); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_IGNORE_FOR_COLLISIONS, bool, setIgnoreForCollisions); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLLISIONS_WILL_MOVE, bool, setCollisionsWillMove); - READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_IS_SPOTLIGHT, bool, setIsSpotlight); - READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_DIFFUSE_COLOR, setDiffuseColor); - READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_AMBIENT_COLOR, setAmbientColor); - READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_SPECULAR_COLOR, setSpecularColor); - READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_CONSTANT_ATTENUATION, float, setConstantAttenuation); - READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINEAR_ATTENUATION, float, setLinearAttenuation); - READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_QUADRATIC_ATTENUATION, float, setQuadraticAttenuation); - READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EXPONENT, float, setExponent); - READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_CUTOFF, float, setCutoff); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LOCKED, bool, setLocked); - READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_TEXTURES, setTextures); - READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_ANIMATION_SETTINGS, setAnimationSettings); READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_USER_DATA, setUserData); + + if (properties.getType() == EntityTypes::Text) { + READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_TEXT, setText); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_HEIGHT, float, setLineHeight); + READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_TEXT_COLOR, setTextColor); + READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_BACKGROUND_COLOR, setBackgroundColor); + } + + if (properties.getType() == EntityTypes::Model) { + READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_MODEL_URL, setModelURL); + READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_ANIMATION_URL, setAnimationURL); + 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); + READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_TEXTURES, setTextures); + READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_ANIMATION_SETTINGS, setAnimationSettings); + } + + if (properties.getType() == EntityTypes::Light) { + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_IS_SPOTLIGHT, bool, setIsSpotlight); + READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_DIFFUSE_COLOR, setDiffuseColor); + READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_AMBIENT_COLOR, setAmbientColor); + READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_SPECULAR_COLOR, setSpecularColor); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_CONSTANT_ATTENUATION, float, setConstantAttenuation); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINEAR_ATTENUATION, float, setLinearAttenuation); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_QUADRATIC_ATTENUATION, float, setQuadraticAttenuation); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_EXPONENT, float, setExponent); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_CUTOFF, float, setCutoff); + } return valid; } @@ -800,6 +844,11 @@ void EntityItemProperties::markAllChanged() { _cutoffChanged = true; _lockedChanged = true; _texturesChanged = true; + + _textChanged = true; + _lineHeightChanged = true; + _textColorChanged = true; + _backgroundColorChanged = true; } AACube EntityItemProperties::getMaximumAACubeInTreeUnits() const { diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 273aedb18a..10cb18e244 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -83,7 +83,14 @@ enum EntityPropertyList { PROP_ANIMATION_SETTINGS, PROP_USER_DATA, - PROP_LAST_ITEM = PROP_USER_DATA + PROP_LAST_ITEM = PROP_USER_DATA, + + // These properties of TextEntity piggy back off of properties of ModelEntities, the type doesn't matter + // since the derived class knows how to interpret it's own properties and knows the types it expects + PROP_TEXT_COLOR = PROP_COLOR, + PROP_TEXT = PROP_MODEL_URL, + PROP_LINE_HEIGHT = PROP_ANIMATION_URL, + PROP_BACKGROUND_COLOR = PROP_ANIMATION_FPS, }; typedef PropertyFlags EntityPropertyFlags; @@ -102,6 +109,7 @@ class EntityItemProperties { friend class BoxEntityItem; // TODO: consider removing this friend relationship and use public methods friend class SphereEntityItem; // TODO: consider removing this friend relationship and use public methods friend class LightEntityItem; // TODO: consider removing this friend relationship and use public methods + friend class TextEntityItem; // TODO: consider removing this friend relationship and use public methods public: EntityItemProperties(); virtual ~EntityItemProperties(); @@ -393,6 +401,12 @@ private: bool _lockedChanged; bool _texturesChanged; + DEFINE_PROPERTY_REF(PROP_TEXT, Text, text, QString); + DEFINE_PROPERTY(PROP_LINE_HEIGHT, LineHeight, lineHeight, float); + DEFINE_PROPERTY_REF(PROP_TEXT_COLOR, TextColor, textColor, xColor); + DEFINE_PROPERTY_REF(PROP_BACKGROUND_COLOR, BackgroundColor, backgroundColor, xColor); + +private: bool _defaultSettings; // NOTE: The following are pseudo client only properties. They are only used in clients which can access diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index 77782cb90f..f61d89dbd2 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -260,6 +260,26 @@ } \ } \ } + +#define CONSTRUCT_PROPERTY(n, V) \ + _##n(V), \ + _##n##Changed(false) + +#define DEFINE_PROPERTY(P, N, n, T) \ + public: \ + T get##N() const { return _##n; } \ + void set##N(T value) { _##n = value; _##n##Changed = true; } \ + private: \ + T _##n; \ + bool _##n##Changed; + +#define DEFINE_PROPERTY_REF(P, N, n, T) \ + public: \ + const T& get##N() const { return _##n; } \ + void set##N(const T& value) { _##n = value; _##n##Changed = true; } \ + private: \ + T _##n; \ + bool _##n##Changed; diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index aaa297f4fd..194df024e0 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -22,6 +22,7 @@ #include "LightEntityItem.h" #include "ModelEntityItem.h" #include "SphereEntityItem.h" +#include "TextEntityItem.h" QMap EntityTypes::_typeToNameMap; QMap EntityTypes::_nameToTypeMap; @@ -35,6 +36,7 @@ REGISTER_ENTITY_TYPE(Model) REGISTER_ENTITY_TYPE(Box) REGISTER_ENTITY_TYPE(Sphere) REGISTER_ENTITY_TYPE(Light) +REGISTER_ENTITY_TYPE(Text) const QString& EntityTypes::getEntityTypeName(EntityType entityType) { diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index 85bbff99ef..8ed407f11d 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -34,7 +34,8 @@ public: Box, Sphere, Light, - LAST = Light + Text, + LAST = Text } EntityType; static const QString& getEntityTypeName(EntityType entityType); diff --git a/libraries/entities/src/TextEntityItem.cpp b/libraries/entities/src/TextEntityItem.cpp new file mode 100644 index 0000000000..491240c178 --- /dev/null +++ b/libraries/entities/src/TextEntityItem.cpp @@ -0,0 +1,113 @@ +// +// TextEntityItem.cpp +// libraries/entities/src +// +// Created by Brad Hefta-Gaub on 12/4/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#include + +#include + +#include "EntityTree.h" +#include "EntityTreeElement.h" +#include "TextEntityItem.h" + + +const QString TextEntityItem::DEFAULT_TEXT(""); +const float TextEntityItem::DEFAULT_LINE_HEIGHT = 0.1f; +const xColor TextEntityItem::DEFAULT_TEXT_COLOR = { 255, 255, 255 }; +const xColor TextEntityItem::DEFAULT_BACKGROUND_COLOR = { 0, 0, 0}; + +EntityItem* TextEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { + EntityItem* result = new TextEntityItem(entityID, properties); + return result; +} + +TextEntityItem::TextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + EntityItem(entityItemID) +{ + _type = EntityTypes::Text; + _created = properties.getCreated(); + setProperties(properties, true); +} + +EntityItemProperties TextEntityItem::getProperties() const { + EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class + + COPY_ENTITY_PROPERTY_TO_PROPERTIES(text, getText); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineHeight, getLineHeight); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(textColor, getTextColorX); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(backgroundColor, getBackgroundColorX); + return properties; +} + +bool TextEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) { + bool somethingChanged = false; + somethingChanged = EntityItem::setProperties(properties, forceCopy); // set the properties in our base class + + SET_ENTITY_PROPERTY_FROM_PROPERTIES(text, setText); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(lineHeight, setLineHeight); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(textColor, setTextColor); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(backgroundColor, setBackgroundColor); + + if (somethingChanged) { + bool wantDebug = false; + if (wantDebug) { + uint64_t now = usecTimestampNow(); + int elapsed = now - getLastEdited(); + qDebug() << "TextEntityItem::setProperties() AFTER update... edited AGO=" << elapsed << + "now=" << now << " getLastEdited()=" << getLastEdited(); + } + setLastEdited(properties._lastEdited); + } + + return somethingChanged; +} + +int TextEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { + + int bytesRead = 0; + const unsigned char* dataAt = data; + + READ_ENTITY_PROPERTY_STRING(PROP_TEXT, setText); + READ_ENTITY_PROPERTY(PROP_LINE_HEIGHT, float, _lineHeight); + READ_ENTITY_PROPERTY_COLOR(PROP_TEXT_COLOR, _textColor); + READ_ENTITY_PROPERTY_COLOR(PROP_BACKGROUND_COLOR, _backgroundColor); + + return bytesRead; +} + + +// TODO: eventually only include properties changed since the params.lastViewFrustumSent time +EntityPropertyFlags TextEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { + EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); + requestedProperties += PROP_TEXT; + requestedProperties += PROP_LINE_HEIGHT; + requestedProperties += PROP_TEXT_COLOR; + requestedProperties += PROP_BACKGROUND_COLOR; + return requestedProperties; +} + +void TextEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { + + bool successPropertyFits = true; + + APPEND_ENTITY_PROPERTY(PROP_TEXT, appendValue, getText()); + APPEND_ENTITY_PROPERTY(PROP_LINE_HEIGHT, appendValue, getLineHeight()); + APPEND_ENTITY_PROPERTY(PROP_TEXT_COLOR, appendColor, getTextColor()); + APPEND_ENTITY_PROPERTY(PROP_BACKGROUND_COLOR, appendColor, getBackgroundColor()); +} \ No newline at end of file diff --git a/libraries/entities/src/TextEntityItem.h b/libraries/entities/src/TextEntityItem.h new file mode 100644 index 0000000000..019d230c36 --- /dev/null +++ b/libraries/entities/src/TextEntityItem.h @@ -0,0 +1,81 @@ +// +// TextEntityItem.h +// libraries/entities/src +// +// Created by Brad Hefta-Gaub on 12/4/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_TextEntityItem_h +#define hifi_TextEntityItem_h + +#include "EntityItem.h" + +class TextEntityItem : public EntityItem { +public: + static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + + TextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + + ALLOW_INSTANTIATION // This class can be instantiated + + // methods for getting/setting all properties of an entity + virtual EntityItemProperties getProperties() const; + virtual bool setProperties(const EntityItemProperties& properties, bool forceCopy = false); + + // TODO: eventually only include properties changed since the params.lastViewFrustumSent time + virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; + + virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const; + + virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData); + + static const QString DEFAULT_TEXT; + void setText(const QString& value) { _text = value; } + const QString& getText() const { return _text; } + + static const float DEFAULT_LINE_HEIGHT; + void setLineHeight(float value) { _lineHeight = value; } + float getLineHeight() const { return _lineHeight; } + + static const xColor DEFAULT_TEXT_COLOR; + const rgbColor& getTextColor() const { return _textColor; } + xColor getTextColorX() const { xColor color = { _textColor[RED_INDEX], _textColor[GREEN_INDEX], _textColor[BLUE_INDEX] }; return color; } + + void setTextColor(const rgbColor& value) { memcpy(_textColor, value, sizeof(_textColor)); } + void setTextColor(const xColor& value) { + _textColor[RED_INDEX] = value.red; + _textColor[GREEN_INDEX] = value.green; + _textColor[BLUE_INDEX] = value.blue; + } + + static const xColor DEFAULT_BACKGROUND_COLOR; + const rgbColor& getBackgroundColor() const { return _backgroundColor; } + xColor getBackgroundColorX() const { xColor color = { _backgroundColor[RED_INDEX], _backgroundColor[GREEN_INDEX], _backgroundColor[BLUE_INDEX] }; return color; } + + void setBackgroundColor(const rgbColor& value) { memcpy(_backgroundColor, value, sizeof(_backgroundColor)); } + void setBackgroundColor(const xColor& value) { + _backgroundColor[RED_INDEX] = value.red; + _backgroundColor[GREEN_INDEX] = value.green; + _backgroundColor[BLUE_INDEX] = value.blue; + } + +protected: + QString _text; + float _lineHeight; + rgbColor _textColor; + rgbColor _backgroundColor; +}; + +#endif // hifi_TextEntityItem_h From dd349ebfd1725c862fa7dbacd4be550c86d2cfc3 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 16:03:43 -0800 Subject: [PATCH 02/13] coding standard cleanup, fix warning --- interface/src/ui/overlays/Overlays.h | 3 ++- libraries/octree/src/OctreeHeadlessViewer.h | 3 ++- libraries/octree/src/OctreeRenderer.h | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index d49ffcc3d0..312d872eb7 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -51,7 +51,8 @@ public: ~Overlays(); void init(QGLWidget* parent); void update(float deltatime); - void render3D(RenderArgs::RenderMode renderMode = RenderArgs::DEFAULT_RENDER_MODE, RenderArgs::RenderSide renderSide = RenderArgs::MONO); + void render3D(RenderArgs::RenderMode renderMode = RenderArgs::DEFAULT_RENDER_MODE, + RenderArgs::RenderSide renderSide = RenderArgs::MONO); void render2D(); public slots: diff --git a/libraries/octree/src/OctreeHeadlessViewer.h b/libraries/octree/src/OctreeHeadlessViewer.h index 03b8a204e0..9a6a5c7102 100644 --- a/libraries/octree/src/OctreeHeadlessViewer.h +++ b/libraries/octree/src/OctreeHeadlessViewer.h @@ -33,7 +33,8 @@ public: virtual void renderElement(OctreeElement* element, RenderArgs* args) { /* swallow these */ } virtual void init(); - virtual void render(RenderArgs::RenderMode renderMode = RenderArgs::DEFAULT_RENDER_MODE) { /* swallow these */ } + virtual void render(RenderArgs::RenderMode renderMode = RenderArgs::DEFAULT_RENDER_MODE, + RenderArgs::RenderSide renderSide = RenderArgs::MONO) { /* swallow these */ } void setJurisdictionListener(JurisdictionListener* jurisdictionListener) { _jurisdictionListener = jurisdictionListener; } diff --git a/libraries/octree/src/OctreeRenderer.h b/libraries/octree/src/OctreeRenderer.h index e8612b4cb6..2999f34fb6 100644 --- a/libraries/octree/src/OctreeRenderer.h +++ b/libraries/octree/src/OctreeRenderer.h @@ -52,7 +52,8 @@ public: virtual void init(); /// render the content of the octree - virtual void render(RenderArgs::RenderMode renderMode = RenderArgs::DEFAULT_RENDER_MODE, RenderArgs::RenderSide renderSide = RenderArgs::MONO); + virtual void render(RenderArgs::RenderMode renderMode = RenderArgs::DEFAULT_RENDER_MODE, + RenderArgs::RenderSide renderSide = RenderArgs::MONO); ViewFrustum* getViewFrustum() const { return _viewFrustum; } void setViewFrustum(ViewFrustum* viewFrustum) { _viewFrustum = viewFrustum; } From 9657e7a469e47479c35b6c34fbb4fe45af3ae074 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 16:28:47 -0800 Subject: [PATCH 03/13] add text entity editing to editModels and entityPropertyDialogBox --- examples/editModels.js | 35 ++++++++++++++++ examples/libraries/entityPropertyDialogBox.js | 40 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/examples/editModels.js b/examples/editModels.js index 7538a83fef..0fc5d4a7f9 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -48,6 +48,9 @@ var RIGHT = 1; var SPAWN_DISTANCE = 1; var DEFAULT_DIMENSION = 0.20; +var DEFAULT_TEXT_DIMENSION_X = 1.0; +var DEFAULT_TEXT_DIMENSION_Y = 1.0; +var DEFAULT_TEXT_DIMENSION_Z = 0.01; var modelURLs = [ HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Alder.fbx", @@ -1122,6 +1125,7 @@ var toolBar = (function () { newModelButton, newCubeButton, newSphereButton, + newTextButton, browseModelsButton, loadURLMenuItem, loadFileMenuItem, @@ -1208,6 +1212,18 @@ var toolBar = (function () { alpha: 0.9, visible: true }); + + print(toolIconUrl + "add-text.svg"); + + newTextButton = toolBar.addTool({ + imageURL: toolIconUrl + "add-text.svg", + subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, + width: toolWidth, + height: toolHeight, + alpha: 0.9, + visible: true + }); + } @@ -1372,6 +1388,25 @@ var toolBar = (function () { } + if (newTextButton === toolBar.clicked(clickedOverlay)) { + var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); + + if (position.x > 0 && position.y > 0 && position.z > 0) { + Entities.addEntity({ + type: "Text", + position: position, + dimensions: { x: DEFAULT_TEXT_DIMENSION_X, y: DEFAULT_TEXT_DIMENSION_Y, z: DEFAULT_TEXT_DIMENSION_Z }, + backgroundColor: { red: 255, green: 0, blue: 0 }, + textColor: { red: 255, green: 255, blue: 255 }, + text: "some text", + lineHight: "0.1" + }); + } else { + print("Can't create box: Text would be out of bounds."); + } + return true; + } + return false; }; diff --git a/examples/libraries/entityPropertyDialogBox.js b/examples/libraries/entityPropertyDialogBox.js index da60e0c370..3dae431e9a 100644 --- a/examples/libraries/entityPropertyDialogBox.js +++ b/examples/libraries/entityPropertyDialogBox.js @@ -65,6 +65,30 @@ EntityPropertyDialogBox = (function () { array.push({ label: "Original Textures:\n" + properties.originalTextures, type: "header" }); index++; } + + if (properties.type == "Text") { + array.push({ label: "Text:", value: properties.text }); + index++; + array.push({ label: "Line Height:", value: properties.lineHeight }); + index++; + array.push({ label: "Text Color:", type: "header" }); + index++; + array.push({ label: "Red:", value: properties.textColor.red }); + index++; + array.push({ label: "Green:", value: properties.textColor.green }); + index++; + array.push({ label: "Blue:", value: properties.textColor.blue }); + index++; + array.push({ label: "Background Color:", type: "header" }); + index++; + array.push({ label: "Red:", value: properties.backgroundColor.red }); + index++; + array.push({ label: "Green:", value: properties.backgroundColor.green }); + index++; + array.push({ label: "Blue:", value: properties.backgroundColor.blue }); + index++; + } + array.push({ label: "Position:", type: "header" }); index++; array.push({ label: "X:", value: properties.position.x.toFixed(decimals) }); @@ -271,6 +295,22 @@ EntityPropertyDialogBox = (function () { properties.textures = array[index++].value; index++; // skip textureNames label } + + if (properties.type == "Text") { + properties.text = array[index++].value; + properties.lineHeight = array[index++].value; + + index++; // skip header + properties.textColor.red = array[index++].value; + properties.textColor.green = array[index++].value; + properties.textColor.blue = array[index++].value; + + index++; // skip header + properties.backgroundColor.red = array[index++].value; + properties.backgroundColor.green = array[index++].value; + properties.backgroundColor.blue = array[index++].value; + } + index++; // skip header properties.position.x = array[index++].value; properties.position.y = array[index++].value; From f31b5aba275867e38087604ba87d4f491448e567 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 16:31:50 -0800 Subject: [PATCH 04/13] use actual background color --- interface/src/entities/RenderableTextEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/entities/RenderableTextEntityItem.cpp b/interface/src/entities/RenderableTextEntityItem.cpp index 601cbb347a..771962ecc6 100644 --- a/interface/src/entities/RenderableTextEntityItem.cpp +++ b/interface/src/entities/RenderableTextEntityItem.cpp @@ -51,7 +51,7 @@ void RenderableTextEntityItem::render(RenderArgs* args) { glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); const float MAX_COLOR = 255.0f; - xColor backgroundColor = { 255, 0, 0 }; //getBackgroundColorX(); + xColor backgroundColor = getBackgroundColorX(); float alpha = 1.0f; //getBackgroundAlpha(); glColor4f(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, alpha); From 3f18741b158ec3bcaf75d97b518ce9be65a5f680 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 16:40:56 -0800 Subject: [PATCH 05/13] add new text entity tool to newEditEntities.js --- examples/editModels.js | 9 +++------ examples/newEditEntities.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 0fc5d4a7f9..69976e03a1 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -1213,18 +1213,15 @@ var toolBar = (function () { visible: true }); - print(toolIconUrl + "add-text.svg"); - newTextButton = toolBar.addTool({ - imageURL: toolIconUrl + "add-text.svg", + //imageURL: toolIconUrl + "add-text.svg", + imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/tools/add-text.svg", // temporarily subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, width: toolWidth, height: toolHeight, alpha: 0.9, visible: true }); - - } function toggleNewModelButton(active) { @@ -1396,7 +1393,7 @@ var toolBar = (function () { type: "Text", position: position, dimensions: { x: DEFAULT_TEXT_DIMENSION_X, y: DEFAULT_TEXT_DIMENSION_Y, z: DEFAULT_TEXT_DIMENSION_Z }, - backgroundColor: { red: 255, green: 0, blue: 0 }, + backgroundColor: { red: 0, green: 0, blue: 0 }, textColor: { red: 255, green: 255, blue: 255 }, text: "some text", lineHight: "0.1" diff --git a/examples/newEditEntities.js b/examples/newEditEntities.js index cc3c0fceda..4d6194880b 100644 --- a/examples/newEditEntities.js +++ b/examples/newEditEntities.js @@ -54,6 +54,9 @@ var wantEntityGlow = false; var SPAWN_DISTANCE = 1; var DEFAULT_DIMENSION = 0.20; +var DEFAULT_TEXT_DIMENSION_X = 1.0; +var DEFAULT_TEXT_DIMENSION_Y = 1.0; +var DEFAULT_TEXT_DIMENSION_Z = 0.01; var MENU_INSPECT_TOOL_ENABLED = "Inspect Tool"; var MENU_EASE_ON_FOCUS = "Ease Orientation on Focus"; @@ -84,6 +87,7 @@ var toolBar = (function () { newCubeButton, newSphereButton, newLightButton, + newTextButton, browseModelsButton, loadURLMenuItem, loadFileMenuItem, @@ -180,6 +184,16 @@ var toolBar = (function () { visible: true }); + newTextButton = toolBar.addTool({ + //imageURL: toolIconUrl + "add-text.svg", + imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/tools/add-text.svg", // temporarily + subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, + width: toolWidth, + height: toolHeight, + alpha: 0.9, + visible: true + }); + } function toggleNewModelButton(active) { @@ -378,6 +392,24 @@ var toolBar = (function () { return true; } + if (newTextButton === toolBar.clicked(clickedOverlay)) { + var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); + + if (position.x > 0 && position.y > 0 && position.z > 0) { + Entities.addEntity({ + type: "Text", + position: position, + dimensions: { x: DEFAULT_TEXT_DIMENSION_X, y: DEFAULT_TEXT_DIMENSION_Y, z: DEFAULT_TEXT_DIMENSION_Z }, + backgroundColor: { red: 0, green: 0, blue: 0 }, + textColor: { red: 255, green: 255, blue: 255 }, + text: "some text", + lineHight: "0.1" + }); + } else { + print("Can't create box: Text would be out of bounds."); + } + return true; + } return false; From 0cb95fc82aa02da34dbc190726fd68a15740bda2 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 17:20:05 -0800 Subject: [PATCH 06/13] add support for text properties to new html propety tools --- examples/html/entityProperties.html | 73 ++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 408e83198f..571eb030a1 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -135,6 +135,16 @@ var elModelAnimationPlaying = document.getElementById("property-model-animation-playing"); var elModelAnimationFPS = document.getElementById("property-model-animation-fps"); + var elTextSection = document.getElementById("text-section"); + var elTextText = document.getElementById("property-text-text"); + var elTextLineHeight = document.getElementById("property-text-line-height"); + var elTextTextColorRed = document.getElementById("property-text-text-color-red"); + var elTextTextColorGreen = document.getElementById("property-text-text-color-green"); + var elTextTextColorBlue = document.getElementById("property-text-text-color-blue"); + var elTextBackgroundColorRed = document.getElementById("property-text-background-color-red"); + var elTextBackgroundColorGreen = document.getElementById("property-text-background-color-green"); + var elTextBackgroundColorBlue = document.getElementById("property-text-background-color-blue"); + if (window.EventBridge !== undefined) { EventBridge.scriptEventReceived.connect(function(data) { data = JSON.parse(data); @@ -201,13 +211,27 @@ elModelSection.style.display = 'none'; } else { elModelSection.style.display = 'block'; - elModelURL.value = properties.modelURL; elModelAnimationURL.value = properties.animationURL; elModelAnimationPlaying.checked = properties.animationPlaying; elModelAnimationFPS.value = properties.animationFPS; } + if (properties.type != "Text") { + elTextSection.style.display = 'none'; + } else { + elTextSection.style.display = 'block'; + + elTextText.value = properties.text; + elTextLineHeight.value = properties.lineHeight; + elTextTextColorRed.value = properties.textColor.red; + elTextTextColorGreen.value = properties.textColor.green; + elTextTextColorBlue.value = properties.textColor.blue; + elTextBackgroundColorRed.value = properties.backgroundColor.red; + elTextBackgroundColorGreen.value = properties.backgroundColor.green; + elTextBackgroundColorBlue.value = properties.backgroundColor.blue; + } + if (properties.type != "Light") { elLightSection.style.display = 'none'; } else { @@ -320,6 +344,22 @@ elModelAnimationPlaying.addEventListener('change', createEmitCheckedPropertyUpdateFunction('animationIsPlaying')); elModelAnimationFPS.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFPS')); elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex')); + + elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text')); + elTextLineHeight.addEventListener('change', createEmitNumberPropertyUpdateFunction('lineHeight')); + + var textTextColorChangeFunction = createEmitColorPropertyUpdateFunction( + 'textColor', elTextTextColorRed, elTextTextColorGreen, elTextTextColorBlue); + elTextTextColorRed.addEventListener('change', textTextColorChangeFunction); + elTextTextColorGreen.addEventListener('change', textTextColorChangeFunction); + elTextTextColorBlue.addEventListener('change', textTextColorChangeFunction); + + var textBackgroundColorChangeFunction = createEmitColorPropertyUpdateFunction( + 'backgroundColor', elTextBackgroundColorRed, elTextBackgroundColorGreen, elTextBackgroundColorBlue); + elTextBackgroundColorRed.addEventListener('change', textBackgroundColorChangeFunction); + elTextBackgroundColorGreen.addEventListener('change', textBackgroundColorChangeFunction); + elTextBackgroundColorBlue.addEventListener('change', textBackgroundColorChangeFunction); + } @@ -492,6 +532,37 @@ +
+
+ + + + +
+
+ + + + +
+
+ + + Red + Green + Blue + +
+
+ + + Red + Green + Blue + +
+
+
From 55ac9c8ef7cf82fce8b63ff1a79fd3c0fd908560 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 21:16:50 -0800 Subject: [PATCH 07/13] make sure properties include type for proper encoding --- libraries/entities/src/EntityScriptingInterface.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 1658764c71..29c4a8b19a 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -93,7 +93,6 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) { EntityItemID actualID = entityID; - // if the entity is unknown, attempt to look it up if (!entityID.isKnownID) { actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); @@ -113,6 +112,18 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E // if at this point, we know the id, send the update to the entity server if (entityID.isKnownID) { + // make sure the properties has a type, so that the encode can know which properties to include + if (properties.getType() == EntityTypes::Unknown) { + EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID); + if (entity) { + EntityItemProperties tempProperties = properties; + tempProperties.setType(entity->getType()); + queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, tempProperties); + return entityID; + } + } + + // if the properties already includes the type, then use it as is queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); } From a37275e6b16e303c60f72c0d3b92c1f6aae4433d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 21:17:13 -0800 Subject: [PATCH 08/13] fix animation frame --- examples/html/entityProperties.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 571eb030a1..695879b678 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -134,6 +134,7 @@ var elModelAnimationURL = document.getElementById("property-model-animation-url"); var elModelAnimationPlaying = document.getElementById("property-model-animation-playing"); var elModelAnimationFPS = document.getElementById("property-model-animation-fps"); + var elModelAnimationFrame = document.getElementById("property-model-animation-frame"); var elTextSection = document.getElementById("text-section"); var elTextText = document.getElementById("property-text-text"); @@ -344,7 +345,7 @@ elModelAnimationPlaying.addEventListener('change', createEmitCheckedPropertyUpdateFunction('animationIsPlaying')); elModelAnimationFPS.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFPS')); elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex')); - + elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text')); elTextLineHeight.addEventListener('change', createEmitNumberPropertyUpdateFunction('lineHeight')); @@ -530,6 +531,12 @@
+
+ + + + +
From 66f519d61386d89a8c94bd0d4c9a51fbb206475f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 22:15:19 -0800 Subject: [PATCH 09/13] dry up EntityItemProperties with macros --- .../entities/src/EntityItemProperties.cpp | 131 +++------ libraries/entities/src/EntityItemProperties.h | 273 ++++-------------- .../entities/src/EntityItemPropertiesMacros.h | 36 ++- 3 files changed, 124 insertions(+), 316 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index d173558711..11c9646cbc 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -24,96 +24,57 @@ EntityItemProperties::EntityItemProperties() : - _id(UNKNOWN_ENTITY_ID), - _idSet(false), - _lastEdited(0), // ???? - _created(UNKNOWN_CREATED_TIME), - _type(EntityTypes::Unknown), - - _position(0), - _dimensions(EntityItem::DEFAULT_DIMENSIONS), - _rotation(EntityItem::DEFAULT_ROTATION), - _mass(EntityItem::DEFAULT_MASS), - _velocity(EntityItem::DEFAULT_VELOCITY), - _gravity(EntityItem::DEFAULT_GRAVITY), - _damping(EntityItem::DEFAULT_DAMPING), - _lifetime(EntityItem::DEFAULT_LIFETIME), - _userData(EntityItem::DEFAULT_USER_DATA), - _script(EntityItem::DEFAULT_SCRIPT), - _registrationPoint(EntityItem::DEFAULT_REGISTRATION_POINT), - _angularVelocity(EntityItem::DEFAULT_ANGULAR_VELOCITY), - _angularDamping(EntityItem::DEFAULT_ANGULAR_DAMPING), - _visible(EntityItem::DEFAULT_VISIBLE), - _ignoreForCollisions(EntityItem::DEFAULT_IGNORE_FOR_COLLISIONS), - _collisionsWillMove(EntityItem::DEFAULT_COLLISIONS_WILL_MOVE), - - _positionChanged(false), - _dimensionsChanged(false), - _rotationChanged(false), - _massChanged(false), - _velocityChanged(false), - _gravityChanged(false), - _dampingChanged(false), - _lifetimeChanged(false), - _userDataChanged(false), - _scriptChanged(false), - _registrationPointChanged(false), - _angularVelocityChanged(false), - _angularDampingChanged(false), - _visibleChanged(false), - _ignoreForCollisionsChanged(false), - _collisionsWillMoveChanged(false), - - _color(), - _modelURL(""), - _animationURL(""), - _animationIsPlaying(ModelEntityItem::DEFAULT_ANIMATION_IS_PLAYING), - _animationFrameIndex(ModelEntityItem::DEFAULT_ANIMATION_FRAME_INDEX), - _animationFPS(ModelEntityItem::DEFAULT_ANIMATION_FPS), - _animationSettings(""), - _glowLevel(0.0f), - _localRenderAlpha(1.0f), - _isSpotlight(false), - - _colorChanged(false), - _modelURLChanged(false), - _animationURLChanged(false), - _animationIsPlayingChanged(false), - _animationFrameIndexChanged(false), - _animationFPSChanged(false), - _animationSettingsChanged(false), - - _glowLevelChanged(false), - _localRenderAlphaChanged(false), - _isSpotlightChanged(false), - - _diffuseColor(), - _ambientColor(), - _specularColor(), - _constantAttenuation(1.0f), - _linearAttenuation(0.0f), - _quadraticAttenuation(0.0f), - _exponent(0.0f), - _cutoff(PI), - _locked(false), - _textures(""), - - _diffuseColorChanged(false), - _ambientColorChanged(false), - _specularColorChanged(false), - _constantAttenuationChanged(false), - _linearAttenuationChanged(false), - _quadraticAttenuationChanged(false), - _exponentChanged(false), - _cutoffChanged(false), - _lockedChanged(false), - _texturesChanged(false), - + CONSTRUCT_PROPERTY(visible, EntityItem::DEFAULT_VISIBLE), + CONSTRUCT_PROPERTY(position, 0), + CONSTRUCT_PROPERTY(dimensions, EntityItem::DEFAULT_DIMENSIONS), + CONSTRUCT_PROPERTY(rotation, EntityItem::DEFAULT_ROTATION), + CONSTRUCT_PROPERTY(mass, EntityItem::DEFAULT_MASS), + CONSTRUCT_PROPERTY(velocity, EntityItem::DEFAULT_VELOCITY), + CONSTRUCT_PROPERTY(gravity, EntityItem::DEFAULT_GRAVITY), + CONSTRUCT_PROPERTY(damping, EntityItem::DEFAULT_DAMPING), + CONSTRUCT_PROPERTY(lifetime, EntityItem::DEFAULT_LIFETIME), + CONSTRUCT_PROPERTY(script, EntityItem::DEFAULT_SCRIPT), + CONSTRUCT_PROPERTY(color, ), + CONSTRUCT_PROPERTY(modelURL, ""), + CONSTRUCT_PROPERTY(animationURL, ""), + CONSTRUCT_PROPERTY(animationFPS, ModelEntityItem::DEFAULT_ANIMATION_FPS), + CONSTRUCT_PROPERTY(animationFrameIndex, ModelEntityItem::DEFAULT_ANIMATION_FRAME_INDEX), + CONSTRUCT_PROPERTY(animationIsPlaying, ModelEntityItem::DEFAULT_ANIMATION_IS_PLAYING), + CONSTRUCT_PROPERTY(registrationPoint, EntityItem::DEFAULT_REGISTRATION_POINT), + CONSTRUCT_PROPERTY(angularVelocity, EntityItem::DEFAULT_ANGULAR_VELOCITY), + CONSTRUCT_PROPERTY(angularDamping, EntityItem::DEFAULT_ANGULAR_DAMPING), + CONSTRUCT_PROPERTY(ignoreForCollisions, EntityItem::DEFAULT_IGNORE_FOR_COLLISIONS), + CONSTRUCT_PROPERTY(collisionsWillMove, EntityItem::DEFAULT_COLLISIONS_WILL_MOVE), + CONSTRUCT_PROPERTY(isSpotlight, false), + CONSTRUCT_PROPERTY(diffuseColor, ), + CONSTRUCT_PROPERTY(ambientColor, ), + CONSTRUCT_PROPERTY(specularColor, ), + CONSTRUCT_PROPERTY(constantAttenuation, 1.0f), + CONSTRUCT_PROPERTY(linearAttenuation, 0.0f), + CONSTRUCT_PROPERTY(quadraticAttenuation, 0.0f), + CONSTRUCT_PROPERTY(exponent, 0.0f), + CONSTRUCT_PROPERTY(cutoff, PI), + CONSTRUCT_PROPERTY(locked, false), + CONSTRUCT_PROPERTY(textures, ""), + CONSTRUCT_PROPERTY(animationSettings, ""), + CONSTRUCT_PROPERTY(userData, EntityItem::DEFAULT_USER_DATA), CONSTRUCT_PROPERTY(text, TextEntityItem::DEFAULT_TEXT), CONSTRUCT_PROPERTY(lineHeight, TextEntityItem::DEFAULT_LINE_HEIGHT), CONSTRUCT_PROPERTY(textColor, TextEntityItem::DEFAULT_TEXT_COLOR), CONSTRUCT_PROPERTY(backgroundColor, TextEntityItem::DEFAULT_BACKGROUND_COLOR), + _id(UNKNOWN_ENTITY_ID), + _idSet(false), + _lastEdited(0), + _created(UNKNOWN_CREATED_TIME), + _type(EntityTypes::Unknown), + + _glowLevel(0.0f), + _localRenderAlpha(1.0f), + + _glowLevelChanged(false), + _localRenderAlphaChanged(false), + _defaultSettings(true), _naturalDimensions(1.0f, 1.0f, 1.0f) { diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 10cb18e244..642e24beec 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -114,6 +114,9 @@ public: EntityItemProperties(); virtual ~EntityItemProperties(); + EntityTypes::EntityType getType() const { return _type; } + void setType(EntityTypes::EntityType type) { _type = type; } + virtual QScriptValue copyToScriptValue(QScriptEngine* engine) const; virtual void copyFromScriptValue(const QScriptValue& object); @@ -131,86 +134,63 @@ public: AABox getAABoxInMeters() const; void debugDump() const; + void setLastEdited(quint64 usecTime) { _lastEdited = usecTime; } + DEFINE_PROPERTY(PROP_VISIBLE, Visible, visible, bool); + DEFINE_PROPERTY_REF_WITH_SETTER(PROP_POSITION, Position, position, glm::vec3); + DEFINE_PROPERTY_REF(PROP_DIMENSIONS, Dimensions, dimensions, glm::vec3); + DEFINE_PROPERTY_REF(PROP_ROTATION, Rotation, rotation, glm::quat); + DEFINE_PROPERTY(PROP_MASS, Mass, mass, float); + DEFINE_PROPERTY_REF(PROP_VELOCITY, Velocity, velocity, glm::vec3); + DEFINE_PROPERTY_REF(PROP_GRAVITY, Gravity, gravity, glm::vec3); + DEFINE_PROPERTY(PROP_DAMPING, Damping, damping, float); + DEFINE_PROPERTY(PROP_LIFETIME, Lifetime, lifetime, float); + DEFINE_PROPERTY_REF(PROP_SCRIPT, Script, script, QString); + DEFINE_PROPERTY_REF(PROP_COLOR, Color, color, xColor); + DEFINE_PROPERTY_REF(PROP_MODEL_URL, ModelURL, modelURL, QString); + DEFINE_PROPERTY_REF(PROP_ANIMATION_URL, AnimationURL, animationURL, QString); + DEFINE_PROPERTY(PROP_ANIMATION_FPS, AnimationFPS, animationFPS, float); + DEFINE_PROPERTY(PROP_ANIMATION_FRAME_INDEX, AnimationFrameIndex, animationFrameIndex, float); + DEFINE_PROPERTY(PROP_ANIMATION_PLAYING, AnimationIsPlaying, animationIsPlaying, bool); + DEFINE_PROPERTY_REF(PROP_REGISTRATION_POINT, RegistrationPoint, registrationPoint, glm::vec3); + DEFINE_PROPERTY_REF(PROP_ANGULAR_VELOCITY, AngularVelocity, angularVelocity, glm::vec3); + DEFINE_PROPERTY(PROP_ANGULAR_DAMPING, AngularDamping, angularDamping, float); + DEFINE_PROPERTY(PROP_IGNORE_FOR_COLLISIONS, IgnoreForCollisions, ignoreForCollisions, bool); + DEFINE_PROPERTY(PROP_COLLISIONS_WILL_MOVE, CollisionsWillMove, collisionsWillMove, bool); + DEFINE_PROPERTY(PROP_IS_SPOTLIGHT, IsSpotlight, isSpotlight, bool); + DEFINE_PROPERTY_REF(PROP_DIFFUSE_COLOR, DiffuseColor, diffuseColor, xColor); + DEFINE_PROPERTY_REF(PROP_AMBIENT_COLOR, AmbientColor, ambientColor, xColor); + DEFINE_PROPERTY_REF(PROP_SPECULAR_COLOR, SpecularColor, specularColor, xColor); + DEFINE_PROPERTY(PROP_CONSTANT_ATTENUATION, ConstantAttenuation, constantAttenuation, float); + DEFINE_PROPERTY(PROP_LINEAR_ATTENUATION, LinearAttenuation, linearAttenuation, float); + DEFINE_PROPERTY(PROP_QUADRATIC_ATTENUATION, QuadraticAttenuation, quadraticAttenuation, float); + DEFINE_PROPERTY(PROP_EXPONENT, Exponent, exponent, float); + DEFINE_PROPERTY(PROP_CUTOFF, Cutoff, cutoff, float); + DEFINE_PROPERTY(PROP_LOCKED, Locked, locked, bool); + DEFINE_PROPERTY_REF(PROP_TEXTURES, Textures, textures, QString); + DEFINE_PROPERTY_REF_WITH_SETTER_AND_GETTER(PROP_ANIMATION_SETTINGS, AnimationSettings, animationSettings, QString); + DEFINE_PROPERTY_REF(PROP_USER_DATA, UserData, userData, QString); + DEFINE_PROPERTY_REF(PROP_TEXT, Text, text, QString); + DEFINE_PROPERTY(PROP_LINE_HEIGHT, LineHeight, lineHeight, float); + DEFINE_PROPERTY_REF(PROP_TEXT_COLOR, TextColor, textColor, xColor); + DEFINE_PROPERTY_REF(PROP_BACKGROUND_COLOR, BackgroundColor, backgroundColor, xColor); - // properties of all entities - EntityTypes::EntityType getType() const { return _type; } - - void setType(EntityTypes::EntityType type) { _type = type; } - - const glm::vec3& getPosition() const { return _position; } - /// set position in meter units, will be clamped to domain bounds - void setPosition(const glm::vec3& value) { _position = glm::clamp(value, 0.0f, (float)TREE_SCALE); _positionChanged = true; } - - - const glm::vec3& getDimensions() const { return _dimensions; } - void setDimensions(const glm::vec3& value) { _dimensions = value; _dimensionsChanged = true; } +public: float getMaxDimension() const { return glm::max(_dimensions.x, _dimensions.y, _dimensions.z); } - const glm::quat& getRotation() const { return _rotation; } - void setRotation(const glm::quat& rotation) { _rotation = rotation; _rotationChanged = true; } - - float getMass() const { return _mass; } - void setMass(float value) { _mass = value; _massChanged = true; } - - /// velocity in meters (0.0-1.0) per second - const glm::vec3& getVelocity() const { return _velocity; } - /// velocity in meters (0.0-1.0) per second - void setVelocity(const glm::vec3& value) { _velocity = value; _velocityChanged = true; } - - /// gravity in meters (0.0-TREE_SCALE) per second squared - const glm::vec3& getGravity() const { return _gravity; } - /// gravity in meters (0.0-TREE_SCALE) per second squared - void setGravity(const glm::vec3& value) { _gravity = value; _gravityChanged = true; } - - float getDamping() const { return _damping; } - void setDamping(float value) { _damping = value; _dampingChanged = true; } - - float getLifetime() const { return _lifetime; } /// get the lifetime in seconds for the entity - void setLifetime(float value) { _lifetime = value; _lifetimeChanged = true; } /// set the lifetime in seconds for the entity - - const QString& getUserData() const { return _userData; } - void setUserData(const QString& value) { _userData = value; _userDataChanged = true; } - float getAge() const { return (float)(usecTimestampNow() - _created) / (float)USECS_PER_SECOND; } quint64 getCreated() const { return _created; } void setCreated(quint64 usecTime) { _created = usecTime; } bool hasCreatedTime() const { return (_created != UNKNOWN_CREATED_TIME); } - - // NOTE: how do we handle _defaultSettings??? bool containsBoundsProperties() const { return (_positionChanged || _dimensionsChanged); } bool containsPositionChange() const { return _positionChanged; } bool containsDimensionsChange() const { return _dimensionsChanged; } - // TODO: this need to be more generic. for now, we're going to have the properties class support these as - // named getter/setters, but we want to move them to generic types... - // properties we want to move to just models and particles - xColor getColor() const { return _color; } - const QString& getModelURL() const { return _modelURL; } - const QString& getAnimationURL() const { return _animationURL; } - float getAnimationFrameIndex() const { return _animationFrameIndex; } - bool getAnimationIsPlaying() const { return _animationIsPlaying; } - float getAnimationFPS() const { return _animationFPS; } - QString getAnimationSettings() const; - float getGlowLevel() const { return _glowLevel; } float getLocalRenderAlpha() const { return _localRenderAlpha; } - const QString& getScript() const { return _script; } - - // model related properties - void setColor(const xColor& value) { _color = value; _colorChanged = true; } - void setModelURL(const QString& url) { _modelURL = url; _modelURLChanged = true; } - void setAnimationURL(const QString& url) { _animationURL = url; _animationURLChanged = true; } - void setAnimationFrameIndex(float value) { _animationFrameIndex = value; _animationFrameIndexChanged = true; } - void setAnimationIsPlaying(bool value) { _animationIsPlaying = value; _animationIsPlayingChanged = true; } - void setAnimationFPS(float value) { _animationFPS = value; _animationFPSChanged = true; } - void setAnimationSettings(const QString& value); - void setGlowLevel(float value) { _glowLevel = value; _glowLevelChanged = true; } void setLocalRenderAlpha(float value) { _localRenderAlpha = value; _localRenderAlphaChanged = true; } - void setScript(const QString& value) { _script = value; _scriptChanged = true; } - static bool encodeEntityEditPacket(PacketType command, EntityItemID id, const EntityItemProperties& properties, unsigned char* bufferOut, int sizeIn, int& sizeOut); @@ -222,23 +202,6 @@ public: static bool decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes, EntityItemID& entityID, EntityItemProperties& properties); - bool positionChanged() const { return _positionChanged; } - bool rotationChanged() const { return _rotationChanged; } - bool massChanged() const { return _massChanged; } - bool velocityChanged() const { return _velocityChanged; } - bool gravityChanged() const { return _gravityChanged; } - bool dampingChanged() const { return _dampingChanged; } - bool lifetimeChanged() const { return _lifetimeChanged; } - bool userDataChanged() const { return _userDataChanged; } - bool scriptChanged() const { return _scriptChanged; } - bool dimensionsChanged() const { return _dimensionsChanged; } - bool registrationPointChanged() const { return _registrationPointChanged; } - bool colorChanged() const { return _colorChanged; } - bool modelURLChanged() const { return _modelURLChanged; } - bool animationURLChanged() const { return _animationURLChanged; } - bool animationIsPlayingChanged() const { return _animationIsPlayingChanged; } - bool animationFrameIndexChanged() const { return _animationFrameIndexChanged; } - bool animationFPSChanged() const { return _animationFPSChanged; } bool glowLevelChanged() const { return _glowLevelChanged; } bool localRenderAlphaChanged() const { return _localRenderAlphaChanged; } @@ -246,167 +209,26 @@ public: void markAllChanged(); void setSittingPoints(const QVector& sittingPoints); - + 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::vec3& getAngularVelocity() const { return _angularVelocity; } - void setAngularVelocity(const glm::vec3& value) { _angularVelocity = value; _angularVelocityChanged = true; } - - float getAngularDamping() const { return _angularDamping; } - void setAngularDamping(float value) { _angularDamping = value; _angularDampingChanged = true; } - - bool getVisible() const { return _visible; } - void setVisible(bool value) { _visible = value; _visibleChanged = true; } - - bool getIgnoreForCollisions() const { return _ignoreForCollisions; } - void setIgnoreForCollisions(bool value) { _ignoreForCollisions = value; _ignoreForCollisionsChanged = true; } - - bool getCollisionsWillMove() const { return _collisionsWillMove; } - void setCollisionsWillMove(bool value) { _collisionsWillMove = value; _collisionsWillMoveChanged = true; } - - bool getIsSpotlight() const { return _isSpotlight; } - void setIsSpotlight(bool value) { _isSpotlight = value; _isSpotlightChanged = true; } - - xColor getDiffuseColor() const { return _diffuseColor; } - xColor getAmbientColor() const { return _ambientColor; } - xColor getSpecularColor() const { return _specularColor; } - - void setDiffuseColor(const xColor& value) { _diffuseColor = value; _diffuseColorChanged = true; } - void setAmbientColor(const xColor& value) { _ambientColor = value; _ambientColorChanged = true; } - void setSpecularColor(const xColor& value) { _specularColor = value; _specularColorChanged = true; } - - bool diffuseColorChanged() const { return _colorChanged; } - bool ambientColorChanged() const { return _ambientColorChanged; } - bool specularColorChanged() const { return _specularColorChanged; } - - float getConstantAttenuation() const { return _constantAttenuation; } - void setConstantAttenuation(float value) { _constantAttenuation = value; _constantAttenuationChanged = true; } - - float getLinearAttenuation() const { return _linearAttenuation; } - void setLinearAttenuation(float value) { _linearAttenuation = value; _linearAttenuationChanged = true; } - - float getQuadraticAttenuation() const { return _quadraticAttenuation; } - void setQuadraticAttenuation(float value) { _quadraticAttenuation = value; _quadraticAttenuationChanged = true; } - - float getExponent() const { return _exponent; } - void setExponent(float value) { _exponent = value; _exponentChanged = true; } - - float getCutoff() const { return _cutoff; } - void setCutoff(float value) { _cutoff = value; _cutoffChanged = true; } - - bool getLocked() const { return _locked; } - void setLocked(bool value) { _locked = value; _lockedChanged = true; } - bool lockedChanged() const { return _lockedChanged; } - - const QString& getTextures() const { return _textures; } - void setTextures(const QString& value) { _textures = value; _texturesChanged = true; } - const QStringList& getTextureNames() const { return _textureNames; } void setTextureNames(const QStringList& value) { _textureNames = value; } - - void setLastEdited(quint64 usecTime) { _lastEdited = usecTime; } + private: - QUuid _id; bool _idSet; quint64 _lastEdited; quint64 _created; - EntityTypes::EntityType _type; - void setType(const QString& typeName) { _type = EntityTypes::getEntityTypeFromName(typeName); } - - glm::vec3 _position; - glm::vec3 _dimensions; - glm::quat _rotation; - float _mass; - glm::vec3 _velocity; - glm::vec3 _gravity; - float _damping; - float _lifetime; - QString _userData; - QString _script; - glm::vec3 _registrationPoint; - glm::vec3 _angularVelocity; - float _angularDamping; - bool _visible; - bool _ignoreForCollisions; - bool _collisionsWillMove; - bool _positionChanged; - bool _dimensionsChanged; - bool _rotationChanged; - bool _massChanged; - bool _velocityChanged; - bool _gravityChanged; - bool _dampingChanged; - bool _lifetimeChanged; - bool _userDataChanged; - bool _scriptChanged; - bool _registrationPointChanged; - bool _angularVelocityChanged; - bool _angularDampingChanged; - bool _visibleChanged; - bool _ignoreForCollisionsChanged; - bool _collisionsWillMoveChanged; - - // TODO: this need to be more generic. for now, we're going to have the properties class support these as - // named getter/setters, but we want to move them to generic types... - xColor _color; - QString _modelURL; - QString _animationURL; - bool _animationIsPlaying; - float _animationFrameIndex; - float _animationFPS; - QString _animationSettings; float _glowLevel; float _localRenderAlpha; - bool _isSpotlight; - - bool _colorChanged; - bool _modelURLChanged; - bool _animationURLChanged; - bool _animationIsPlayingChanged; - bool _animationFrameIndexChanged; - bool _animationFPSChanged; - bool _animationSettingsChanged; bool _glowLevelChanged; bool _localRenderAlphaChanged; - bool _isSpotlightChanged; - - xColor _diffuseColor; - xColor _ambientColor; - xColor _specularColor; - float _constantAttenuation; - float _linearAttenuation; - float _quadraticAttenuation; - float _exponent; - float _cutoff; - bool _locked; - QString _textures; - - bool _diffuseColorChanged; - bool _ambientColorChanged; - bool _specularColorChanged; - bool _constantAttenuationChanged; - bool _linearAttenuationChanged; - bool _quadraticAttenuationChanged; - bool _exponentChanged; - bool _cutoffChanged; - bool _lockedChanged; - bool _texturesChanged; - - DEFINE_PROPERTY_REF(PROP_TEXT, Text, text, QString); - DEFINE_PROPERTY(PROP_LINE_HEIGHT, LineHeight, lineHeight, float); - DEFINE_PROPERTY_REF(PROP_TEXT_COLOR, TextColor, textColor, xColor); - DEFINE_PROPERTY_REF(PROP_BACKGROUND_COLOR, BackgroundColor, backgroundColor, xColor); - -private: bool _defaultSettings; // NOTE: The following are pseudo client only properties. They are only used in clients which can access @@ -420,6 +242,11 @@ QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const Enti void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties); +// define these inline here so the macros work +inline void EntityItemProperties::setPosition(const glm::vec3& value) + { _position = glm::clamp(value, 0.0f, (float)TREE_SCALE); _positionChanged = true; } + + inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { debug << "EntityItemProperties[" << "\n" << " position:" << properties.getPosition() << "in meters" << "\n" diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index f61d89dbd2..8ad444a975 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -267,19 +267,39 @@ #define DEFINE_PROPERTY(P, N, n, T) \ public: \ - T get##N() const { return _##n; } \ - void set##N(T value) { _##n = value; _##n##Changed = true; } \ + T get##N() const { return _##n; } \ + void set##N(T value) { _##n = value; _##n##Changed = true; } \ + bool n##Changed() const { return _##n##Changed; } \ private: \ - T _##n; \ - bool _##n##Changed; + T _##n; \ + bool _##n##Changed; #define DEFINE_PROPERTY_REF(P, N, n, T) \ public: \ - const T& get##N() const { return _##n; } \ - void set##N(const T& value) { _##n = value; _##n##Changed = true; } \ + const T& get##N() const { return _##n; } \ + void set##N(const T& value) { _##n = value; _##n##Changed = true; } \ + bool n##Changed() const { return _##n##Changed; } \ private: \ - T _##n; \ - bool _##n##Changed; + T _##n; \ + bool _##n##Changed; + +#define DEFINE_PROPERTY_REF_WITH_SETTER(P, N, n, T) \ + public: \ + const T& get##N() const { return _##n; } \ + void set##N(const T& value); \ + bool n##Changed() const; \ + private: \ + T _##n; \ + bool _##n##Changed; + +#define DEFINE_PROPERTY_REF_WITH_SETTER_AND_GETTER(P, N, n, T) \ + public: \ + T get##N() const; \ + void set##N(const T& value); \ + bool n##Changed() const; \ + private: \ + T _##n; \ + bool _##n##Changed; From 60908ef0403ca42b07d167570d3987e8d43073ce Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 22:15:28 -0800 Subject: [PATCH 10/13] fix some warnings --- interface/src/entities/RenderableTextEntityItem.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/interface/src/entities/RenderableTextEntityItem.cpp b/interface/src/entities/RenderableTextEntityItem.cpp index 771962ecc6..f790f6fa35 100644 --- a/interface/src/entities/RenderableTextEntityItem.cpp +++ b/interface/src/entities/RenderableTextEntityItem.cpp @@ -20,8 +20,6 @@ #include "EntityTreeRenderer.h" #include "RenderableTextEntityItem.h" -const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 }; -const float DEFAULT_MARGIN = 0.1f; const int FIXED_FONT_POINT_SIZE = 40; const float LINE_SCALE_RATIO = 1.2f; @@ -33,7 +31,6 @@ void RenderableTextEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderableTextEntityItem::render"); assert(getType() == EntityTypes::Text); glm::vec3 position = getPositionInMeters(); - glm::vec3 center = getCenter() * (float)TREE_SCALE; glm::vec3 dimensions = getDimensions() * (float)TREE_SCALE; glm::vec3 halfDimensions = dimensions / 2.0f; glm::quat rotation = getRotation(); From f0cd258a13e4947ec13e9c96299f3baa7068047b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 22:51:04 -0800 Subject: [PATCH 11/13] test --- libraries/entities/src/EntityItemProperties.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 642e24beec..5984ae9c65 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -110,6 +110,15 @@ class EntityItemProperties { friend class SphereEntityItem; // TODO: consider removing this friend relationship and use public methods friend class LightEntityItem; // TODO: consider removing this friend relationship and use public methods friend class TextEntityItem; // TODO: consider removing this friend relationship and use public methods +private: + QUuid _id; + bool _idSet; + quint64 _lastEdited; + quint64 _created; + EntityTypes::EntityType _type; + void setType(const QString& typeName) { _type = EntityTypes::getEntityTypeFromName(typeName); } + + public: EntityItemProperties(); virtual ~EntityItemProperties(); @@ -218,13 +227,6 @@ public: private: - QUuid _id; - bool _idSet; - quint64 _lastEdited; - quint64 _created; - EntityTypes::EntityType _type; - void setType(const QString& typeName) { _type = EntityTypes::getEntityTypeFromName(typeName); } - float _glowLevel; float _localRenderAlpha; bool _glowLevelChanged; From 28fc6d15f49d137f1e1f0d2afceb48b1a9e9fe23 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 14 Nov 2014 22:53:29 -0800 Subject: [PATCH 12/13] test --- libraries/entities/src/EntityItemProperties.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 5984ae9c65..642e24beec 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -110,15 +110,6 @@ class EntityItemProperties { friend class SphereEntityItem; // TODO: consider removing this friend relationship and use public methods friend class LightEntityItem; // TODO: consider removing this friend relationship and use public methods friend class TextEntityItem; // TODO: consider removing this friend relationship and use public methods -private: - QUuid _id; - bool _idSet; - quint64 _lastEdited; - quint64 _created; - EntityTypes::EntityType _type; - void setType(const QString& typeName) { _type = EntityTypes::getEntityTypeFromName(typeName); } - - public: EntityItemProperties(); virtual ~EntityItemProperties(); @@ -227,6 +218,13 @@ public: private: + QUuid _id; + bool _idSet; + quint64 _lastEdited; + quint64 _created; + EntityTypes::EntityType _type; + void setType(const QString& typeName) { _type = EntityTypes::getEntityTypeFromName(typeName); } + float _glowLevel; float _localRenderAlpha; bool _glowLevelChanged; From 42e8d4d3778b260a1226ad640db12d453049effd Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 15 Nov 2014 20:24:00 -0800 Subject: [PATCH 13/13] fix warnings in overlays --- interface/src/ui/overlays/BillboardOverlay.cpp | 12 +++++++----- interface/src/ui/overlays/ImageOverlay.cpp | 11 ++++++----- interface/src/ui/overlays/ModelOverlay.cpp | 6 +++--- interface/src/ui/overlays/Overlay.cpp | 18 ++++++++++-------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index dee5eceab7..5fbad7839a 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -26,12 +26,14 @@ BillboardOverlay::BillboardOverlay() : BillboardOverlay::BillboardOverlay(const BillboardOverlay* billboardOverlay) : Base3DOverlay(billboardOverlay), - _newTextureNeeded(true), - _scale(billboardOverlay->_scale), - _isFacingAvatar(billboardOverlay->_isFacingAvatar), - _fromImage(billboardOverlay->_fromImage), _url(billboardOverlay->_url), - _billboard(billboardOverlay->_billboard) + _billboard(billboardOverlay->_billboard), + _size(), + _billboardTexture(), + _newTextureNeeded(true), + _fromImage(billboardOverlay->_fromImage), + _scale(billboardOverlay->_scale), + _isFacingAvatar(billboardOverlay->_isFacingAvatar) { } diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index fad19be292..f903dfe19c 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -29,12 +29,13 @@ ImageOverlay::ImageOverlay() : ImageOverlay::ImageOverlay(const ImageOverlay* imageOverlay) : Overlay2D(imageOverlay), - _textureID(0), - _textureBound(false), - _wantClipFromImage(false), - _renderImage(imageOverlay->_renderImage), _imageURL(imageOverlay->_imageURL), - _textureImage(imageOverlay->_textureImage) + _textureImage(imageOverlay->_textureImage), + _textureID(0), + _fromImage(), + _renderImage(imageOverlay->_renderImage), + _textureBound(false), + _wantClipFromImage(false) { } diff --git a/interface/src/ui/overlays/ModelOverlay.cpp b/interface/src/ui/overlays/ModelOverlay.cpp index 3594d7e828..60049e0b3b 100644 --- a/interface/src/ui/overlays/ModelOverlay.cpp +++ b/interface/src/ui/overlays/ModelOverlay.cpp @@ -26,10 +26,10 @@ ModelOverlay::ModelOverlay(const ModelOverlay* modelOverlay) : Base3DOverlay(modelOverlay), _model(), _modelTextures(QVariantMap()), - _scale(modelOverlay->_scale), - _updateModel(false), _url(modelOverlay->_url), - _rotation(modelOverlay->_rotation) + _rotation(modelOverlay->_rotation), + _scale(modelOverlay->_scale), + _updateModel(false) { _model.init(); if (_url.isValid()) { diff --git a/interface/src/ui/overlays/Overlay.cpp b/interface/src/ui/overlays/Overlay.cpp index 549152ded0..fd7aaca717 100644 --- a/interface/src/ui/overlays/Overlay.cpp +++ b/interface/src/ui/overlays/Overlay.cpp @@ -41,20 +41,22 @@ Overlay::Overlay() : Overlay::Overlay(const Overlay* overlay) : _parent(NULL), + _isLoaded(overlay->_isLoaded), _alpha(overlay->_alpha), - _lastPulseUpdate(usecTimestampNow()), - _alphaPulse(overlay->_alphaPulse), - _anchor(overlay->_anchor), - _color(overlay->_color), - _colorPulse(overlay->_colorPulse), _glowLevel(overlay->_glowLevel), - _glowLevelPulse(overlay->_glowLevelPulse), - _pulseDirection(overlay->_pulseDirection), + _pulse(overlay->_pulse), _pulseMax(overlay->_pulseMax), _pulseMin(overlay->_pulseMin), _pulsePeriod(overlay->_pulsePeriod), + _pulseDirection(overlay->_pulseDirection), + _lastPulseUpdate(usecTimestampNow()), + _glowLevelPulse(overlay->_glowLevelPulse), + _alphaPulse(overlay->_alphaPulse), + _colorPulse(overlay->_colorPulse), + _color(overlay->_color), _visible(overlay->_visible), - _isLoaded(overlay->_isLoaded) + _anchor(overlay->_anchor), + _scriptEngine(NULL) { }