From a9c2a6e0486c2dde52ec59ad42cce456c9f4bc28 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 20 Apr 2015 18:17:21 -0700 Subject: [PATCH 1/7] another attempt at zones starting from box --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 4 +++- libraries/entities/src/EntityItemProperties.h | 1 + libraries/entities/src/EntityTypes.cpp | 5 +++-- libraries/entities/src/EntityTypes.h | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index da972b3843..132feff7e3 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -30,9 +30,10 @@ #include "RenderableBoxEntityItem.h" #include "RenderableLightEntityItem.h" #include "RenderableModelEntityItem.h" +#include "RenderableParticleEffectEntityItem.h" #include "RenderableSphereEntityItem.h" #include "RenderableTextEntityItem.h" -#include "RenderableParticleEffectEntityItem.h" +#include "RenderableZoneEntityItem.h" #include "EntitiesRendererLogging.h" @@ -56,6 +57,7 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf REGISTER_ENTITY_TYPE_WITH_FACTORY(Light, RenderableLightEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Text, RenderableTextEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(ParticleEffect, RenderableParticleEffectEntityItem::factory) + REGISTER_ENTITY_TYPE_WITH_FACTORY(Zone, RenderableZoneEntityItem::factory) _currentHoverOverEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID _currentClickingOnEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 7de0fc0e8b..0bc0bcedc7 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -137,6 +137,7 @@ class EntityItemProperties { 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 friend class ParticleEffectEntityItem; // TODO: consider removing this friend relationship and use public methods + friend class ZoneEntityItem; // TODO: consider removing this friend relationship and use public methods public: EntityItemProperties(); virtual ~EntityItemProperties(); diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index 55e9512f53..f0baa3da93 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -21,9 +21,10 @@ #include "BoxEntityItem.h" #include "LightEntityItem.h" #include "ModelEntityItem.h" +#include "ParticleEffectEntityItem.h" #include "SphereEntityItem.h" #include "TextEntityItem.h" -#include "ParticleEffectEntityItem.h" +#include "ZoneEntityItem.h" QMap EntityTypes::_typeToNameMap; QMap EntityTypes::_nameToTypeMap; @@ -39,7 +40,7 @@ REGISTER_ENTITY_TYPE(Sphere) REGISTER_ENTITY_TYPE(Light) REGISTER_ENTITY_TYPE(Text) REGISTER_ENTITY_TYPE(ParticleEffect) - +REGISTER_ENTITY_TYPE(Zone) const QString& EntityTypes::getEntityTypeName(EntityType entityType) { QMap::iterator matchedTypeName = _typeToNameMap.find(entityType); diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index e1f8e876bb..28cfe2278b 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -36,7 +36,8 @@ public: Light, Text, ParticleEffect, - LAST = ParticleEffect + Zone, + LAST = Zone } EntityType; static const QString& getEntityTypeName(EntityType entityType); From 8ce4cb628a9c74015bc559e6915f1e966d1f5859 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 20 Apr 2015 18:18:01 -0700 Subject: [PATCH 2/7] another attempt at zones starting from box --- .../src/RenderableZoneEntityItem.cpp | 50 +++++++ .../src/RenderableZoneEntityItem.h | 29 +++++ libraries/entities/src/ZoneEntityItem.cpp | 122 ++++++++++++++++++ libraries/entities/src/ZoneEntityItem.h | 62 +++++++++ 4 files changed, 263 insertions(+) create mode 100644 libraries/entities-renderer/src/RenderableZoneEntityItem.cpp create mode 100644 libraries/entities-renderer/src/RenderableZoneEntityItem.h create mode 100644 libraries/entities/src/ZoneEntityItem.cpp create mode 100644 libraries/entities/src/ZoneEntityItem.h diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp new file mode 100644 index 0000000000..6a16404f89 --- /dev/null +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -0,0 +1,50 @@ +// +// RenderableZoneEntityItem.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 + +#include +#include + +#include "RenderableZoneEntityItem.h" + +EntityItem* RenderableZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { + return new RenderableZoneEntityItem(entityID, properties); +} + +void RenderableZoneEntityItem::render(RenderArgs* args) { + PerformanceTimer perfTimer("RenderableZoneEntityItem::render"); + assert(getType() == EntityTypes::Zone); + glm::vec3 position = getPosition(); + glm::vec3 center = getCenter(); + glm::vec3 dimensions = getDimensions(); + glm::quat rotation = getRotation(); + + const float MAX_COLOR = 255.0f; + + glm::vec4 cubeColor(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, + getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); + + 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); + glPushMatrix(); + glm::vec3 positionToCenter = center - position; + glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); + glScalef(dimensions.x, dimensions.y, dimensions.z); + DependencyManager::get()->renderWireCube(1.0f, cubeColor); + glPopMatrix(); + glPopMatrix(); + +}; diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h new file mode 100644 index 0000000000..b05fd0e3f8 --- /dev/null +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -0,0 +1,29 @@ +// +// RenderableZoneEntityItem.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_RenderableZoneEntityItem_h +#define hifi_RenderableZoneEntityItem_h + +#include + +class RenderableZoneEntityItem : public ZoneEntityItem { +public: + static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + + RenderableZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + ZoneEntityItem(entityItemID, properties) + { } + + virtual void render(RenderArgs* args); +}; + + +#endif // hifi_RenderableZoneEntityItem_h diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp new file mode 100644 index 0000000000..a22c22ce5d --- /dev/null +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -0,0 +1,122 @@ +// +// ZoneEntityItem.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 "ZoneEntityItem.h" +#include "EntityTree.h" +#include "EntitiesLogging.h" +#include "EntityTreeElement.h" + +/* +bool ZoneEntityItem::_zonesArePickable = false; + +const xColor ZoneEntityItem::DEFAULT_SUN_sunColor = { 255, 255, 255 }; +const float ZoneEntityItem::DEFAULT_SUN_INTENSITY = 0.1f; +const float ZoneEntityItem::DEFAULT_SUN_AMBIENT_INTENSITY = 0.0f; +const bool ZoneEntityItem::DEFAULT_SUN_USE_EARTH_MODEL = true; +const float ZoneEntityItem::DEFAULT_SUN_APPARENT_LATITUDE = 37.777f; +const float ZoneEntityItem::DEFAULT_SUN_APPARENT_LONGITUDE = 122.407f; +const float ZoneEntityItem::DEFAULT_SUN_APPARENT_ALTITUDE = 0.03f; +const quint16 ZoneEntityItem::DEFAULT_SUN_APPARENT_DAY = 60; +const float ZoneEntityItem::DEFAULT_SUN_APPARENT_HOUR = 12.0f; +const glm::vec3 ZoneEntityItem::DEFAULT_SUN_DIRECTION = { 0.0f, -1.0f, 0.0f }; +*/ + +EntityItem* ZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { + EntityItem* result = new ZoneEntityItem(entityID, properties); + return result; +} + +ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + EntityItem(entityItemID) +{ + _type = EntityTypes::Zone; + _created = properties.getCreated(); + setProperties(properties); +} + +EntityItemProperties ZoneEntityItem::getProperties() const { + EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class + + properties._color = getXColor(); + properties._colorChanged = false; + + properties._glowLevel = getGlowLevel(); + properties._glowLevelChanged = false; + + return properties; +} + +bool ZoneEntityItem::setProperties(const EntityItemProperties& properties) { + bool somethingChanged = false; + somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class + + SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); + + if (somethingChanged) { + bool wantDebug = false; + if (wantDebug) { + uint64_t now = usecTimestampNow(); + int elapsed = now - getLastEdited(); + qCDebug(entities) << "ZoneEntityItem::setProperties() AFTER update... edited AGO=" << elapsed << + "now=" << now << " getLastEdited()=" << getLastEdited(); + } + setLastEdited(properties._lastEdited); + } + return somethingChanged; +} + +int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { + + int bytesRead = 0; + const unsigned char* dataAt = data; + + READ_ENTITY_PROPERTY_COLOR(PROP_COLOR, _sunColor); + + return bytesRead; +} + + +// TODO: eventually only include properties changed since the params.lastViewFrustumSent time +EntityPropertyFlags ZoneEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { + EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); + requestedProperties += PROP_COLOR; + return requestedProperties; +} + +void ZoneEntityItem::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_COLOR, appendColor, getColor()); +} + +void ZoneEntityItem::debugDump() const { + quint64 now = usecTimestampNow(); + qCDebug(entities) << " BOX EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " color:" << _sunColor[0] << "," << _sunColor[1] << "," << _sunColor[2]; + qCDebug(entities) << " position:" << debugTreeVector(_position); + qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); + qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); +} + diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h new file mode 100644 index 0000000000..4b0b960697 --- /dev/null +++ b/libraries/entities/src/ZoneEntityItem.h @@ -0,0 +1,62 @@ +// +// ZoneEntityItem.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_ZoneEntityItem_h +#define hifi_ZoneEntityItem_h + +#include "EntityItem.h" + +class ZoneEntityItem : public EntityItem { +public: + static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + + ZoneEntityItem(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); + + // 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); + + const rgbColor& getColor() const { return _sunColor; } + xColor getXColor() const { xColor color = { _sunColor[RED_INDEX], _sunColor[GREEN_INDEX], _sunColor[BLUE_INDEX] }; return color; } + + void setColor(const rgbColor& value) { memcpy(_sunColor, value, sizeof(_sunColor)); } + void setColor(const xColor& value) { + _sunColor[RED_INDEX] = value.red; + _sunColor[GREEN_INDEX] = value.green; + _sunColor[BLUE_INDEX] = value.blue; + } + + virtual ShapeType getShapeType() const { return SHAPE_TYPE_BOX; } + + virtual void debugDump() const; + +protected: + rgbColor _sunColor; +}; + +#endif // hifi_ZoneEntityItem_h From e436c9521206336b842152ce32783fbf913bff09 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 21 Apr 2015 14:36:13 -0700 Subject: [PATCH 3/7] first cut at reworking zones --- .../src/EntityTreeRenderer.cpp | 114 ++++++++++++++++- .../src/EntityTreeRenderer.h | 28 ++++- .../src/RenderableZoneEntityItem.cpp | 6 +- .../entities/src/EntityItemProperties.cpp | 85 ++++++++++++- libraries/entities/src/EntityItemProperties.h | 39 +++++- .../entities/src/EntityItemPropertiesMacros.h | 9 ++ libraries/entities/src/ZoneEntityItem.cpp | 117 ++++++++++++++---- libraries/entities/src/ZoneEntityItem.h | 69 +++++++++-- libraries/networking/src/PacketHeaders.cpp | 2 +- libraries/networking/src/PacketHeaders.h | 3 +- 10 files changed, 421 insertions(+), 51 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 132feff7e3..adf7fb4e29 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "EntityTreeRenderer.h" @@ -35,7 +36,7 @@ #include "RenderableTextEntityItem.h" #include "RenderableZoneEntityItem.h" #include "EntitiesRendererLogging.h" - +#include "ZoneEntityItem.h" EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterface* viewState, AbstractScriptingServicesInterface* scriptingServices) : @@ -395,10 +396,106 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::R _tree->lockForRead(); - _tree->recurseTreeWithOperation(renderOperation, &args); -// Model::RenderMode modelRenderMode = renderMode == RenderArgs::SHADOW_RENDER_MODE - // ? RenderArgs::SHADOW_RENDER_MODE : RenderArgs::DEFAULT_RENDER_MODE; + // Implement some kind of a stack/union mechanism here... + // + // * As you enter a zone (A), you use it's properties + // * if already in a zone, and you enter the union of that zone and a new zone (A + B) + // you use the settings of the new zone (B) you entered.. but remember that you were previously + // in zone A + // * if you enter a new zone and are in the union of 3 zones (A+B+C) then use zone C and remember + // you were most recently in B + _lastZones = _currentZones; + _currentZones.clear(); + _tree->recurseTreeWithOperation(renderOperation, &args); + const ZoneEntityItem* bestZone = NULL; + + if (_currentZones.empty()) { + // if we're not in any current zone, then we can completely erase our zoneHistory + _zoneHistory.clear(); + } else { + // we're in some zone... check to see if we've changed zones.. + QSet newZones = _currentZones - _lastZones; + + if (!newZones.empty()) { + // we just entered a new zone, so we want to make a shift + EntityItemID theNewZone = *(newZones.begin()); // random we don't care, if it's one, then this works. + _zoneHistory << _currentZone; // remember the single zone we used to be in. + _currentZone = theNewZone; // change to our new zone + + // do something to remove any item of _zoneHistory that is not in _currentZones + QStack newHistory; + QStack::iterator i = _zoneHistory.begin(); + while(i != _zoneHistory.end()) { + EntityItemID zoneID = *i; + if (_currentZones.contains(zoneID)) { + newHistory << zoneID; + } + ++i; + } + + _zoneHistory = newHistory; + bestZone = dynamic_cast( + static_cast(_tree)->findEntityByEntityItemID(_currentZone)); + } else { + + if (_currentZones.contains(_currentZone)) { + // No change in zone, keep the current zone + bestZone = dynamic_cast( + static_cast(_tree)->findEntityByEntityItemID(_currentZone)); + } else { + if (!_zoneHistory.empty()) { + _currentZone = _zoneHistory.pop(); + bestZone = dynamic_cast( + static_cast(_tree)->findEntityByEntityItemID(_currentZone)); + } + + } + + } + } + + QSharedPointer scene = DependencyManager::get(); + + if (bestZone) { + if (!_hasPreviousZone) { + _previousKeyLightColor = scene->getKeyLightColor(); + _previousKeyLightIntensity = scene->getKeyLightIntensity(); + _previousKeyLightAmbientIntensity = scene->getKeyLightAmbientIntensity(); + _previousKeyLightDirection = scene->getKeyLightDirection(); + _previousUseEarthModel = scene->isStageEarthSunModelEnabled(); + _previousStageLongitude = scene->getStageLocationLongitude(); + _previousStageLatitude = scene->getStageLocationLatitude(); + _previousStageAltitude = scene->getStageLocationAltitude(); + _previousStageHour = scene->getStageDayTime(); + _previousStageDay = scene->getStageYearTime(); + _hasPreviousZone = true; + } + scene->setKeyLightColor(bestZone->getKeyLightColorVec3()); + scene->setKeyLightIntensity(bestZone->getKeyLightIntensity()); + scene->setKeyLightAmbientIntensity(bestZone->getKeyLightAmbientIntensity()); + scene->setKeyLightDirection(bestZone->getKeyLightDirection()); + scene->setStageEarthSunModelEnable(bestZone->getUseEarthModel()); + scene->setStageLocation(bestZone->getStageLongitude(), bestZone->getStageLatitude(), + bestZone->getStageAltitude()); + scene->setStageDayTime(bestZone->getStageHour()); + scene->setStageYearTime(bestZone->getStageDay()); + + } else { + _currentZone = EntityItemID(); // clear out current zone + if (_hasPreviousZone) { + scene->setKeyLightColor(_previousKeyLightColor); + scene->setKeyLightIntensity(_previousKeyLightIntensity); + scene->setKeyLightAmbientIntensity(_previousKeyLightAmbientIntensity); + scene->setKeyLightDirection(_previousKeyLightDirection); + scene->setStageEarthKeyLightModelEnable(_previousUseEarthModel); + scene->setStageLocation(_previousStageLongitude, _previousStageLatitude, + _previousStageAltitude); + scene->setStageDayTime(_previousStageHour); + scene->setStageYearTime(_previousStageDay); + _hasPreviousZone = false; + } + } // we must call endScene while we still have the tree locked so that no one deletes a model // on us while rendering the scene @@ -598,6 +695,15 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) EntityItem* entityItem = entityItems[i]; if (entityItem->isVisible()) { + + // Zone Entities are a special case we handle here... + if (entityItem->getType() == EntityTypes::Zone) { + if (entityItem->contains(args->_viewFrustum->getPosition())) { + _currentZones << entityItem->getEntityItemID(); + } + } + // NOTE: we might not want to render zones here... + // render entityItem AABox entityBox = entityItem->getAABox(); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index e8d70c9df9..fd979fc9f9 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -12,18 +12,20 @@ #ifndef hifi_EntityTreeRenderer_h #define hifi_EntityTreeRenderer_h +#include +#include + #include #include // for RayToEntityIntersectionResult #include #include #include +class AbstractScriptingServicesInterface; +class AbstractViewStateInterface; class Model; class ScriptEngine; -class AbstractViewStateInterface; -class AbstractScriptingServicesInterface; - -class ScriptEngine; +class ZoneEntityItem; class EntityScriptDetails { public: @@ -164,6 +166,24 @@ private: bool _shuttingDown = false; QMultiMap _waitingOnPreload; + + QSet _lastZones; + QSet _currentZones; + QStack _zoneHistory; + EntityItemID _currentZone; + + bool _hasPreviousZone = false; + + glm::vec3 _previousKeyLightColor; + float _previousKeyLightIntensity; + float _previousKeyLightAmbientIntensity; + glm::vec3 _previousKeyLightDirection; + bool _previousStageSunModelEnabled; + float _previousStageLongitude; + float _previousStageLatitude; + float _previousStageAltitude; + float _previousStageHour; + int _previousStageDay; }; diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 6a16404f89..d13fa37681 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -32,8 +32,8 @@ void RenderableZoneEntityItem::render(RenderArgs* args) { const float MAX_COLOR = 255.0f; - glm::vec4 cubeColor(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, - getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); + glm::vec4 cubeColor(_keyLightColor[RED_INDEX] / MAX_COLOR, _keyLightColor[GREEN_INDEX] / MAX_COLOR, + _keyLightColor[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); glPushMatrix(); glTranslatef(position.x, position.y, position.z); @@ -47,4 +47,6 @@ void RenderableZoneEntityItem::render(RenderArgs* args) { glPopMatrix(); glPopMatrix(); + //debugDump(); + }; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 8a25d59f26..50856f53db 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -18,14 +18,14 @@ #include #include +#include "EntitiesLogging.h" #include "EntityItem.h" #include "EntityItemProperties.h" #include "EntityItemPropertiesDefaults.h" #include "ModelEntityItem.h" -#include "TextEntityItem.h" -#include "EntitiesLogging.h" #include "ParticleEffectEntityItem.h" - +#include "TextEntityItem.h" +#include "ZoneEntityItem.h" EntityPropertyList PROP_LAST_ITEM = (EntityPropertyList)(PROP_AFTER_LAST_ITEM - 1); @@ -76,6 +76,16 @@ EntityItemProperties::EntityItemProperties() : CONSTRUCT_PROPERTY(localGravity, ParticleEffectEntityItem::DEFAULT_LOCAL_GRAVITY), CONSTRUCT_PROPERTY(particleRadius, ParticleEffectEntityItem::DEFAULT_PARTICLE_RADIUS), CONSTRUCT_PROPERTY(marketplaceID, ENTITY_ITEM_DEFAULT_MARKETPLACE_ID), + CONSTRUCT_PROPERTY(keyLightColor, ZoneEntityItem::DEFAULT_KEYLIGHT_COLOR), + CONSTRUCT_PROPERTY(keyLightIntensity, ZoneEntityItem::DEFAULT_KEYLIGHT_INTENSITY), + CONSTRUCT_PROPERTY(keyLightAmbientIntensity, ZoneEntityItem::DEFAULT_KEYLIGHT_AMBIENT_INTENSITY), + CONSTRUCT_PROPERTY(keyLightDirection, ZoneEntityItem::DEFAULT_KEYLIGHT_DIRECTION), + CONSTRUCT_PROPERTY(stageSunModelEnabled, ZoneEntityItem::DEFAULT_STAGE_SUN_MODEL_ENABLED), + CONSTRUCT_PROPERTY(stageLatitude, ZoneEntityItem::DEFAULT_STAGE_LATITUDE), + CONSTRUCT_PROPERTY(stageLongitude, ZoneEntityItem::DEFAULT_STAGE_LONGITUDE), + CONSTRUCT_PROPERTY(stageAltitude, ZoneEntityItem::DEFAULT_STAGE_ALTITUDE), + CONSTRUCT_PROPERTY(stageDay, ZoneEntityItem::DEFAULT_STAGE_DAY), + CONSTRUCT_PROPERTY(stageHour, ZoneEntityItem::DEFAULT_STAGE_HOUR), _id(UNKNOWN_ENTITY_ID), _idSet(false), @@ -268,6 +278,16 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_LOCAL_GRAVITY, localGravity); CHECK_PROPERTY_CHANGE(PROP_PARTICLE_RADIUS, particleRadius); CHECK_PROPERTY_CHANGE(PROP_MARKETPLACE_ID, marketplaceID); + CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_COLOR, keyLightColor); + CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_INTENSITY, keyLightIntensity); + CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_AMBIENT_INTENSITY, keyLightAmbientIntensity); + CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_DIRECTION, keyLightDirection); + CHECK_PROPERTY_CHANGE(PROP_STAGE_SUN_MODEL_ENABLED, stageSunModelEnabled); + CHECK_PROPERTY_CHANGE(PROP_STAGE_LATITUDE, stageLatitude); + CHECK_PROPERTY_CHANGE(PROP_STAGE_LONGITUDE, stageLongitude); + CHECK_PROPERTY_CHANGE(PROP_STAGE_ALTITUDE, stageAltitude); + CHECK_PROPERTY_CHANGE(PROP_STAGE_DAY, stageDay); + CHECK_PROPERTY_CHANGE(PROP_STAGE_HOUR, stageHour); return changedProperties; } @@ -334,6 +354,17 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons COPY_PROPERTY_TO_QSCRIPTVALUE(particleRadius); COPY_PROPERTY_TO_QSCRIPTVALUE(marketplaceID); + COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR(keyLightColor); + COPY_PROPERTY_TO_QSCRIPTVALUE(keyLightIntensity); + COPY_PROPERTY_TO_QSCRIPTVALUE(keyLightAmbientIntensity); + COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(keyLightDirection); + COPY_PROPERTY_TO_QSCRIPTVALUE(stageSunModelEnabled); + COPY_PROPERTY_TO_QSCRIPTVALUE(stageLatitude); + COPY_PROPERTY_TO_QSCRIPTVALUE(stageLongitude); + COPY_PROPERTY_TO_QSCRIPTVALUE(stageAltitude); + COPY_PROPERTY_TO_QSCRIPTVALUE(stageDay); + COPY_PROPERTY_TO_QSCRIPTVALUE(stageHour); + // Sitting properties support QScriptValue sittingPoints = engine->newObject(); for (int i = 0; i < _sittingPoints.size(); ++i) { @@ -418,6 +449,17 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(particleRadius, setParticleRadius); COPY_PROPERTY_FROM_QSCRIPTVALUE_STRING(marketplaceID, setMarketplaceID); + COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(keyLightColor, setKeyLightColor); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(keyLightIntensity, setKeyLightIntensity); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(keyLightAmbientIntensity, setKeyLightAmbientIntensity); + COPY_PROPERTY_FROM_QSCRIPTVALUE_VEC3(keyLightDirection, setKeyLightDirection); + COPY_PROPERTY_FROM_QSCRIPTVALUE_BOOL(stageSunModelEnabled, setStageSunModelEnabled); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(stageLatitude, setStageLatitude); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(stageLongitude, setStageLongitude); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(stageAltitude, setStageAltitude); + COPY_PROPERTY_FROM_QSCRIPTVALUE_INT(stageDay, setStageDay); + COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(stageHour, setStageHour); + _lastEdited = usecTimestampNow(); } @@ -603,6 +645,19 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_LOCAL_GRAVITY, appendValue, properties.getLocalGravity()); APPEND_ENTITY_PROPERTY(PROP_PARTICLE_RADIUS, appendValue, properties.getParticleRadius()); } + + if (properties.getType() == EntityTypes::Zone) { + APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, appendColor, properties.getKeyLightColor()); + APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, appendValue, properties.getKeyLightIntensity()); + APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, appendValue, properties.getKeyLightAmbientIntensity()); + APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, appendValue, properties.getKeyLightDirection()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_SUN_MODEL_ENABLED, appendValue, properties.getStageSunModelEnabled()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_LATITUDE, appendValue, properties.getStageLatitude()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_LONGITUDE, appendValue, properties.getStageLongitude()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_ALTITUDE, appendValue, properties.getStageAltitude()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_DAY, appendValue, properties.getStageDay()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_HOUR, appendValue, properties.getStageHour()); + } APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, appendValue, properties.getMarketplaceID()); } @@ -836,6 +891,19 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LOCAL_GRAVITY, float, setLocalGravity); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_PARTICLE_RADIUS, float, setParticleRadius); } + + if (properties.getType() == EntityTypes::Zone) { + READ_ENTITY_PROPERTY_COLOR_TO_PROPERTIES(PROP_KEYLIGHT_COLOR, setKeyLightColor); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_KEYLIGHT_INTENSITY, float, setKeyLightIntensity); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_KEYLIGHT_AMBIENT_INTENSITY, float, setKeyLightAmbientIntensity); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_KEYLIGHT_DIRECTION, glm::vec3, setKeyLightDirection); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STAGE_SUN_MODEL_ENABLED, bool, setStageSunModelEnabled); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STAGE_LATITUDE, float, setStageLatitude); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STAGE_LONGITUDE, float, setStageLongitude); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STAGE_ALTITUDE, float, setStageAltitude); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STAGE_DAY, quint16, setStageDay); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STAGE_HOUR, float, setStageHour); + } READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_MARKETPLACE_ID, setMarketplaceID); @@ -923,6 +991,17 @@ void EntityItemProperties::markAllChanged() { _particleRadiusChanged = true; _marketplaceIDChanged = true; + + _keyLightColorChanged = true; + _keyLightIntensityChanged = true; + _keyLightAmbientIntensityChanged = true; + _keyLightDirectionChanged = true; + _stageSunModelEnabledChanged = true; + _stageLatitudeChanged = true; + _stageLongitudeChanged = true; + _stageAltitudeChanged = true; + _stageDayChanged = true; + _stageHourChanged = true; } /// The maximum bounding cube for the entity, independent of it's rotation. diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 0bc0bcedc7..9a68abd73e 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -97,6 +97,17 @@ enum EntityPropertyList { PROP_MARKETPLACE_ID, PROP_ACCELERATION, PROP_SIMULATOR_ID, + + PROP_KEYLIGHT_COLOR, + PROP_KEYLIGHT_INTENSITY, + PROP_KEYLIGHT_AMBIENT_INTENSITY, + PROP_KEYLIGHT_DIRECTION, + PROP_STAGE_SUN_MODEL_ENABLED, + PROP_STAGE_LATITUDE, + PROP_STAGE_LONGITUDE, + PROP_STAGE_ALTITUDE, + PROP_STAGE_DAY, + PROP_STAGE_HOUR, //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties ABOVE this line @@ -113,7 +124,22 @@ enum EntityPropertyList { PROP_TEXT = PROP_MODEL_URL, PROP_LINE_HEIGHT = PROP_ANIMATION_URL, PROP_BACKGROUND_COLOR = PROP_ANIMATION_FPS, - PROP_COLLISION_MODEL_URL_OLD_VERSION = PROP_ANIMATION_FPS + 1 + PROP_COLLISION_MODEL_URL_OLD_VERSION = PROP_ANIMATION_FPS + 1, + + // Aliases/Piggyback properties for Zones. These properties intentionally reuse the enum values for + // other properties + /* + PROP_KEYLIGHT_COLOR = PROP_COLOR, + PROP_KEYLIGHT_INTENSITY = PROP_INTENSITY, + PROP_KEYLIGHT_AMBIENT_INTENSITY = PROP_CUTOFF, + PROP_KEYLIGHT_DIRECTION = PROP_EXPONENT, + PROP_STAGE_SUN_MODEL_ENABLED = PROP_IS_SPOTLIGHT, + PROP_STAGE_LATITUDE = PROP_DIFFUSE_COLOR_UNUSED, + PROP_STAGE_LONGITUDE = PROP_AMBIENT_COLOR_UNUSED, + PROP_STAGE_ALTITUDE = PROP_SPECULAR_COLOR_UNUSED, + PROP_STAGE_DAY = PROP_LINEAR_ATTENUATION_UNUSED, + PROP_STAGE_HOUR = PROP_QUADRATIC_ATTENUATION_UNUSED, + */ // WARNING!!! DO NOT ADD PROPS_xxx here unless you really really meant to.... Add them UP above }; @@ -215,6 +241,17 @@ public: DEFINE_PROPERTY(PROP_LOCAL_GRAVITY, LocalGravity, localGravity, float); DEFINE_PROPERTY(PROP_PARTICLE_RADIUS, ParticleRadius, particleRadius, float); DEFINE_PROPERTY_REF(PROP_MARKETPLACE_ID, MarketplaceID, marketplaceID, QString); + DEFINE_PROPERTY_REF(PROP_KEYLIGHT_COLOR, KeyLightColor, keyLightColor, xColor); + DEFINE_PROPERTY(PROP_KEYLIGHT_INTENSITY, KeyLightIntensity, keyLightIntensity, float); + DEFINE_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, KeyLightAmbientIntensity, keyLightAmbientIntensity, float); + DEFINE_PROPERTY_REF(PROP_KEYLIGHT_DIRECTION, KeyLightDirection, keyLightDirection, glm::vec3); + DEFINE_PROPERTY(PROP_STAGE_SUN_MODEL_ENABLED, StageSunModelEnabled, stageSunModelEnabled, bool); + DEFINE_PROPERTY(PROP_STAGE_LATITUDE, StageLatitude, stageLatitude, float); + DEFINE_PROPERTY(PROP_STAGE_LONGITUDE, StageLongitude, stageLongitude, float); + DEFINE_PROPERTY(PROP_STAGE_ALTITUDE, StageAltitude, stageAltitude, float); + DEFINE_PROPERTY(PROP_STAGE_DAY, StageDay, stageDay, quint16); + DEFINE_PROPERTY(PROP_STAGE_HOUR, StageHour, stageHour, float); + public: float getMaxDimension() const { return glm::max(_dimensions.x, _dimensions.y, _dimensions.z); } diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index e3e54f5bc8..753ac793ac 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -189,6 +189,15 @@ } \ } +#define COPY_PROPERTY_FROM_QSCRIPTVALUE_INT(P, S) \ + QScriptValue P = object.property(#P); \ + if (P.isValid()) { \ + int newValue = P.toVariant().toInt(); \ + if (_defaultSettings || newValue != _##P) { \ + S(newValue); \ + } \ + } + #define COPY_PROPERTY_FROM_QSCRIPTVALUE_BOOL(P, S) \ QScriptValue P = object.property(#P); \ if (P.isValid()) { \ diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index a22c22ce5d..e0fe238c57 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -19,20 +19,18 @@ #include "EntitiesLogging.h" #include "EntityTreeElement.h" -/* bool ZoneEntityItem::_zonesArePickable = false; -const xColor ZoneEntityItem::DEFAULT_SUN_sunColor = { 255, 255, 255 }; -const float ZoneEntityItem::DEFAULT_SUN_INTENSITY = 0.1f; -const float ZoneEntityItem::DEFAULT_SUN_AMBIENT_INTENSITY = 0.0f; -const bool ZoneEntityItem::DEFAULT_SUN_USE_EARTH_MODEL = true; -const float ZoneEntityItem::DEFAULT_SUN_APPARENT_LATITUDE = 37.777f; -const float ZoneEntityItem::DEFAULT_SUN_APPARENT_LONGITUDE = 122.407f; -const float ZoneEntityItem::DEFAULT_SUN_APPARENT_ALTITUDE = 0.03f; -const quint16 ZoneEntityItem::DEFAULT_SUN_APPARENT_DAY = 60; -const float ZoneEntityItem::DEFAULT_SUN_APPARENT_HOUR = 12.0f; -const glm::vec3 ZoneEntityItem::DEFAULT_SUN_DIRECTION = { 0.0f, -1.0f, 0.0f }; -*/ +const xColor ZoneEntityItem::DEFAULT_KEYLIGHT_COLOR = { 255, 255, 255 }; +const float ZoneEntityItem::DEFAULT_KEYLIGHT_INTENSITY = 1.0f; +const float ZoneEntityItem::DEFAULT_KEYLIGHT_AMBIENT_INTENSITY = 0.5f; +const glm::vec3 ZoneEntityItem::DEFAULT_KEYLIGHT_DIRECTION = { 0.0f, -1.0f, 0.0f }; +const bool ZoneEntityItem::DEFAULT_STAGE_SUN_MODEL_ENABLED = false; +const float ZoneEntityItem::DEFAULT_STAGE_LATITUDE = 37.777f; +const float ZoneEntityItem::DEFAULT_STAGE_LONGITUDE = 122.407f; +const float ZoneEntityItem::DEFAULT_STAGE_ALTITUDE = 0.03f; +const quint16 ZoneEntityItem::DEFAULT_STAGE_DAY = 60; +const float ZoneEntityItem::DEFAULT_STAGE_HOUR = 12.0f; EntityItem* ZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItem* result = new ZoneEntityItem(entityID, properties); @@ -44,17 +42,37 @@ ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID, const EntityIte { _type = EntityTypes::Zone; _created = properties.getCreated(); + + _keyLightColor[RED_INDEX] = DEFAULT_KEYLIGHT_COLOR.red; + _keyLightColor[GREEN_INDEX] = DEFAULT_KEYLIGHT_COLOR.green; + _keyLightColor[BLUE_INDEX] = DEFAULT_KEYLIGHT_COLOR.blue; + + _keyLightIntensity = DEFAULT_KEYLIGHT_INTENSITY; + _keyLightAmbientIntensity = DEFAULT_KEYLIGHT_AMBIENT_INTENSITY; + _keyLightDirection = DEFAULT_KEYLIGHT_DIRECTION; + _stageSunModelEnabled = DEFAULT_STAGE_SUN_MODEL_ENABLED; + _stageLatitude = DEFAULT_STAGE_LATITUDE; + _stageLongitude = DEFAULT_STAGE_LONGITUDE; + _stageAltitude = DEFAULT_STAGE_ALTITUDE; + _stageDay = DEFAULT_STAGE_DAY; + _stageHour = DEFAULT_STAGE_HOUR; + setProperties(properties); } EntityItemProperties ZoneEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class - properties._color = getXColor(); - properties._colorChanged = false; - - properties._glowLevel = getGlowLevel(); - properties._glowLevelChanged = false; + COPY_ENTITY_PROPERTY_TO_PROPERTIES(keyLightColor, getKeyLightColor); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(keyLightIntensity, getKeyLightIntensity); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(keyLightAmbientIntensity, getKeyLightAmbientIntensity); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(keyLightDirection, getKeyLightDirection); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(stageSunModelEnabled, getStageSunModelEnabled); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(stageLatitude, getStageLatitude); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(stageLongitude, getStageLongitude); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(stageAltitude, getStageAltitude); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(stageDay, getStageDay); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(stageHour, getStageHour); return properties; } @@ -63,7 +81,16 @@ bool ZoneEntityItem::setProperties(const EntityItemProperties& properties) { bool somethingChanged = false; somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class - SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(keyLightColor, setKeyLightColor); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(keyLightIntensity, setKeyLightIntensity); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(keyLightAmbientIntensity, setKeyLightAmbientIntensity); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(keyLightDirection, setKeyLightDirection); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(stageSunModelEnabled, setStageSunModelEnabled); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(stageLatitude, setStageLatitude); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(stageLongitude, setStageLongitude); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(stageAltitude, setStageAltitude); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(stageDay, setStageDay); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(stageHour, setStageHour); if (somethingChanged) { bool wantDebug = false; @@ -85,7 +112,16 @@ int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesRead = 0; const unsigned char* dataAt = data; - READ_ENTITY_PROPERTY_COLOR(PROP_COLOR, _sunColor); + READ_ENTITY_PROPERTY_COLOR(PROP_KEYLIGHT_COLOR, _keyLightColor); + READ_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, float, _keyLightIntensity); + READ_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, float, _keyLightAmbientIntensity); + READ_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, glm::vec3, _keyLightDirection); + READ_ENTITY_PROPERTY(PROP_STAGE_SUN_MODEL_ENABLED, bool, _stageSunModelEnabled); + READ_ENTITY_PROPERTY(PROP_STAGE_LATITUDE, float, _stageLatitude); + READ_ENTITY_PROPERTY(PROP_STAGE_LONGITUDE, float, _stageLongitude); + READ_ENTITY_PROPERTY(PROP_STAGE_ALTITUDE, float, _stageAltitude); + READ_ENTITY_PROPERTY(PROP_STAGE_DAY, quint16, _stageDay); + READ_ENTITY_PROPERTY(PROP_STAGE_HOUR, float, _stageHour); return bytesRead; } @@ -94,7 +130,18 @@ int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, // TODO: eventually only include properties changed since the params.lastViewFrustumSent time EntityPropertyFlags ZoneEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); - requestedProperties += PROP_COLOR; + + requestedProperties += PROP_KEYLIGHT_COLOR; + requestedProperties += PROP_KEYLIGHT_INTENSITY; + requestedProperties += PROP_KEYLIGHT_AMBIENT_INTENSITY; + requestedProperties += PROP_KEYLIGHT_DIRECTION; + requestedProperties += PROP_STAGE_SUN_MODEL_ENABLED; + requestedProperties += PROP_STAGE_LATITUDE; + requestedProperties += PROP_STAGE_LONGITUDE; + requestedProperties += PROP_STAGE_ALTITUDE; + requestedProperties += PROP_STAGE_DAY; + requestedProperties += PROP_STAGE_HOUR; + return requestedProperties; } @@ -108,15 +155,33 @@ void ZoneEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits bool successPropertyFits = true; - APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor()); + APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, appendColor, _keyLightColor); + APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, appendValue, getKeyLightIntensity()); + APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, appendValue, getKeyLightAmbientIntensity()); + APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, appendValue, getKeyLightDirection()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_SUN_MODEL_ENABLED, appendValue, getStageSunModelEnabled()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_LATITUDE, appendValue, getStageLatitude()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_LONGITUDE, appendValue, getStageLongitude()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_ALTITUDE, appendValue, getStageAltitude()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_DAY, appendValue, getStageDay()); + APPEND_ENTITY_PROPERTY(PROP_STAGE_HOUR, appendValue, getStageHour()); } void ZoneEntityItem::debugDump() const { quint64 now = usecTimestampNow(); - qCDebug(entities) << " BOX EntityItem id:" << getEntityItemID() << "---------------------------------------------"; - qCDebug(entities) << " color:" << _sunColor[0] << "," << _sunColor[1] << "," << _sunColor[2]; - qCDebug(entities) << " position:" << debugTreeVector(_position); - qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); - qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); + qCDebug(entities) << " ZoneEntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " keyLightColor:" << _keyLightColor[0] << "," << _keyLightColor[1] << "," << _keyLightColor[2]; + qCDebug(entities) << " position:" << debugTreeVector(_position); + qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); + qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); + qCDebug(entities) << " _keyLightIntensity:" << _keyLightIntensity; + qCDebug(entities) << " _keyLightAmbientIntensity:" << _keyLightAmbientIntensity; + qCDebug(entities) << " _keyLightDirection:" << _keyLightDirection; + qCDebug(entities) << " _stageSunModelEnabled:" << _stageSunModelEnabled; + qCDebug(entities) << " _stageLatitude:" << _stageLatitude; + qCDebug(entities) << " _stageLongitude:" << _stageLongitude; + qCDebug(entities) << " _stageAltitude:" << _stageAltitude; + qCDebug(entities) << " _stageDay:" << _stageDay; + qCDebug(entities) << " _stageHour:" << _stageHour; } diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index 4b0b960697..5d22b2d8bd 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -41,22 +41,73 @@ public: ReadBitstreamToTreeParams& args, EntityPropertyFlags& propertyFlags, bool overwriteLocalData); - const rgbColor& getColor() const { return _sunColor; } - xColor getXColor() const { xColor color = { _sunColor[RED_INDEX], _sunColor[GREEN_INDEX], _sunColor[BLUE_INDEX] }; return color; } + virtual ShapeType getShapeType() const { return SHAPE_TYPE_BOX; } - void setColor(const rgbColor& value) { memcpy(_sunColor, value, sizeof(_sunColor)); } - void setColor(const xColor& value) { - _sunColor[RED_INDEX] = value.red; - _sunColor[GREEN_INDEX] = value.green; - _sunColor[BLUE_INDEX] = value.blue; + xColor getKeyLightColor() const { xColor color = { _keyLightColor[RED_INDEX], _keyLightColor[GREEN_INDEX], _keyLightColor[BLUE_INDEX] }; return color; } + void setKeyLightColor(const xColor& value) { + _keyLightColor[RED_INDEX] = value.red; + _keyLightColor[GREEN_INDEX] = value.green; + _keyLightColor[BLUE_INDEX] = value.blue; } - virtual ShapeType getShapeType() const { return SHAPE_TYPE_BOX; } + float getKeyLightIntensity() const { return _keyLightIntensity; } + void setKeyLightIntensity(float value) { _keyLightIntensity = value; } + + float getKeyLightAmbientIntensity() const { return _keyLightAmbientIntensity; } + void setKeyLightAmbientIntensity(float value) { _keyLightAmbientIntensity = value; } + + const glm::vec3& getKeyLightDirection() const { return _keyLightDirection; } + void setKeyLightDirection(const glm::vec3& value) { _keyLightDirection = value; } + + bool getStageSunModelEnabled() const { return _stageSunModelEnabled; } + void setStageSunModelEnabled(bool value) { _stageSunModelEnabled = value; } + + float getStageLatitude() const { return _stageLatitude; } + void setStageLatitude(float value) { _stageLatitude = value; } + + float getStageLongitude() const { return _stageLongitude; } + void setStageLongitude(float value) { _stageLongitude = value; } + + float getStageAltitude() const { return _stageAltitude; } + void setStageAltitude(float value) { _stageAltitude = value; } + + uint16_t getStageDay() const { return _stageDay; } + void setStageDay(uint16_t value) { _stageDay = value; } + + float getStageHour() const { return _stageHour; } + void setStageHour(float value) { _stageHour = value; } + + static bool getZonesArePickable() { return _zonesArePickable; } + static void setZonesArePickable(bool value) { _zonesArePickable = value; } + virtual void debugDump() const; + static const xColor DEFAULT_KEYLIGHT_COLOR; + static const float DEFAULT_KEYLIGHT_INTENSITY; + static const float DEFAULT_KEYLIGHT_AMBIENT_INTENSITY; + static const glm::vec3 DEFAULT_KEYLIGHT_DIRECTION; + static const bool DEFAULT_STAGE_SUN_MODEL_ENABLED; + static const float DEFAULT_STAGE_LATITUDE; + static const float DEFAULT_STAGE_LONGITUDE; + static const float DEFAULT_STAGE_ALTITUDE; + static const quint16 DEFAULT_STAGE_DAY; + static const float DEFAULT_STAGE_HOUR; + protected: - rgbColor _sunColor; + // properties of the "sun" in the zone + rgbColor _keyLightColor; + float _keyLightIntensity; + float _keyLightAmbientIntensity; + glm::vec3 _keyLightDirection; + bool _stageSunModelEnabled; + float _stageLatitude; + float _stageLongitude; + float _stageAltitude; + uint16_t _stageDay; + float _stageHour; + + static bool _zonesArePickable; }; #endif // hifi_ZoneEntityItem_h diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index 52153f9e83..8f0cee10cf 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -74,7 +74,7 @@ PacketVersion versionForPacketType(PacketType type) { return 1; case PacketTypeEntityAddOrEdit: case PacketTypeEntityData: - return VERSION_ENTITIES_HAVE_ACCELERATION; + return VERSION_ENTITIES_ZONE_ENTITIES_EXIST; case PacketTypeEntityErase: return 2; case PacketTypeAudioStreamStats: diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index 9fb14854aa..0f89aa9423 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -119,6 +119,7 @@ PacketType packetTypeForPacket(const char* packet); int arithmeticCodingValueFromBuffer(const char* checkValue); int numBytesArithmeticCodingFromBuffer(const char* checkValue); +const PacketVersion VERSION_OCTREE_HAS_FILE_BREAKS = 1; const PacketVersion VERSION_ENTITIES_HAVE_ANIMATION = 1; const PacketVersion VERSION_ROOT_ELEMENT_HAS_DATA = 2; const PacketVersion VERSION_ENTITIES_SUPPORT_SPLIT_MTU = 3; @@ -135,6 +136,6 @@ const PacketVersion VERSION_ENTITIES_HAS_COLLISION_MODEL = 12; const PacketVersion VERSION_ENTITIES_HAS_MARKETPLACE_ID_DAMAGED = 13; const PacketVersion VERSION_ENTITIES_HAS_MARKETPLACE_ID = 14; const PacketVersion VERSION_ENTITIES_HAVE_ACCELERATION = 15; -const PacketVersion VERSION_OCTREE_HAS_FILE_BREAKS = 1; +const PacketVersion VERSION_ENTITIES_ZONE_ENTITIES_EXIST = 16; #endif // hifi_PacketHeaders_h From 4ce451f9845856186f081773d355b6b61755e504 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 21 Apr 2015 14:55:45 -0700 Subject: [PATCH 4/7] wire up zone rendering again --- .../entities-renderer/src/EntityTreeRenderer.cpp | 6 +++--- libraries/entities/src/ZoneEntityItem.h | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index adf7fb4e29..59f7aa0f5c 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -463,7 +463,7 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::R _previousKeyLightIntensity = scene->getKeyLightIntensity(); _previousKeyLightAmbientIntensity = scene->getKeyLightAmbientIntensity(); _previousKeyLightDirection = scene->getKeyLightDirection(); - _previousUseEarthModel = scene->isStageEarthSunModelEnabled(); + _previousStageSunModelEnabled = scene->isStageSunModelEnabled(); _previousStageLongitude = scene->getStageLocationLongitude(); _previousStageLatitude = scene->getStageLocationLatitude(); _previousStageAltitude = scene->getStageLocationAltitude(); @@ -475,7 +475,7 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::R scene->setKeyLightIntensity(bestZone->getKeyLightIntensity()); scene->setKeyLightAmbientIntensity(bestZone->getKeyLightAmbientIntensity()); scene->setKeyLightDirection(bestZone->getKeyLightDirection()); - scene->setStageEarthSunModelEnable(bestZone->getUseEarthModel()); + scene->setStageSunModelEnable(bestZone->getStageSunModelEnabled()); scene->setStageLocation(bestZone->getStageLongitude(), bestZone->getStageLatitude(), bestZone->getStageAltitude()); scene->setStageDayTime(bestZone->getStageHour()); @@ -488,7 +488,7 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::R scene->setKeyLightIntensity(_previousKeyLightIntensity); scene->setKeyLightAmbientIntensity(_previousKeyLightAmbientIntensity); scene->setKeyLightDirection(_previousKeyLightDirection); - scene->setStageEarthKeyLightModelEnable(_previousUseEarthModel); + scene->setStageSunModelEnable(_previousStageSunModelEnabled); scene->setStageLocation(_previousStageLongitude, _previousStageLatitude, _previousStageAltitude); scene->setStageDayTime(_previousStageHour); diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index 5d22b2d8bd..8f1b15d174 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -41,7 +41,10 @@ public: ReadBitstreamToTreeParams& args, EntityPropertyFlags& propertyFlags, bool overwriteLocalData); - virtual ShapeType getShapeType() const { return SHAPE_TYPE_BOX; } + // NOTE: Apparently if you begin to return a shape type, then the physics system will prevent an avatar + // from penetrating the walls of the entity. This fact will likely be important to Clement as he works + // on better defining the shape/volume of a zone. + //virtual ShapeType getShapeType() const { return SHAPE_TYPE_BOX; } xColor getKeyLightColor() const { xColor color = { _keyLightColor[RED_INDEX], _keyLightColor[GREEN_INDEX], _keyLightColor[BLUE_INDEX] }; return color; } void setKeyLightColor(const xColor& value) { @@ -49,6 +52,15 @@ public: _keyLightColor[GREEN_INDEX] = value.green; _keyLightColor[BLUE_INDEX] = value.blue; } + + glm::vec3 getKeyLightColorVec3() const { + const quint8 MAX_COLOR = 255; + glm::vec3 color = { _keyLightColor[RED_INDEX] / MAX_COLOR, + _keyLightColor[GREEN_INDEX] / MAX_COLOR, + _keyLightColor[BLUE_INDEX] / MAX_COLOR }; + return color; + } + float getKeyLightIntensity() const { return _keyLightIntensity; } void setKeyLightIntensity(float value) { _keyLightIntensity = value; } From 8366dd02a0f1c0f3bdad779dae359c5a607c0645 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 21 Apr 2015 15:03:04 -0700 Subject: [PATCH 5/7] remove RenderableZoneEntityItem class since zones don't render like other entities --- .../src/EntityTreeRenderer.cpp | 52 +++++++++---------- .../src/RenderableZoneEntityItem.cpp | 52 ------------------- .../src/RenderableZoneEntityItem.h | 29 ----------- 3 files changed, 25 insertions(+), 108 deletions(-) delete mode 100644 libraries/entities-renderer/src/RenderableZoneEntityItem.cpp delete mode 100644 libraries/entities-renderer/src/RenderableZoneEntityItem.h diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 59f7aa0f5c..c14a821a38 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -34,7 +34,6 @@ #include "RenderableParticleEffectEntityItem.h" #include "RenderableSphereEntityItem.h" #include "RenderableTextEntityItem.h" -#include "RenderableZoneEntityItem.h" #include "EntitiesRendererLogging.h" #include "ZoneEntityItem.h" @@ -58,7 +57,6 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf REGISTER_ENTITY_TYPE_WITH_FACTORY(Light, RenderableLightEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Text, RenderableTextEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(ParticleEffect, RenderableParticleEffectEntityItem::factory) - REGISTER_ENTITY_TYPE_WITH_FACTORY(Zone, RenderableZoneEntityItem::factory) _currentHoverOverEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID _currentClickingOnEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID @@ -696,42 +694,42 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) if (entityItem->isVisible()) { - // Zone Entities are a special case we handle here... + // NOTE: Zone Entities are a special case we handle here... Zones don't render + // like other entity types. So we will skip the normal rendering tests if (entityItem->getType() == EntityTypes::Zone) { if (entityItem->contains(args->_viewFrustum->getPosition())) { _currentZones << entityItem->getEntityItemID(); } - } - // NOTE: we might not want to render zones here... - - // render entityItem - AABox entityBox = entityItem->getAABox(); + } else { + // render entityItem + AABox entityBox = entityItem->getAABox(); - // TODO: some entity types (like lights) might want to be rendered even - // when they are outside of the view frustum... - float distance = args->_viewFrustum->distanceToCamera(entityBox.calcCenter()); + // TODO: some entity types (like lights) might want to be rendered even + // when they are outside of the view frustum... + float distance = args->_viewFrustum->distanceToCamera(entityBox.calcCenter()); - bool outOfView = args->_viewFrustum->boxInFrustum(entityBox) == ViewFrustum::OUTSIDE; - if (!outOfView) { - bool bigEnoughToRender = _viewState->shouldRenderMesh(entityBox.getLargestDimension(), distance); + bool outOfView = args->_viewFrustum->boxInFrustum(entityBox) == ViewFrustum::OUTSIDE; + if (!outOfView) { + bool bigEnoughToRender = _viewState->shouldRenderMesh(entityBox.getLargestDimension(), distance); - if (bigEnoughToRender) { - renderProxies(entityItem, args); + if (bigEnoughToRender) { + renderProxies(entityItem, args); - Glower* glower = NULL; - if (entityItem->getGlowLevel() > 0.0f) { - glower = new Glower(entityItem->getGlowLevel()); - } - entityItem->render(args); - args->_itemsRendered++; - if (glower) { - delete glower; + Glower* glower = NULL; + if (entityItem->getGlowLevel() > 0.0f) { + glower = new Glower(entityItem->getGlowLevel()); + } + entityItem->render(args); + args->_itemsRendered++; + if (glower) { + delete glower; + } + } else { + args->_itemsTooSmall++; } } else { - args->_itemsTooSmall++; + args->_itemsOutOfView++; } - } else { - args->_itemsOutOfView++; } } } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp deleted file mode 100644 index d13fa37681..0000000000 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// -// RenderableZoneEntityItem.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 - -#include -#include - -#include "RenderableZoneEntityItem.h" - -EntityItem* RenderableZoneEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - return new RenderableZoneEntityItem(entityID, properties); -} - -void RenderableZoneEntityItem::render(RenderArgs* args) { - PerformanceTimer perfTimer("RenderableZoneEntityItem::render"); - assert(getType() == EntityTypes::Zone); - glm::vec3 position = getPosition(); - glm::vec3 center = getCenter(); - glm::vec3 dimensions = getDimensions(); - glm::quat rotation = getRotation(); - - const float MAX_COLOR = 255.0f; - - glm::vec4 cubeColor(_keyLightColor[RED_INDEX] / MAX_COLOR, _keyLightColor[GREEN_INDEX] / MAX_COLOR, - _keyLightColor[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); - - 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); - glPushMatrix(); - glm::vec3 positionToCenter = center - position; - glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); - glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderWireCube(1.0f, cubeColor); - glPopMatrix(); - glPopMatrix(); - - //debugDump(); - -}; diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h deleted file mode 100644 index b05fd0e3f8..0000000000 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// RenderableZoneEntityItem.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_RenderableZoneEntityItem_h -#define hifi_RenderableZoneEntityItem_h - -#include - -class RenderableZoneEntityItem : public ZoneEntityItem { -public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); - - RenderableZoneEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : - ZoneEntityItem(entityItemID, properties) - { } - - virtual void render(RenderArgs* args); -}; - - -#endif // hifi_RenderableZoneEntityItem_h From 486ab044a0b6065136b63d1509092e8ac8d99f4f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 21 Apr 2015 15:16:46 -0700 Subject: [PATCH 6/7] use piggyback properties to save on property bit space --- libraries/entities/src/EntityItemProperties.h | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 9a68abd73e..27b9adbc1b 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -98,23 +98,11 @@ enum EntityPropertyList { PROP_ACCELERATION, PROP_SIMULATOR_ID, - PROP_KEYLIGHT_COLOR, - PROP_KEYLIGHT_INTENSITY, - PROP_KEYLIGHT_AMBIENT_INTENSITY, - PROP_KEYLIGHT_DIRECTION, - PROP_STAGE_SUN_MODEL_ENABLED, - PROP_STAGE_LATITUDE, - PROP_STAGE_LONGITUDE, - PROP_STAGE_ALTITUDE, - PROP_STAGE_DAY, - PROP_STAGE_HOUR, - //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties ABOVE this line PROP_AFTER_LAST_ITEM, //////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////// // WARNING! Do not add props here unless you intentionally mean to reuse PROP_ indexes // @@ -127,8 +115,8 @@ enum EntityPropertyList { PROP_COLLISION_MODEL_URL_OLD_VERSION = PROP_ANIMATION_FPS + 1, // Aliases/Piggyback properties for Zones. These properties intentionally reuse the enum values for - // other properties - /* + // other properties which will never overlap with each other. We do this so that we don't have to expand + // the size of the properties bitflags mask PROP_KEYLIGHT_COLOR = PROP_COLOR, PROP_KEYLIGHT_INTENSITY = PROP_INTENSITY, PROP_KEYLIGHT_AMBIENT_INTENSITY = PROP_CUTOFF, @@ -139,7 +127,7 @@ enum EntityPropertyList { PROP_STAGE_ALTITUDE = PROP_SPECULAR_COLOR_UNUSED, PROP_STAGE_DAY = PROP_LINEAR_ATTENUATION_UNUSED, PROP_STAGE_HOUR = PROP_QUADRATIC_ATTENUATION_UNUSED, - */ + // WARNING!!! DO NOT ADD PROPS_xxx here unless you really really meant to.... Add them UP above }; From ac81e3e84781d5717ff983380f1f5136ed0f3a9a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 22 Apr 2015 11:27:35 -0700 Subject: [PATCH 7/7] added example script --- .../example/entities/zoneEntityExample.js | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 examples/example/entities/zoneEntityExample.js diff --git a/examples/example/entities/zoneEntityExample.js b/examples/example/entities/zoneEntityExample.js new file mode 100644 index 0000000000..84d87d1370 --- /dev/null +++ b/examples/example/entities/zoneEntityExample.js @@ -0,0 +1,69 @@ +// +// zoneEntityExample.js +// examples +// +// Created by Brad Hefta-Gaub on 4/16/15. +// Copyright 2015 High Fidelity, Inc. +// +// This is an example script that demonstrates creating and editing a entity +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; + +var count = 0; +var stopAfter = 1000; + +var zoneEntityA = Entities.addEntity({ + type: "Zone", + position: { x: 5, y: 5, z: 5 }, + dimensions: { x: 10, y: 10, z: 10 }, + keyLightColor: { red: 255, green: 0, blue: 0 }, + stageSunModelEnabled: false, + keyLightDirection: { x: 0, y: -1.0, z: 0 } +}); + +print("zoneEntityA:" + zoneEntityA); + +var zoneEntityB = Entities.addEntity({ + type: "Zone", + position: { x: 1, y: 1, z: 21 }, + dimensions: { x: 2, y: 2, z: 2 }, + keyLightColor: { red: 0, green: 255, blue: 0 }, + keyLightIntensity: 0.9, + stageLatitude: 37.777, + stageLongitude: 122.407, + stageAltitude: 0.03, + stageDay: 60, + stageHour: 12, + stageSunModelEnabled: true +}); + +print("zoneEntityB:" + zoneEntityB); + + +var zoneEntityC = Entities.addEntity({ + type: "Zone", + position: { x: 5, y: 5, z: 15 }, + dimensions: { x: 10, y: 10, z: 10 }, + keyLightColor: { red: 0, green: 0, blue: 255 }, + keyLightIntensity: 0.75, + keyLightDirection: { x: 0, y: 0, z: -1 }, + stageSunModelEnabled: false +}); + +print("zoneEntityC:" + zoneEntityC); + + +// register the call back so it fires before each data send +Script.update.connect(function(deltaTime) { + // stop it... + if (count >= stopAfter) { + print("calling Script.stop()"); + Script.stop(); + } + count++; +}); +