mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 18:55:01 +02:00
commit
894e91ea23
13 changed files with 276 additions and 22 deletions
|
@ -96,6 +96,7 @@ PolyLineEntityRenderer::PolyLineEntityRenderer(const EntityItemPointer& entity)
|
|||
polylineFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), offsetof(Vertex, position));
|
||||
polylineFormat->setAttribute(gpu::Stream::NORMAL, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), offsetof(Vertex, normal));
|
||||
polylineFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), offsetof(Vertex, uv));
|
||||
polylineFormat->setAttribute(gpu::Stream::COLOR, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RGB), offsetof(Vertex, color));
|
||||
});
|
||||
|
||||
PolyLineUniforms uniforms;
|
||||
|
@ -116,7 +117,8 @@ bool PolyLineEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityP
|
|||
entity->pointsChanged() ||
|
||||
entity->strokeWidthsChanged() ||
|
||||
entity->normalsChanged() ||
|
||||
entity->texturesChanged()
|
||||
entity->texturesChanged() ||
|
||||
entity->strokeColorsChanged()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -129,9 +131,11 @@ void PolyLineEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer&
|
|||
if (!textures.isEmpty()) {
|
||||
entityTextures = QUrl(textures);
|
||||
}
|
||||
_texture = DependencyManager::get<TextureCache>()->getTexture(entityTextures);
|
||||
}
|
||||
|
||||
if (!_texture || _texture->getURL() != entityTextures) {
|
||||
|
||||
|
||||
if (!_texture) {
|
||||
_texture = DependencyManager::get<TextureCache>()->getTexture(entityTextures);
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +147,10 @@ void PolyLineEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPo
|
|||
auto pointsChanged = entity->pointsChanged();
|
||||
auto strokeWidthsChanged = entity->strokeWidthsChanged();
|
||||
auto normalsChanged = entity->normalsChanged();
|
||||
auto strokeColorsChanged = entity->strokeColorsChanged();
|
||||
|
||||
|
||||
bool isUVModeStretch = entity->getIsUVModeStretch();
|
||||
entity->resetPolyLineChanged();
|
||||
|
||||
_polylineTransform = Transform();
|
||||
|
@ -158,10 +166,14 @@ void PolyLineEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPo
|
|||
if (normalsChanged) {
|
||||
_lastNormals = entity->getNormals();
|
||||
}
|
||||
if (pointsChanged || strokeWidthsChanged || normalsChanged) {
|
||||
if (strokeColorsChanged) {
|
||||
_lastStrokeColors = entity->getStrokeColors();
|
||||
_lastStrokeColors = _lastNormals.size() == _lastStrokeColors.size() ? _lastStrokeColors : QVector<glm::vec3>({ toGlm(entity->getXColor()) });
|
||||
}
|
||||
if (pointsChanged || strokeWidthsChanged || normalsChanged || strokeColorsChanged) {
|
||||
_empty = std::min(_lastPoints.size(), std::min(_lastNormals.size(), _lastStrokeWidths.size())) < 2;
|
||||
if (!_empty) {
|
||||
updateGeometry(updateVertices(_lastPoints, _lastNormals, _lastStrokeWidths));
|
||||
updateGeometry(updateVertices(_lastPoints, _lastNormals, _lastStrokeWidths, _lastStrokeColors, isUVModeStretch, _textureAspectRatio));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -175,7 +187,12 @@ void PolyLineEntityRenderer::updateGeometry(const std::vector<Vertex>& vertices)
|
|||
_verticesBuffer->setSubData(0, vertices);
|
||||
}
|
||||
|
||||
std::vector<PolyLineEntityRenderer::Vertex> PolyLineEntityRenderer::updateVertices(const QVector<glm::vec3>& points, const QVector<glm::vec3>& normals, const QVector<float>& strokeWidths) {
|
||||
std::vector<PolyLineEntityRenderer::Vertex> PolyLineEntityRenderer::updateVertices(const QVector<glm::vec3>& points,
|
||||
const QVector<glm::vec3>& normals,
|
||||
const QVector<float>& strokeWidths,
|
||||
const QVector<glm::vec3>& strokeColors,
|
||||
const bool isUVModeStretch,
|
||||
const float textureAspectRatio) {
|
||||
// Calculate the minimum vector size out of normals, points, and stroke widths
|
||||
int size = std::min(points.size(), std::min(normals.size(), strokeWidths.size()));
|
||||
|
||||
|
@ -190,10 +207,52 @@ std::vector<PolyLineEntityRenderer::Vertex> PolyLineEntityRenderer::updateVertic
|
|||
float uCoord = 0.0f;
|
||||
int finalIndex = size - 1;
|
||||
glm::vec3 binormal;
|
||||
float accumulatedDistance = 0.0f;
|
||||
float distanceToLastPoint = 0.0f;
|
||||
float accumulatedStrokeWidth = 0.0f;
|
||||
float strokeWidth = 0.0f;
|
||||
bool doesStrokeWidthVary = false;
|
||||
|
||||
|
||||
for (int i = 1; i < strokeWidths.size(); i++) {
|
||||
if (strokeWidths[i] != strokeWidths[i - 1]) {
|
||||
doesStrokeWidthVary = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i <= finalIndex; i++) {
|
||||
const float& width = strokeWidths.at(i);
|
||||
const auto& point = points.at(i);
|
||||
const auto& normal = normals.at(i);
|
||||
const auto& color = strokeColors.size() == normals.size() ? strokeColors.at(i) : strokeColors.at(0);
|
||||
int vertexIndex = i * 2;
|
||||
|
||||
|
||||
if (!isUVModeStretch && i >= 1) {
|
||||
distanceToLastPoint = glm::distance(points.at(i), points.at(i - 1));
|
||||
accumulatedDistance += distanceToLastPoint;
|
||||
strokeWidth = 2 * strokeWidths[i];
|
||||
|
||||
if (doesStrokeWidthVary) {
|
||||
//If the stroke varies along the line the texture will stretch more or less depending on the speed
|
||||
//because it looks better than using the same method as below
|
||||
accumulatedStrokeWidth += strokeWidth;
|
||||
float increaseValue = 1;
|
||||
if (accumulatedStrokeWidth != 0) {
|
||||
float newUcoord = glm::ceil(((1.0f / textureAspectRatio) * accumulatedDistance) / (accumulatedStrokeWidth / i));
|
||||
increaseValue = newUcoord - uCoord;
|
||||
}
|
||||
|
||||
increaseValue = increaseValue > 0 ? increaseValue : 1;
|
||||
uCoord += increaseValue;
|
||||
} else {
|
||||
//If the stroke width is constant then the textures should keep the aspect ratio along the line
|
||||
uCoord = ((1.0f / textureAspectRatio) * accumulatedDistance) / strokeWidth;
|
||||
}
|
||||
} else if (vertexIndex >= 2) {
|
||||
uCoord += uCoordInc;
|
||||
}
|
||||
|
||||
// For last point we can assume binormals are the same since it represents the last two vertices of quad
|
||||
if (i < finalIndex) {
|
||||
|
@ -206,11 +265,10 @@ std::vector<PolyLineEntityRenderer::Vertex> PolyLineEntityRenderer::updateVertic
|
|||
}
|
||||
}
|
||||
|
||||
const auto v1 = point + binormal;
|
||||
const auto v2 = point - binormal;
|
||||
vertices.emplace_back(v1, normal, vec2(uCoord, 0.0f));
|
||||
vertices.emplace_back(v2, normal, vec2(uCoord, 1.0f));
|
||||
uCoord += uCoordInc;
|
||||
const auto v1 = points.at(i) + binormal;
|
||||
const auto v2 = points.at(i) - binormal;
|
||||
vertices.emplace_back(v1, normal, vec2(uCoord, 0.0f), color);
|
||||
vertices.emplace_back(v2, normal, vec2(uCoord, 1.0f), color);
|
||||
}
|
||||
|
||||
return vertices;
|
||||
|
@ -235,6 +293,12 @@ void PolyLineEntityRenderer::doRender(RenderArgs* args) {
|
|||
batch.setResourceTexture(PAINTSTROKE_TEXTURE_SLOT, DependencyManager::get<TextureCache>()->getWhiteTexture());
|
||||
}
|
||||
|
||||
float textureWidth = (float)_texture->getOriginalWidth();
|
||||
float textureHeight = (float)_texture->getOriginalHeight();
|
||||
if (textureWidth != 0 && textureHeight != 0) {
|
||||
_textureAspectRatio = textureWidth / textureHeight;
|
||||
}
|
||||
|
||||
batch.setInputFormat(polylineFormat);
|
||||
batch.setInputBuffer(0, _verticesBuffer, 0, sizeof(Vertex));
|
||||
|
||||
|
@ -247,4 +311,4 @@ void PolyLineEntityRenderer::doRender(RenderArgs* args) {
|
|||
#endif
|
||||
|
||||
batch.draw(gpu::TRIANGLE_STRIP, _numVertices, 0);
|
||||
}
|
||||
}
|
|
@ -27,7 +27,9 @@ public:
|
|||
|
||||
protected:
|
||||
virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override;
|
||||
virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override;
|
||||
virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene,
|
||||
Transaction& transaction,
|
||||
const TypedEntityPointer& entity) override;
|
||||
virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) override;
|
||||
|
||||
virtual ItemKey getKey() override;
|
||||
|
@ -38,24 +40,37 @@ protected:
|
|||
|
||||
struct Vertex {
|
||||
Vertex() {}
|
||||
Vertex(const vec3& position, const vec3& normal, const vec2& uv) : position(position), normal(normal), uv(uv) {}
|
||||
Vertex(const vec3& position, const vec3& normal, const vec2& uv, const vec3& color) : position(position),
|
||||
normal(normal),
|
||||
uv(uv),
|
||||
color(color) {}
|
||||
vec3 position;
|
||||
vec3 normal;
|
||||
vec2 uv;
|
||||
vec3 color;
|
||||
};
|
||||
|
||||
void updateGeometry(const std::vector<Vertex>& vertices);
|
||||
static std::vector<Vertex> updateVertices(const QVector<glm::vec3>& points, const QVector<glm::vec3>& normals, const QVector<float>& strokeWidths);
|
||||
static std::vector<Vertex> updateVertices(const QVector<glm::vec3>& points,
|
||||
const QVector<glm::vec3>& normals,
|
||||
const QVector<float>& strokeWidths,
|
||||
const QVector<glm::vec3>& strokeColors,
|
||||
const bool isUVModeStretch,
|
||||
const float textureAspectRatio);
|
||||
|
||||
Transform _polylineTransform;
|
||||
QVector<glm::vec3> _lastPoints;
|
||||
QVector<glm::vec3> _lastNormals;
|
||||
QVector<glm::vec3> _lastStrokeColors;
|
||||
QVector<float> _lastStrokeWidths;
|
||||
gpu::BufferPointer _verticesBuffer;
|
||||
gpu::BufferView _uniformBuffer;
|
||||
|
||||
uint32_t _numVertices { 0 };
|
||||
bool _empty{ true };
|
||||
NetworkTexturePointer _texture;
|
||||
float _textureAspectRatio { 1.0f };
|
||||
|
||||
};
|
||||
|
||||
} } // namespace
|
||||
|
|
|
@ -40,7 +40,7 @@ void main(void) {
|
|||
packDeferredFragmentTranslucent(
|
||||
float(frontCondition) * interpolatedNormal,
|
||||
texel.a * varColor.a,
|
||||
polyline.color * texel.rgb,
|
||||
color * texel.rgb,
|
||||
vec3(0.01, 0.01, 0.01),
|
||||
10.0);
|
||||
}
|
||||
|
|
|
@ -345,7 +345,9 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
|
|||
CHECK_PROPERTY_CHANGE(PROP_FACE_CAMERA, faceCamera);
|
||||
CHECK_PROPERTY_CHANGE(PROP_ACTION_DATA, actionData);
|
||||
CHECK_PROPERTY_CHANGE(PROP_NORMALS, normals);
|
||||
CHECK_PROPERTY_CHANGE(PROP_STROKE_COLORS, strokeColors);
|
||||
CHECK_PROPERTY_CHANGE(PROP_STROKE_WIDTHS, strokeWidths);
|
||||
CHECK_PROPERTY_CHANGE(PROP_IS_UV_MODE_STRETCH, isUVModeStretch);
|
||||
CHECK_PROPERTY_CHANGE(PROP_X_TEXTURE_URL, xTextureURL);
|
||||
CHECK_PROPERTY_CHANGE(PROP_Y_TEXTURE_URL, yTextureURL);
|
||||
CHECK_PROPERTY_CHANGE(PROP_Z_TEXTURE_URL, zTextureURL);
|
||||
|
@ -595,8 +597,10 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
|
|||
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LINE_WIDTH, lineWidth);
|
||||
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LINE_POINTS, linePoints);
|
||||
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_NORMALS, normals);
|
||||
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_STROKE_COLORS, strokeColors);
|
||||
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_STROKE_WIDTHS, strokeWidths);
|
||||
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_TEXTURES, textures);
|
||||
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_IS_UV_MODE_STRETCH, isUVModeStretch);
|
||||
}
|
||||
|
||||
if (!skipDefaults && !strictSemantics) {
|
||||
|
@ -761,7 +765,10 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool
|
|||
COPY_PROPERTY_FROM_QSCRIPTVALUE(faceCamera, bool, setFaceCamera);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(actionData, QByteArray, setActionData);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(normals, qVectorVec3, setNormals);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(strokeColors, qVectorVec3, setStrokeColors);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(strokeWidths,qVectorFloat, setStrokeWidths);
|
||||
COPY_PROPERTY_FROM_QSCRIPTVALUE(isUVModeStretch, bool, setIsUVModeStretch);
|
||||
|
||||
|
||||
if (!honorReadOnly) {
|
||||
// this is used by the json reader to set things that we don't want javascript to able to affect.
|
||||
|
@ -915,7 +922,9 @@ void EntityItemProperties::merge(const EntityItemProperties& other) {
|
|||
COPY_PROPERTY_IF_CHANGED(faceCamera);
|
||||
COPY_PROPERTY_IF_CHANGED(actionData);
|
||||
COPY_PROPERTY_IF_CHANGED(normals);
|
||||
COPY_PROPERTY_IF_CHANGED(strokeColors);
|
||||
COPY_PROPERTY_IF_CHANGED(strokeWidths);
|
||||
COPY_PROPERTY_IF_CHANGED(isUVModeStretch);
|
||||
COPY_PROPERTY_IF_CHANGED(created);
|
||||
|
||||
_animation.merge(other._animation);
|
||||
|
@ -1102,7 +1111,9 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue
|
|||
ADD_PROPERTY_TO_MAP(PROP_FACE_CAMERA, FaceCamera, faceCamera, bool);
|
||||
ADD_PROPERTY_TO_MAP(PROP_ACTION_DATA, ActionData, actionData, QByteArray);
|
||||
ADD_PROPERTY_TO_MAP(PROP_NORMALS, Normals, normals, QVector<glm::vec3>);
|
||||
ADD_PROPERTY_TO_MAP(PROP_STROKE_COLORS, StrokeColors, strokeColors, QVector<glm::vec3>);
|
||||
ADD_PROPERTY_TO_MAP(PROP_STROKE_WIDTHS, StrokeWidths, strokeWidths, QVector<float>);
|
||||
ADD_PROPERTY_TO_MAP(PROP_IS_UV_MODE_STRETCH, IsUVModeStretch, isUVModeStretch, QVector<float>);
|
||||
ADD_PROPERTY_TO_MAP(PROP_X_TEXTURE_URL, XTextureURL, xTextureURL, QString);
|
||||
ADD_PROPERTY_TO_MAP(PROP_Y_TEXTURE_URL, YTextureURL, yTextureURL, QString);
|
||||
ADD_PROPERTY_TO_MAP(PROP_Z_TEXTURE_URL, ZTextureURL, zTextureURL, QString);
|
||||
|
@ -1448,9 +1459,11 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
|
|||
if (properties.getType() == EntityTypes::PolyLine) {
|
||||
APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, properties.getLineWidth());
|
||||
APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, properties.getLinePoints());
|
||||
APPEND_ENTITY_PROPERTY(PROP_NORMALS, properties.getNormals());
|
||||
APPEND_ENTITY_PROPERTY(PROP_NORMALS, properties.getPackedNormals());
|
||||
APPEND_ENTITY_PROPERTY(PROP_STROKE_COLORS, properties.getPackedStrokeColors());
|
||||
APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, properties.getStrokeWidths());
|
||||
APPEND_ENTITY_PROPERTY(PROP_TEXTURES, properties.getTextures());
|
||||
APPEND_ENTITY_PROPERTY(PROP_IS_UV_MODE_STRETCH, properties.getIsUVModeStretch());
|
||||
}
|
||||
// NOTE: Spheres and Boxes are just special cases of Shape, and they need to include their PROP_SHAPE
|
||||
// when encoding/decoding edits because otherwise they can't polymorph to other shape types
|
||||
|
@ -1537,6 +1550,44 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
|
|||
return success;
|
||||
}
|
||||
|
||||
QByteArray EntityItemProperties::getPackedNormals() const {
|
||||
return packNormals(getNormals());
|
||||
}
|
||||
|
||||
QByteArray EntityItemProperties::packNormals(const QVector<glm::vec3>& normals) const {
|
||||
int normalsSize = normals.size();
|
||||
QByteArray packedNormals = QByteArray(normalsSize * 6 + 1, '0');
|
||||
// add size of the array
|
||||
packedNormals[0] = ((uint8_t)normalsSize);
|
||||
|
||||
int index = 1;
|
||||
for (int i = 0; i < normalsSize; i++) {
|
||||
int numBytes = packFloatVec3ToSignedTwoByteFixed((unsigned char*)packedNormals.data() + index, normals[i], 15);
|
||||
index += numBytes;
|
||||
}
|
||||
return packedNormals;
|
||||
}
|
||||
|
||||
QByteArray EntityItemProperties::getPackedStrokeColors() const {
|
||||
return packStrokeColors(getStrokeColors());
|
||||
}
|
||||
QByteArray EntityItemProperties::packStrokeColors(const QVector<glm::vec3>& strokeColors) const {
|
||||
int strokeColorsSize = strokeColors.size();
|
||||
QByteArray packedStrokeColors = QByteArray(strokeColorsSize * 3 + 1, '0');
|
||||
|
||||
// add size of the array
|
||||
packedStrokeColors[0] = ((uint8_t)strokeColorsSize);
|
||||
|
||||
|
||||
for (int i = 0; i < strokeColorsSize; i++) {
|
||||
// add the color to the QByteArray
|
||||
packedStrokeColors[i * 3 + 1] = strokeColors[i].r * 255;
|
||||
packedStrokeColors[i * 3 + 2] = strokeColors[i].g * 255;
|
||||
packedStrokeColors[i * 3 + 3] = strokeColors[i].b * 255;
|
||||
}
|
||||
return packedStrokeColors;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// how to handle lastEdited?
|
||||
// how to handle lastUpdated?
|
||||
|
@ -1758,9 +1809,11 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
|
|||
if (properties.getType() == EntityTypes::PolyLine) {
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_WIDTH, float, setLineWidth);
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LINE_POINTS, QVector<glm::vec3>, setLinePoints);
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_NORMALS, QVector<glm::vec3>, setNormals);
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_NORMALS, QByteArray, setPackedNormals);
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STROKE_COLORS, QByteArray, setPackedStrokeColors);
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STROKE_WIDTHS, QVector<float>, setStrokeWidths);
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_TEXTURES, QString, setTextures);
|
||||
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_IS_UV_MODE_STRETCH, bool, setIsUVModeStretch);
|
||||
}
|
||||
|
||||
// NOTE: Spheres and Boxes are just special cases of Shape, and they need to include their PROP_SHAPE
|
||||
|
@ -1791,6 +1844,53 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
|
|||
return valid;
|
||||
}
|
||||
|
||||
void EntityItemProperties::setPackedNormals(const QByteArray& value) {
|
||||
setNormals(unpackNormals(value));
|
||||
}
|
||||
|
||||
QVector<glm::vec3> EntityItemProperties::unpackNormals(const QByteArray& normals) {
|
||||
// the size of the vector is packed first
|
||||
QVector<glm::vec3> unpackedNormals = QVector<glm::vec3>((int)normals[0]);
|
||||
|
||||
if ((int)normals[0] == normals.size() / 6) {
|
||||
int j = 0;
|
||||
for (int i = 1; i < normals.size();) {
|
||||
glm::vec3 aux = glm::vec3();
|
||||
i += unpackFloatVec3FromSignedTwoByteFixed((unsigned char*)normals.data() + i, aux, 15);
|
||||
unpackedNormals[j] = aux;
|
||||
j++;
|
||||
}
|
||||
} else {
|
||||
qCDebug(entities) << "WARNING - Expected received size for normals does not match. Expected: " << (int)normals[0]
|
||||
<< " Received: " << (normals.size() / 6);
|
||||
}
|
||||
return unpackedNormals;
|
||||
}
|
||||
|
||||
void EntityItemProperties::setPackedStrokeColors(const QByteArray& value) {
|
||||
setStrokeColors(unpackStrokeColors(value));
|
||||
}
|
||||
|
||||
QVector<glm::vec3> EntityItemProperties::unpackStrokeColors(const QByteArray& strokeColors) {
|
||||
// the size of the vector is packed first
|
||||
QVector<glm::vec3> unpackedStrokeColors = QVector<glm::vec3>((int)strokeColors[0]);
|
||||
|
||||
if ((int)strokeColors[0] == strokeColors.size() / 3) {
|
||||
int j = 0;
|
||||
for (int i = 1; i < strokeColors.size();) {
|
||||
|
||||
float r = (uint8_t)strokeColors[i++] / 255.0f;
|
||||
float g = (uint8_t)strokeColors[i++] / 255.0f;
|
||||
float b = (uint8_t)strokeColors[i++] / 255.0f;
|
||||
unpackedStrokeColors[j++] = glmVec3(r, g, b);
|
||||
}
|
||||
} else {
|
||||
qCDebug(entities) << "WARNING - Expected received size for stroke colors does not match. Expected: "
|
||||
<< (int)strokeColors[0] << " Received: " << (strokeColors.size() / 3);
|
||||
}
|
||||
|
||||
return unpackedStrokeColors;
|
||||
}
|
||||
|
||||
// NOTE: This version will only encode the portion of the edit message immediately following the
|
||||
// header it does not include the send times and sequence number because that is handled by the
|
||||
|
@ -1932,7 +2032,9 @@ void EntityItemProperties::markAllChanged() {
|
|||
_actionDataChanged = true;
|
||||
|
||||
_normalsChanged = true;
|
||||
_strokeColorsChanged = true;
|
||||
_strokeWidthsChanged = true;
|
||||
_isUVModeStretchChanged = true;
|
||||
|
||||
_xTextureURLChanged = true;
|
||||
_yTextureURLChanged = true;
|
||||
|
@ -2347,6 +2449,14 @@ QList<QString> EntityItemProperties::listChangedProperties() {
|
|||
out += "shape";
|
||||
}
|
||||
|
||||
if (strokeColorsChanged()) {
|
||||
out += "strokeColors";
|
||||
}
|
||||
|
||||
if (isUVModeStretchChanged()) {
|
||||
out += "isUVModeStretch";
|
||||
}
|
||||
|
||||
getAnimation().listChangedProperties(out);
|
||||
getKeyLight().listChangedProperties(out);
|
||||
getSkybox().listChangedProperties(out);
|
||||
|
|
|
@ -191,8 +191,10 @@ public:
|
|||
DEFINE_PROPERTY_REF(PROP_DESCRIPTION, Description, description, QString, "");
|
||||
DEFINE_PROPERTY(PROP_FACE_CAMERA, FaceCamera, faceCamera, bool, TextEntityItem::DEFAULT_FACE_CAMERA);
|
||||
DEFINE_PROPERTY_REF(PROP_ACTION_DATA, ActionData, actionData, QByteArray, QByteArray());
|
||||
DEFINE_PROPERTY(PROP_NORMALS, Normals, normals, QVector<glm::vec3>, QVector<glm::vec3>());
|
||||
DEFINE_PROPERTY(PROP_NORMALS, Normals, normals, QVector<glm::vec3>, ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC);
|
||||
DEFINE_PROPERTY(PROP_STROKE_COLORS, StrokeColors, strokeColors, QVector<glm::vec3>, ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC);
|
||||
DEFINE_PROPERTY(PROP_STROKE_WIDTHS, StrokeWidths, strokeWidths, QVector<float>, QVector<float>());
|
||||
DEFINE_PROPERTY(PROP_IS_UV_MODE_STRETCH, IsUVModeStretch, isUVModeStretch, bool, true);
|
||||
DEFINE_PROPERTY_REF(PROP_X_TEXTURE_URL, XTextureURL, xTextureURL, QString, "");
|
||||
DEFINE_PROPERTY_REF(PROP_Y_TEXTURE_URL, YTextureURL, yTextureURL, QString, "");
|
||||
DEFINE_PROPERTY_REF(PROP_Z_TEXTURE_URL, ZTextureURL, zTextureURL, QString, "");
|
||||
|
@ -322,6 +324,17 @@ public:
|
|||
bool getRenderInfoHasTransparent() const { return _renderInfoHasTransparent; }
|
||||
void setRenderInfoHasTransparent(bool value) { _renderInfoHasTransparent = value; }
|
||||
|
||||
void setPackedNormals(const QByteArray& value);
|
||||
QVector<glm::vec3> unpackNormals(const QByteArray& normals);
|
||||
|
||||
void setPackedStrokeColors(const QByteArray& value);
|
||||
QVector<glm::vec3> unpackStrokeColors(const QByteArray& strokeColors);
|
||||
|
||||
QByteArray getPackedNormals() const;
|
||||
QByteArray packNormals(const QVector<glm::vec3>& normals) const;
|
||||
|
||||
QByteArray getPackedStrokeColors() const;
|
||||
QByteArray packStrokeColors(const QVector<glm::vec3>& strokeColors) const;
|
||||
|
||||
protected:
|
||||
QString getCollisionMaskAsString() const;
|
||||
|
|
|
@ -24,6 +24,8 @@ const glm::vec3 ENTITY_ITEM_ZERO_VEC3 = glm::vec3(0.0f);
|
|||
const glm::vec3 ENTITY_ITEM_ONE_VEC3 = glm::vec3(1.0f);
|
||||
const glm::vec3 ENTITY_ITEM_HALF_VEC3 = glm::vec3(0.5f);
|
||||
|
||||
const QVector<glm::vec3> ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC = QVector<glm::vec3>();
|
||||
|
||||
const bool ENTITY_ITEM_DEFAULT_LOCKED = false;
|
||||
const QString ENTITY_ITEM_DEFAULT_USER_DATA = QString("");
|
||||
const QUuid ENTITY_ITEM_DEFAULT_SIMULATOR_ID = QUuid();
|
||||
|
|
|
@ -109,7 +109,9 @@ enum EntityPropertyList {
|
|||
|
||||
// Used by PolyLine entity
|
||||
PROP_NORMALS,
|
||||
PROP_STROKE_COLORS,
|
||||
PROP_STROKE_WIDTHS,
|
||||
PROP_IS_UV_MODE_STRETCH,
|
||||
|
||||
// used by particles
|
||||
PROP_SPEED_SPREAD,
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "PolyLineEntityItem.h"
|
||||
|
||||
const float PolyLineEntityItem::DEFAULT_LINE_WIDTH = 0.1f;
|
||||
const int PolyLineEntityItem::MAX_POINTS_PER_LINE = 70;
|
||||
const int PolyLineEntityItem::MAX_POINTS_PER_LINE = 60;
|
||||
|
||||
|
||||
EntityItemPointer PolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||
|
@ -31,6 +31,7 @@ EntityItemPointer PolyLineEntityItem::factory(const EntityItemID& entityID, cons
|
|||
return entity;
|
||||
}
|
||||
|
||||
|
||||
PolyLineEntityItem::PolyLineEntityItem(const EntityItemID& entityItemID) : EntityItem(entityItemID) {
|
||||
_type = EntityTypes::PolyLine;
|
||||
}
|
||||
|
@ -42,12 +43,15 @@ EntityItemProperties PolyLineEntityItem::getProperties(EntityPropertyFlags desir
|
|||
|
||||
properties._color = getXColor();
|
||||
properties._colorChanged = false;
|
||||
|
||||
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(lineWidth, getLineWidth);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(linePoints, getLinePoints);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(normals, getNormals);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(strokeColors, getStrokeColors);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(strokeWidths, getStrokeWidths);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(textures, getTextures);
|
||||
COPY_ENTITY_PROPERTY_TO_PROPERTIES(isUVModeStretch, getIsUVModeStretch);
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
@ -60,8 +64,10 @@ bool PolyLineEntityItem::setProperties(const EntityItemProperties& properties) {
|
|||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(lineWidth, setLineWidth);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(linePoints, setLinePoints);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(normals, setNormals);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(strokeColors, setStrokeColors);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(strokeWidths, setStrokeWidths);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(textures, setTextures);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(isUVModeStretch, setIsUVModeStretch);
|
||||
|
||||
if (somethingChanged) {
|
||||
bool wantDebug = false;
|
||||
|
@ -108,6 +114,15 @@ bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PolyLineEntityItem::setStrokeColors(const QVector<glm::vec3>& strokeColors) {
|
||||
withWriteLock([&] {
|
||||
_strokeColors = strokeColors;
|
||||
_strokeColorsChanged = true;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
||||
if (points.size() > MAX_POINTS_PER_LINE) {
|
||||
return false;
|
||||
|
@ -193,8 +208,10 @@ int PolyLineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* da
|
|||
READ_ENTITY_PROPERTY(PROP_LINE_WIDTH, float, setLineWidth);
|
||||
READ_ENTITY_PROPERTY(PROP_LINE_POINTS, QVector<glm::vec3>, setLinePoints);
|
||||
READ_ENTITY_PROPERTY(PROP_NORMALS, QVector<glm::vec3>, setNormals);
|
||||
READ_ENTITY_PROPERTY(PROP_STROKE_COLORS, QVector<glm::vec3>, setStrokeColors);
|
||||
READ_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, QVector<float>, setStrokeWidths);
|
||||
READ_ENTITY_PROPERTY(PROP_TEXTURES, QString, setTextures);
|
||||
READ_ENTITY_PROPERTY(PROP_IS_UV_MODE_STRETCH, bool, setIsUVModeStretch);
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
@ -207,8 +224,10 @@ EntityPropertyFlags PolyLineEntityItem::getEntityProperties(EncodeBitstreamParam
|
|||
requestedProperties += PROP_LINE_WIDTH;
|
||||
requestedProperties += PROP_LINE_POINTS;
|
||||
requestedProperties += PROP_NORMALS;
|
||||
requestedProperties += PROP_STROKE_COLORS;
|
||||
requestedProperties += PROP_STROKE_WIDTHS;
|
||||
requestedProperties += PROP_TEXTURES;
|
||||
requestedProperties += PROP_IS_UV_MODE_STRETCH;
|
||||
return requestedProperties;
|
||||
}
|
||||
|
||||
|
@ -227,8 +246,10 @@ void PolyLineEntityItem::appendSubclassData(OctreePacketData* packetData, Encode
|
|||
APPEND_ENTITY_PROPERTY(PROP_LINE_WIDTH, getLineWidth());
|
||||
APPEND_ENTITY_PROPERTY(PROP_LINE_POINTS, getLinePoints());
|
||||
APPEND_ENTITY_PROPERTY(PROP_NORMALS, getNormals());
|
||||
APPEND_ENTITY_PROPERTY(PROP_STROKE_COLORS, getStrokeColors());
|
||||
APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, getStrokeWidths());
|
||||
APPEND_ENTITY_PROPERTY(PROP_TEXTURES, getTextures());
|
||||
APPEND_ENTITY_PROPERTY(PROP_IS_UV_MODE_STRETCH, getIsUVModeStretch());
|
||||
}
|
||||
|
||||
void PolyLineEntityItem::debugDump() const {
|
||||
|
@ -258,6 +279,14 @@ QVector<glm::vec3> PolyLineEntityItem::getNormals() const {
|
|||
return result;
|
||||
}
|
||||
|
||||
QVector<glm::vec3> PolyLineEntityItem::getStrokeColors() const {
|
||||
QVector<glm::vec3> result;
|
||||
withReadLock([&] {
|
||||
result = _strokeColors;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
QVector<float> PolyLineEntityItem::getStrokeWidths() const {
|
||||
QVector<float> result;
|
||||
withReadLock([&] {
|
||||
|
|
|
@ -46,9 +46,11 @@ class PolyLineEntityItem : public EntityItem {
|
|||
xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; }
|
||||
|
||||
void setColor(const rgbColor& value) {
|
||||
_strokeColorsChanged = true;
|
||||
memcpy(_color, value, sizeof(_color));
|
||||
}
|
||||
void setColor(const xColor& value) {
|
||||
_strokeColorsChanged = true;
|
||||
_color[RED_INDEX] = value.red;
|
||||
_color[GREEN_INDEX] = value.green;
|
||||
_color[BLUE_INDEX] = value.blue;
|
||||
|
@ -64,9 +66,15 @@ class PolyLineEntityItem : public EntityItem {
|
|||
bool setNormals(const QVector<glm::vec3>& normals);
|
||||
QVector<glm::vec3> getNormals() const;
|
||||
|
||||
bool setStrokeColors(const QVector<glm::vec3>& strokeColors);
|
||||
QVector<glm::vec3> getStrokeColors() const;
|
||||
|
||||
bool setStrokeWidths(const QVector<float>& strokeWidths);
|
||||
QVector<float> getStrokeWidths() const;
|
||||
|
||||
void setIsUVModeStretch(bool isUVModeStretch){ _isUVModeStretch = isUVModeStretch; }
|
||||
bool getIsUVModeStretch() const{ return _isUVModeStretch; }
|
||||
|
||||
QString getTextures() const;
|
||||
void setTextures(const QString& textures);
|
||||
|
||||
|
@ -76,10 +84,11 @@ class PolyLineEntityItem : public EntityItem {
|
|||
|
||||
bool pointsChanged() const { return _pointsChanged; }
|
||||
bool normalsChanged() const { return _normalsChanged; }
|
||||
bool strokeColorsChanged() const { return _strokeColorsChanged; }
|
||||
bool strokeWidthsChanged() const { return _strokeWidthsChanged; }
|
||||
bool texturesChanged() const { return _texturesChangedFlag; }
|
||||
void resetTexturesChanged() { _texturesChangedFlag = false; }
|
||||
void resetPolyLineChanged() { _strokeWidthsChanged = _normalsChanged = _pointsChanged = false; }
|
||||
void resetPolyLineChanged() { _strokeColorsChanged = _strokeWidthsChanged = _normalsChanged = _pointsChanged = false; }
|
||||
|
||||
|
||||
// never have a ray intersection pick a PolyLineEntityItem.
|
||||
|
@ -103,11 +112,14 @@ private:
|
|||
float _lineWidth { DEFAULT_LINE_WIDTH };
|
||||
bool _pointsChanged { true };
|
||||
bool _normalsChanged { true };
|
||||
bool _strokeColorsChanged { true };
|
||||
bool _strokeWidthsChanged { true };
|
||||
QVector<glm::vec3> _points;
|
||||
QVector<glm::vec3> _normals;
|
||||
QVector<glm::vec3> _strokeColors;
|
||||
QVector<float> _strokeWidths;
|
||||
QString _textures;
|
||||
bool _isUVModeStretch;
|
||||
bool _texturesChangedFlag { false };
|
||||
mutable QReadWriteLock _quadReadWriteLock;
|
||||
};
|
||||
|
|
|
@ -29,6 +29,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
|
|||
case PacketType::EntityAdd:
|
||||
case PacketType::EntityEdit:
|
||||
case PacketType::EntityData:
|
||||
return VERSION_ENTITIES_STROKE_COLOR_PROPERTY;
|
||||
case PacketType::EntityPhysics:
|
||||
return VERSION_ENTITIES_HAZE;
|
||||
case PacketType::EntityQuery:
|
||||
|
|
|
@ -269,6 +269,9 @@ const PacketVersion VERSION_ENTITIES_HAS_HIGHLIGHT_SCRIPTING_INTERFACE = 72;
|
|||
const PacketVersion VERSION_ENTITIES_ANIMATION_ALLOW_TRANSLATION_PROPERTIES = 73;
|
||||
const PacketVersion VERSION_ENTITIES_HAS_CERTIFICATE_PROPERTIES = 74;
|
||||
const PacketVersion VERSION_ENTITIES_HAZE = 75;
|
||||
const PacketVersion VERSION_ENTITIES_UV_MODE_PROPERTY = 76;
|
||||
const PacketVersion VERSION_ENTITIES_STROKE_COLOR_PROPERTY = 77;
|
||||
|
||||
|
||||
enum class EntityQueryPacketVersion: PacketVersion {
|
||||
JSONFilter = 18,
|
||||
|
|
|
@ -32,7 +32,7 @@ var DEFAULT_SCRIPTS_COMBINED = [
|
|||
"system/tablet-ui/tabletUI.js"
|
||||
];
|
||||
var DEFAULT_SCRIPTS_SEPARATE = [
|
||||
"system/controllers/controllerScripts.js",
|
||||
"system/controllers/controllerScripts.js"
|
||||
// "system/chat.js"
|
||||
];
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ For usage and examples: colpick.com/plugin
|
|||
cal.data('colpick').color = col = hexToHsb(fixHex(this.value));
|
||||
fillRGBFields(col, cal.get(0));
|
||||
fillHSBFields(col, cal.get(0));
|
||||
fillHexFields(col, cal.get(0));
|
||||
} else if (this.parentNode.className.indexOf('_hsb') > 0) {
|
||||
cal.data('colpick').color = col = fixHSB({
|
||||
h: parseInt(cal.data('colpick').fields.eq(4).val(), 10),
|
||||
|
@ -76,6 +77,7 @@ For usage and examples: colpick.com/plugin
|
|||
});
|
||||
fillRGBFields(col, cal.get(0));
|
||||
fillHexFields(col, cal.get(0));
|
||||
fillHSBFields(col, cal.get(0));
|
||||
} else {
|
||||
cal.data('colpick').color = col = rgbToHsb(fixRGB({
|
||||
r: parseInt(cal.data('colpick').fields.eq(1).val(), 10),
|
||||
|
@ -84,6 +86,7 @@ For usage and examples: colpick.com/plugin
|
|||
}));
|
||||
fillHexFields(col, cal.get(0));
|
||||
fillHSBFields(col, cal.get(0));
|
||||
fillRGBFields(col, cal.get(0));
|
||||
}
|
||||
setSelector(col, cal.get(0));
|
||||
setHue(col, cal.get(0));
|
||||
|
|
Loading…
Reference in a new issue