This commit is contained in:
Clément Brisset 2015-05-07 18:39:51 +01:00
commit 8997879b02
16 changed files with 434 additions and 35 deletions

View file

@ -0,0 +1,60 @@
//
// zoneSkyboxExample.js
// examples
//
// Created by Brad Hefta-Gaub on 4/16/15.
// Copyright 2015 High Fidelity, Inc.
//
// This is an example script that demonstrates creating a zone using the atmosphere features
//
// 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 = 600;
var zoneEntityA = Entities.addEntity({
type: "Zone",
position: { x: 1000, y: 1000, z: 1000},
dimensions: { x: 2000, y: 2000, z: 2000 },
keyLightColor: { red: 255, green: 0, blue: 0 },
stageSunModelEnabled: false,
shapeType: "sphere",
backgroundMode: "skybox",
atmosphere: {
center: { x: 1000, y: 0, z: 1000},
innerRadius: 1000.0,
outerRadius: 1025.0,
rayleighScattering: 0.0025,
mieScattering: 0.0010,
scatteringWavelengths: { x: 0.650, y: 0.570, z: 0.475 },
hasStars: false
},
skybox: {
color: { red: 255, green: 0, blue: 255 },
url: ""
},
stageLatitude: 37.777,
stageLongitude: 122.407,
stageAltitude: 0.03,
stageDay: 60,
stageHour: 0,
stageSunModelEnabled: true
});
var props = Entities.getEntityProperties(zoneEntityA);
print(JSON.stringify(props));
// 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++;
});

View file

@ -445,7 +445,22 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode,
data.setSunBrightness(sunBrightness);
_viewState->overrideEnvironmentData(data);
scene->getSkyStage()->setBackgroundMode(model::SunSkyStage::SKY_DOME);
} else {
_viewState->endOverrideEnvironmentData();
if (_bestZone->getBackgroundMode() == BACKGROUND_MODE_SKYBOX) {
auto stage = scene->getSkyStage();
stage->getSkybox()->setColor(_bestZone->getSkyboxProperties().getColorVec3());
if (_bestZone->getSkyboxProperties().getURL().isEmpty()) {
stage->getSkybox()->clearCubemap();
} else {
stage->getSkybox()->clearCubemap(); // NOTE: this should be changed to do something to set the cubemap
}
stage->setBackgroundMode(model::SunSkyStage::SKY_BOX);
}
}
} else {
if (_hasPreviousZone) {
scene->setKeyLightColor(_previousKeyLightColor);
@ -460,6 +475,7 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode,
_hasPreviousZone = false;
}
_viewState->endOverrideEnvironmentData();
scene->getSkyStage()->setBackgroundMode(model::SunSkyStage::SKY_DOME);
}
// we must call endScene while we still have the tree locked so that no one deletes a model

View file

@ -26,13 +26,13 @@ AtmospherePropertyGroup::AtmospherePropertyGroup() {
}
void AtmospherePropertyGroup::copyToScriptValue(QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_VEC3(Atmosphere, Center, center);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, InnerRadius, innerRadius);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, OuterRadius, outerRadius);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, MieScattering, mieScattering);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, RayleighScattering, rayleighScattering);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_VEC3(Atmosphere, ScatteringWavelengths, scatteringWavelengths);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, HasStars, hasStars);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_VEC3(Atmosphere, atmosphere, Center, center);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, atmosphere, InnerRadius, innerRadius);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, atmosphere, OuterRadius, outerRadius);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, atmosphere, MieScattering, mieScattering);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, atmosphere, RayleighScattering, rayleighScattering);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_VEC3(Atmosphere, atmosphere, ScatteringWavelengths, scatteringWavelengths);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, atmosphere, HasStars, hasStars);
}
void AtmospherePropertyGroup::copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) {

View file

@ -28,6 +28,7 @@
#include "ZoneEntityItem.h"
AtmospherePropertyGroup EntityItemProperties::_staticAtmosphere;
SkyboxPropertyGroup EntityItemProperties::_staticSkybox;
EntityPropertyList PROP_LAST_ITEM = (EntityPropertyList)(PROP_AFTER_LAST_ITEM - 1);
@ -237,7 +238,7 @@ void EntityItemProperties::setShapeTypeFromString(const QString& shapeName) {
}
}
const char* backgroundModeNames[] = {"inherit", "atmosphere", "texture" };
const char* backgroundModeNames[] = {"inherit", "atmosphere", "skybox" };
QHash<QString, BackgroundMode> stringToBackgroundModeLookup;
@ -248,7 +249,7 @@ void addBackgroundMode(BackgroundMode type) {
void buildStringToBackgroundModeLookup() {
addBackgroundMode(BACKGROUND_MODE_INHERIT);
addBackgroundMode(BACKGROUND_MODE_ATMOSPHERE);
addBackgroundMode(BACKGROUND_MODE_TEXTURE);
addBackgroundMode(BACKGROUND_MODE_SKYBOX);
}
QString EntityItemProperties::getBackgroundModeAsString() const {
@ -337,6 +338,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_MODE, backgroundMode);
changedProperties += _atmosphere.getChangedProperties();
changedProperties += _skybox.getChangedProperties();
return changedProperties;
}
@ -455,6 +457,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
}
_atmosphere.copyToScriptValue(properties, engine, skipDefaults, defaultEntityProperties);
_skybox.copyToScriptValue(properties, engine, skipDefaults, defaultEntityProperties);
return properties;
}
@ -526,6 +529,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(stageHour, setStageHour);
COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(backgroundMode, BackgroundMode);
_atmosphere.copyFromScriptValue(object, _defaultSettings);
_skybox.copyFromScriptValue(object, _defaultSettings);
_lastEdited = usecTimestampNow();
}
@ -735,6 +739,9 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
_staticAtmosphere.setProperties(properties);
_staticAtmosphere.appentToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState );
_staticSkybox.setProperties(properties);
_staticSkybox.appentToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState );
}
APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, appendValue, properties.getMarketplaceID());
@ -986,6 +993,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_COMPOUND_SHAPE_URL, setCompoundShapeURL);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_BACKGROUND_MODE, BackgroundMode, setBackgroundMode);
properties.getAtmosphere().decodeFromEditPacket(propertyFlags, dataAt , processedBytes);
properties.getSkybox().decodeFromEditPacket(propertyFlags, dataAt , processedBytes);
}
READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_MARKETPLACE_ID, setMarketplaceID);
@ -1090,6 +1098,7 @@ void EntityItemProperties::markAllChanged() {
_backgroundModeChanged = true;
_atmosphere.markAllChanged();
_skybox.markAllChanged();
}

View file

@ -30,6 +30,7 @@
#include <ShapeInfo.h>
#include "AtmospherePropertyGroup.h"
#include "SkyboxPropertyGroup.h"
#include "EntityItemID.h"
#include "EntityItemPropertiesMacros.h"
#include "EntityTypes.h"
@ -138,8 +139,9 @@ public:
DEFINE_PROPERTY(PROP_STAGE_DAY, StageDay, stageDay, quint16);
DEFINE_PROPERTY(PROP_STAGE_HOUR, StageHour, stageHour, float);
DEFINE_PROPERTY_REF(PROP_NAME, Name, name, QString);
DEFINE_PROPERTY_GROUP(Atmosphere, atmosphere, AtmospherePropertyGroup);
DEFINE_PROPERTY_REF_ENUM(PROP_BACKGROUND_MODE, BackgroundMode, backgroundMode, BackgroundMode);
DEFINE_PROPERTY_GROUP(Atmosphere, atmosphere, AtmospherePropertyGroup);
DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup);
static QString getBackgroundModeString(BackgroundMode mode);

View file

@ -116,6 +116,17 @@
bytesRead += sizeof(rgbColor); \
}
#define READ_ENTITY_PROPERTY_XCOLOR(P,M) \
if (propertyFlags.getHasProperty(P)) { \
if (overwriteLocalData) { \
M.red = dataAt[RED_INDEX]; \
M.green = dataAt[GREEN_INDEX]; \
M.blue = dataAt[BLUE_INDEX]; \
} \
dataAt += sizeof(rgbColor); \
bytesRead += sizeof(rgbColor); \
}
#define READ_ENTITY_PROPERTY_TO_PROPERTIES(P,T,O) \
if (propertyFlags.getHasProperty(P)) { \
T fromBuffer; \
@ -206,27 +217,40 @@
}
#define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_VEC3(G,P,p) \
#define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_VEC3(G,g,P,p) \
if (!skipDefaults || defaultEntityProperties.get##G().get##P() != _##p) { \
QScriptValue groupProperties = properties.property(#G); \
QScriptValue groupProperties = properties.property(#g); \
if (!groupProperties.isValid()) { \
groupProperties = engine->newObject(); \
} \
QScriptValue V = vec3toScriptValue(engine, _##p); \
groupProperties.setProperty(#p, V); \
properties.setProperty(#G, groupProperties); \
properties.setProperty(#g, groupProperties); \
}
#define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(G,P,p) \
#define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(G,g,P,p) \
if (!skipDefaults || defaultEntityProperties.get##G().get##P() != _##p) { \
QScriptValue groupProperties = properties.property(#G); \
QScriptValue groupProperties = properties.property(#g); \
if (!groupProperties.isValid()) { \
groupProperties = engine->newObject(); \
} \
groupProperties.setProperty(#p, _##p); \
properties.setProperty(#G, groupProperties); \
properties.setProperty(#g, groupProperties); \
}
#define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_COLOR(G,g,P,p) \
if (!skipDefaults || defaultEntityProperties.get##G().get##P() != _##p) { \
QScriptValue groupProperties = properties.property(#g); \
if (!groupProperties.isValid()) { \
groupProperties = engine->newObject(); \
} \
QScriptValue colorValue = xColorToScriptValue(engine, _##p); \
groupProperties.setProperty(#p, colorValue); \
properties.setProperty(#g, groupProperties); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(P) \
if (!skipDefaults || defaultEntityProperties._##P != _##P) { \
QScriptValue P = vec3toScriptValue(engine, _##P); \
@ -328,6 +352,20 @@
} \
}
#define COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_STRING(G, P, S)\
{ \
QScriptValue G = object.property(#G); \
if (G.isValid()) { \
QScriptValue P = G.property(#P); \
if (P.isValid()) { \
QString newValue = P.toVariant().toString().trimmed();\
if (_defaultSettings || newValue != _##P) { \
S(newValue); \
} \
} \
} \
}
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_UUID(P, S) \
QScriptValue P = object.property(#P); \
if (P.isValid()) { \
@ -428,6 +466,31 @@
} \
}
#define COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_COLOR(G, P, S) \
{ \
QScriptValue G = object.property(#G); \
if (G.isValid()) { \
QScriptValue P = G.property(#P); \
if (P.isValid()) { \
QScriptValue r = P.property("red"); \
QScriptValue g = P.property("green"); \
QScriptValue b = P.property("blue"); \
if (r.isValid() && g.isValid() && b.isValid()) {\
xColor newColor; \
newColor.red = r.toVariant().toInt(); \
newColor.green = g.toVariant().toInt(); \
newColor.blue = b.toVariant().toInt(); \
if (_defaultSettings || \
(newColor.red != _color.red || \
newColor.green != _color.green || \
newColor.blue != _color.blue)) { \
S(newColor); \
} \
} \
} \
} \
}
#define COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(P, S) \
QScriptValue P = object.property(#P); \
if (P.isValid()) { \

View file

@ -144,6 +144,8 @@ enum EntityPropertyList {
PROP_ATMOSPHERE_SCATTERING_WAVELENGTHS = PROP_LOCAL_GRAVITY,
PROP_ATMOSPHERE_HAS_STARS = PROP_PARTICLE_RADIUS,
PROP_BACKGROUND_MODE = PROP_MODEL_URL,
PROP_SKYBOX_COLOR = PROP_ANIMATION_URL,
PROP_SKYBOX_URL = PROP_ANIMATION_FPS,
// WARNING!!! DO NOT ADD PROPS_xxx here unless you really really meant to.... Add them UP above
};
@ -158,7 +160,7 @@ extern EntityPropertyList PROP_LAST_ITEM;
enum BackgroundMode {
BACKGROUND_MODE_INHERIT,
BACKGROUND_MODE_ATMOSPHERE,
BACKGROUND_MODE_TEXTURE,
BACKGROUND_MODE_SKYBOX,
};

View file

@ -0,0 +1,130 @@
//
// SkyboxPropertyGroup.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 <OctreePacketData.h>
#include "SkyboxPropertyGroup.h"
#include "EntityItemProperties.h"
#include "EntityItemPropertiesMacros.h"
SkyboxPropertyGroup::SkyboxPropertyGroup() {
_color.red = _color.green = _color.blue = 0;
_url = QString();
}
void SkyboxPropertyGroup::copyToScriptValue(QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_COLOR(Skybox, skybox, Color, color);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Skybox, skybox, URL, url);
}
void SkyboxPropertyGroup::copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_COLOR(skybox, color, setColor);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_STRING(skybox, url, setURL);
}
void SkyboxPropertyGroup::debugDump() const {
qDebug() << " SkyboxPropertyGroup: ---------------------------------------------";
qDebug() << " Color:" << getColor() << " has changed:" << colorChanged();
qDebug() << " URL:" << getURL() << " has changed:" << urlChanged();
}
bool SkyboxPropertyGroup::appentToEditPacket(OctreePacketData* packetData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const {
bool successPropertyFits = true;
APPEND_ENTITY_PROPERTY(PROP_SKYBOX_COLOR, appendColor, getColor());
APPEND_ENTITY_PROPERTY(PROP_SKYBOX_URL, appendValue, getURL());
return true;
}
bool SkyboxPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt , int& processedBytes) {
int bytesRead = 0;
bool overwriteLocalData = true;
READ_ENTITY_PROPERTY_XCOLOR(PROP_SKYBOX_COLOR, _color);
READ_ENTITY_PROPERTY_STRING(PROP_SKYBOX_URL, setURL);
processedBytes += bytesRead;
return true;
}
void SkyboxPropertyGroup::markAllChanged() {
_colorChanged = true;
_urlChanged = true;
}
EntityPropertyFlags SkyboxPropertyGroup::getChangedProperties() const {
EntityPropertyFlags changedProperties;
CHECK_PROPERTY_CHANGE(PROP_SKYBOX_COLOR, color);
CHECK_PROPERTY_CHANGE(PROP_SKYBOX_URL, url);
return changedProperties;
}
void SkyboxPropertyGroup::getProperties(EntityItemProperties& properties) const {
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Skybox, Color, getColor);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Skybox, URL, getURL);
}
bool SkyboxPropertyGroup::setProperties(const EntityItemProperties& properties) {
bool somethingChanged = false;
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Skybox, Color, color, setColor);
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Skybox, URL, url, setURL);
return somethingChanged;
}
EntityPropertyFlags SkyboxPropertyGroup::getEntityProperties(EncodeBitstreamParams& params) const {
EntityPropertyFlags requestedProperties;
requestedProperties += PROP_SKYBOX_COLOR;
requestedProperties += PROP_SKYBOX_URL;
return requestedProperties;
}
void SkyboxPropertyGroup::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const {
bool successPropertyFits = true;
APPEND_ENTITY_PROPERTY(PROP_SKYBOX_COLOR, appendColor, getColor());
APPEND_ENTITY_PROPERTY(PROP_SKYBOX_URL, appendValue, getURL());
}
int SkyboxPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData) {
int bytesRead = 0;
const unsigned char* dataAt = data;
READ_ENTITY_PROPERTY_XCOLOR(PROP_SKYBOX_COLOR, _color);
READ_ENTITY_PROPERTY_STRING(PROP_SKYBOX_URL, setURL);
return bytesRead;
}

View file

@ -0,0 +1,85 @@
//
// SkyboxPropertyGroup.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_SkyboxPropertyGroup_h
#define hifi_SkyboxPropertyGroup_h
#include <QtScript/QScriptEngine>
#include "PropertyGroup.h"
#include "EntityItemPropertiesMacros.h"
class EntityItemProperties;
class EncodeBitstreamParams;
class OctreePacketData;
class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
#include <stdint.h>
#include <glm/glm.hpp>
class SkyboxPropertyGroup : public PropertyGroup {
public:
SkyboxPropertyGroup();
virtual ~SkyboxPropertyGroup() {}
// EntityItemProperty related helpers
virtual void copyToScriptValue(QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const;
virtual void copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings);
virtual void debugDump() const;
virtual bool appentToEditPacket(OctreePacketData* packetData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const;
virtual bool decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt , int& processedBytes);
virtual void markAllChanged();
virtual EntityPropertyFlags getChangedProperties() const;
// EntityItem related helpers
// methods for getting/setting all properties of an entity
virtual void getProperties(EntityItemProperties& propertiesOut) const;
/// returns true if something changed
virtual bool setProperties(const EntityItemProperties& properties);
virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const;
virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData,
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);
glm::vec3 getColorVec3() const {
const quint8 MAX_COLOR = 255;
glm::vec3 color = { (float)_color.red / (float)MAX_COLOR,
(float)_color.green / (float)MAX_COLOR,
(float)_color.blue / (float)MAX_COLOR };
return color;
}
DEFINE_PROPERTY_REF(PROP_SKYBOX_COLOR, Color, color, xColor);
DEFINE_PROPERTY_REF(PROP_SKYBOX_URL, URL, url, QString);
};
#endif // hifi_SkyboxPropertyGroup_h

View file

@ -71,13 +71,13 @@ ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID, const EntityIte
EnvironmentData ZoneEntityItem::getEnvironmentData() const {
EnvironmentData result;
result.setAtmosphereCenter(_atmospherePropeties.getCenter());
result.setAtmosphereInnerRadius(_atmospherePropeties.getInnerRadius());
result.setAtmosphereOuterRadius(_atmospherePropeties.getOuterRadius());
result.setRayleighScattering(_atmospherePropeties.getRayleighScattering());
result.setMieScattering(_atmospherePropeties.getMieScattering());
result.setScatteringWavelengths(_atmospherePropeties.getScatteringWavelengths());
result.setHasStars(_atmospherePropeties.getHasStars());
result.setAtmosphereCenter(_atmosphereProperties.getCenter());
result.setAtmosphereInnerRadius(_atmosphereProperties.getInnerRadius());
result.setAtmosphereOuterRadius(_atmosphereProperties.getOuterRadius());
result.setRayleighScattering(_atmosphereProperties.getRayleighScattering());
result.setMieScattering(_atmosphereProperties.getMieScattering());
result.setScatteringWavelengths(_atmosphereProperties.getScatteringWavelengths());
result.setHasStars(_atmosphereProperties.getHasStars());
// NOTE: The sunLocation and SunBrightness will be overwritten in the EntityTreeRenderer to use the
// keyLight details from the scene interface
@ -105,7 +105,8 @@ EntityItemProperties ZoneEntityItem::getProperties() const {
COPY_ENTITY_PROPERTY_TO_PROPERTIES(backgroundMode, getBackgroundMode);
_atmospherePropeties.getProperties(properties);
_atmosphereProperties.getProperties(properties);
_skyboxProperties.getProperties(properties);
return properties;
}
@ -128,9 +129,10 @@ bool ZoneEntityItem::setProperties(const EntityItemProperties& properties) {
SET_ENTITY_PROPERTY_FROM_PROPERTIES(compoundShapeURL, setCompoundShapeURL);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(backgroundMode, setBackgroundMode);
bool somethingChangedInAtmosphere = _atmospherePropeties.setProperties(properties);
bool somethingChangedInAtmosphere = _atmosphereProperties.setProperties(properties);
bool somethingChangedInSkybox = _skyboxProperties.setProperties(properties);
somethingChanged = somethingChanged || somethingChangedInAtmosphere;
somethingChanged = somethingChanged || somethingChangedInAtmosphere || somethingChangedInSkybox;
if (somethingChanged) {
bool wantDebug = false;
@ -165,8 +167,17 @@ int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data,
READ_ENTITY_PROPERTY_SETTER(PROP_SHAPE_TYPE, ShapeType, updateShapeType);
READ_ENTITY_PROPERTY_STRING(PROP_COMPOUND_SHAPE_URL, setCompoundShapeURL);
READ_ENTITY_PROPERTY_SETTER(PROP_BACKGROUND_MODE, BackgroundMode, setBackgroundMode);
bytesRead += _atmospherePropeties.readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args,
int bytesFromAtmosphere = _atmosphereProperties.readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args,
propertyFlags, overwriteLocalData);
bytesRead += bytesFromAtmosphere;
dataAt += bytesFromAtmosphere;
int bytesFromSkybox = _skyboxProperties.readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args,
propertyFlags, overwriteLocalData);
bytesRead += bytesFromSkybox;
dataAt += bytesFromSkybox;
return bytesRead;
}
@ -189,7 +200,8 @@ EntityPropertyFlags ZoneEntityItem::getEntityProperties(EncodeBitstreamParams& p
requestedProperties += PROP_SHAPE_TYPE;
requestedProperties += PROP_COMPOUND_SHAPE_URL;
requestedProperties += PROP_BACKGROUND_MODE;
requestedProperties += _atmospherePropeties.getEntityProperties(params);
requestedProperties += _atmosphereProperties.getEntityProperties(params);
requestedProperties += _skyboxProperties.getEntityProperties(params);
return requestedProperties;
}
@ -218,7 +230,10 @@ void ZoneEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits
APPEND_ENTITY_PROPERTY(PROP_COMPOUND_SHAPE_URL, appendValue, getCompoundShapeURL());
APPEND_ENTITY_PROPERTY(PROP_BACKGROUND_MODE, appendValue, (uint32_t)getBackgroundMode()); // could this be a uint16??
_atmospherePropeties.appendSubclassData(packetData, params, modelTreeElementExtraEncodeData, requestedProperties,
_atmosphereProperties.appendSubclassData(packetData, params, modelTreeElementExtraEncodeData, requestedProperties,
propertyFlags, propertiesDidntFit, propertyCount, appendState);
_skyboxProperties.appendSubclassData(packetData, params, modelTreeElementExtraEncodeData, requestedProperties,
propertyFlags, propertiesDidntFit, propertyCount, appendState);
}
@ -241,7 +256,8 @@ void ZoneEntityItem::debugDump() const {
qCDebug(entities) << " _stageHour:" << _stageHour;
qCDebug(entities) << " _backgroundMode:" << EntityItemProperties::getBackgroundModeString(_backgroundMode);
_atmospherePropeties.debugDump();
_atmosphereProperties.debugDump();
_skyboxProperties.debugDump();
}
ShapeType ZoneEntityItem::getShapeType() const {

View file

@ -105,6 +105,8 @@ public:
BackgroundMode getBackgroundMode() const { return _backgroundMode; }
EnvironmentData getEnvironmentData() const;
const AtmospherePropertyGroup& getAtmosphereProperties() const { return _atmosphereProperties; }
const SkyboxPropertyGroup& getSkyboxProperties() const { return _skyboxProperties; }
virtual bool supportsDetailedRayIntersection() const { return true; }
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
@ -143,7 +145,8 @@ protected:
QString _compoundShapeURL;
BackgroundMode _backgroundMode = BACKGROUND_MODE_INHERIT;
AtmospherePropertyGroup _atmospherePropeties;
AtmospherePropertyGroup _atmosphereProperties;
SkyboxPropertyGroup _skyboxProperties;
static bool _drawZoneBoundaries;
static bool _zonesArePickable;

View file

@ -41,10 +41,13 @@ void Skybox::setCubemap(const gpu::TexturePointer& cubemap) {
_cubemap = cubemap;
}
void Skybox::clearCubemap() {
_cubemap.reset();
}
void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) {
if (skybox.getCubemap()) {
static gpu::PipelinePointer thePipeline;
static gpu::BufferPointer theBuffer;
static gpu::Stream::FormatPointer theFormat;

View file

@ -32,6 +32,7 @@ public:
void setCubemap(const gpu::TexturePointer& cubemap);
const gpu::TexturePointer& getCubemap() const { return _cubemap; }
void clearCubemap();
static void render(gpu::Batch& batch, const ViewFrustum& frustum, const Skybox& skybox);

View file

@ -74,7 +74,7 @@ PacketVersion versionForPacketType(PacketType type) {
return 1;
case PacketTypeEntityAddOrEdit:
case PacketTypeEntityData:
return VERSION_ENTITIES_ZONE_ENTITIES_HAVE_ATMOSPHERE;
return VERSION_ENTITIES_ZONE_ENTITIES_HAVE_SKYBOX;
case PacketTypeEntityErase:
return 2;
case PacketTypeAudioStreamStats:

View file

@ -141,5 +141,6 @@ const PacketVersion VERSION_ENTITIES_ZONE_ENTITIES_EXIST = 17;
const PacketVersion VERSION_ENTITIES_ZONE_ENTITIES_HAVE_DYNAMIC_SHAPE = 18;
const PacketVersion VERSION_ENTITIES_HAVE_NAMES = 19;
const PacketVersion VERSION_ENTITIES_ZONE_ENTITIES_HAVE_ATMOSPHERE = 20;
const PacketVersion VERSION_ENTITIES_ZONE_ENTITIES_HAVE_SKYBOX = 21;
#endif // hifi_PacketHeaders_h

View file

@ -23,11 +23,19 @@
const int BYTES_PER_COLOR = 3;
const int BYTES_PER_FLAGS = 1;
typedef unsigned char rgbColor[BYTES_PER_COLOR];
typedef unsigned char colorPart;
typedef unsigned char nodeColor[BYTES_PER_COLOR + BYTES_PER_FLAGS];
typedef unsigned char rgbColor[BYTES_PER_COLOR];
inline QDebug& operator<<(QDebug& dbg, const rgbColor& c) {
dbg.nospace() << "{type='rgbColor'"
", red=" << c[0] <<
", green=" << c[1] <<
", blue=" << c[2] <<
"}";
return dbg;
}
struct xColor {
unsigned char red;
unsigned char green;