mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-24 12:41:36 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into hdr
This commit is contained in:
commit
86e9c5ac9b
10 changed files with 431 additions and 47 deletions
66
examples/entityScripts/tribble.js
Normal file
66
examples/entityScripts/tribble.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
(function () {
|
||||
// See tests/performance/tribbles.js
|
||||
var dimensions, oldColor, entityID,
|
||||
editRate = 60,
|
||||
moveRate = 1,
|
||||
scale = 2,
|
||||
accumulated = 0,
|
||||
increment = {red: 1, green: 1, blue: 1},
|
||||
hasUpdate = false,
|
||||
shutdown = false;
|
||||
function nextWavelength(color) {
|
||||
var old = oldColor[color];
|
||||
if (old === 255) {
|
||||
increment[color] = -1;
|
||||
} else if (old === 0) {
|
||||
increment[color] = 1;
|
||||
}
|
||||
var next = (old + increment[color]) % 256;
|
||||
return next;
|
||||
}
|
||||
function update(delta) { // High frequency stuff is done in update in case we fall behind.
|
||||
accumulated += delta;
|
||||
if (accumulated > (1 / editRate)) {
|
||||
var newColor = {red: nextWavelength('red'), green: nextWavelength('green'), blue: nextWavelength('blue')};
|
||||
oldColor = newColor;
|
||||
Entities.editEntity(entityID, {color: newColor});
|
||||
accumulated = 0;
|
||||
}
|
||||
}
|
||||
function randomCentered() { return Math.random() - 0.5; }
|
||||
function randomVector() { return {x: randomCentered() * dimensions.x, y: randomCentered() * dimensions.y, z: randomCentered() * dimensions.z}; }
|
||||
function move() {
|
||||
var newData = {velocity: Vec3.sum({x: 0, y: 1, z: 0}, randomVector()), angularVelocity: Vec3.multiply(Math.PI, randomVector())};
|
||||
var nextChange = Math.ceil(Math.random() * 2000 / moveRate);
|
||||
Entities.editEntity(entityID, newData);
|
||||
if (!shutdown) { Script.setTimeout(move, nextChange); }
|
||||
}
|
||||
this.preload = function (givenEntityID) {
|
||||
entityID = givenEntityID;
|
||||
var properties = Entities.getEntityProperties(entityID);
|
||||
var userData = properties.userData && JSON.parse(properties.userData);
|
||||
var moveTimeout = userData ? userData.moveTimeout : 0;
|
||||
var editTimeout = userData ? userData.editTimeout : 0;
|
||||
editRate = (userData && userData.editRate) || editRate;
|
||||
moveRate = (moveRate && userData.moveRate) || moveRate;
|
||||
oldColor = properties.color;
|
||||
dimensions = Vec3.multiply(scale, properties.dimensions);
|
||||
if (editTimeout) {
|
||||
hasUpdate = true;
|
||||
Script.update.connect(update);
|
||||
if (editTimeout > 0) {
|
||||
Script.setTimeout(function () { Script.update.disconnect(update); hasUpdate = false; }, editTimeout * 1000);
|
||||
}
|
||||
}
|
||||
if (moveTimeout) {
|
||||
Script.setTimeout(move, 1000);
|
||||
if (moveTimeout > 0) {
|
||||
Script.setTimeout(function () { shutdown = true; }, moveTimeout * 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.unload = function () {
|
||||
shutdown = true;
|
||||
if (hasUpdate) { Script.update.disconnect(update); }
|
||||
};
|
||||
})
|
|
@ -28,8 +28,7 @@
|
|||
var PAINT_TRIGGER_THRESHOLD = 0.6;
|
||||
var MIN_STROKE_WIDTH = 0.0005;
|
||||
var MAX_STROKE_WIDTH = 0.03;
|
||||
|
||||
var textureURL = "https://s3.amazonaws.com/hifi-public/eric/textures/paintStrokes/paintStroke.png";
|
||||
var textureURL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/textures/paintStroke.png";
|
||||
|
||||
var TRIGGER_CONTROLS = [
|
||||
Controller.Standard.LT,
|
||||
|
@ -170,7 +169,7 @@
|
|||
type: "PolyLine",
|
||||
name: "paintStroke",
|
||||
color: this.strokeColor,
|
||||
textures: "https://s3.amazonaws.com/hifi-public/eric/textures/paintStrokes/paintStroke.png",
|
||||
textures: textureURL,
|
||||
dimensions: {
|
||||
x: 50,
|
||||
y: 50,
|
||||
|
|
|
@ -41,6 +41,7 @@ var whiteboard = Entities.addEntity({
|
|||
type: "Model",
|
||||
shapeType: "box",
|
||||
modelURL: modelURL,
|
||||
dimensions: {x: 2, y: 2.67, z: 0.76},
|
||||
name: "whiteboard base",
|
||||
position: center,
|
||||
rotation: rotation,
|
||||
|
@ -53,8 +54,11 @@ var colorIndicatorPosition = {
|
|||
};
|
||||
colorIndicatorPosition.y += 1.55;
|
||||
colorIndicatorPosition = Vec3.sum(colorIndicatorPosition, Vec3.multiply(-0.1, Quat.getFront(rotation)));
|
||||
var colorIndicatorBorderDimensions = {x: 1.84, y: 0.46, z: 0.04};
|
||||
var colorIndicatorBorder = Entities.addEntity({
|
||||
type: "Model",
|
||||
name: "Whiteboard Color Indicator Border",
|
||||
dimensions: colorIndicatorBorderDimensions,
|
||||
position: colorIndicatorPosition,
|
||||
modelURL: colorIndicatorBorderModelURL,
|
||||
rotation: rotation,
|
||||
|
@ -63,10 +67,12 @@ var colorIndicatorBorder = Entities.addEntity({
|
|||
|
||||
var surfaceCenter = Vec3.sum(center, Vec3.multiply(-0.1, Quat.getFront(rotation)));
|
||||
surfaceCenter.y += 0.6;
|
||||
var whiteboardDimensions = {x: 1.8, y: 1.3, z: 0.01};
|
||||
var drawingSurface = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: surfaceModelURL,
|
||||
shapeType: "box",
|
||||
dimensions: whiteboardDimensions,
|
||||
name: "whiteboard surface",
|
||||
position: surfaceCenter,
|
||||
script: scriptURL,
|
||||
|
@ -111,6 +117,7 @@ var eraser = Entities.addEntity({
|
|||
type: "Model",
|
||||
modelURL: eraserModelURL,
|
||||
position: eraserPosition,
|
||||
dimensions: {x: 1.73, y: 0.47, z: 0.11},
|
||||
name: "Eraser",
|
||||
script: scriptURL,
|
||||
rotation: rotation,
|
||||
|
@ -122,11 +129,7 @@ var eraser = Entities.addEntity({
|
|||
})
|
||||
});
|
||||
|
||||
Script.setTimeout(function() {
|
||||
whiteboardDimensions = Entities.getEntityProperties(whiteboard, "naturalDimensions").naturalDimensions;
|
||||
colorIndicatorBorderDimensions = Entities.getEntityProperties(colorIndicatorBorder, "naturalDimensions").naturalDimensions;
|
||||
setUp();
|
||||
}, 2000)
|
||||
setUp();
|
||||
|
||||
|
||||
function setUp() {
|
||||
|
@ -138,6 +141,7 @@ function setUp() {
|
|||
blockerPosition = Vec3.sum(blockerPosition, Vec3.multiply(-1, Quat.getFront(rotation)));
|
||||
blocker = Entities.addEntity({
|
||||
type: "Box",
|
||||
name: "Whiteboard Blocker",
|
||||
rotation: rotation,
|
||||
position: blockerPosition,
|
||||
dimensions: {
|
||||
|
@ -148,26 +152,17 @@ function setUp() {
|
|||
shapeType: "box",
|
||||
visible: false
|
||||
});
|
||||
|
||||
var eraseModelDimensions = Entities.getEntityProperties(eraser, "naturalDimensions").naturalDimensions;
|
||||
Entities.editEntity(eraser, {
|
||||
dimensions: eraseModelDimensions
|
||||
});
|
||||
Entities.editEntity(colorIndicatorBorder, {
|
||||
dimensions: colorIndicatorBorderDimensions
|
||||
});
|
||||
|
||||
scriptURL = Script.resolvePath("colorIndicatorEntityScript.js");
|
||||
var colorIndicatorPosition = Vec3.sum(center, {
|
||||
x: 0,
|
||||
y: whiteboardDimensions.y / 2 + colorIndicatorBorderDimensions.y / 2,
|
||||
y: whiteboardDimensions.y / 2 + colorIndicatorBorderDimensions.y * 2,
|
||||
z: 0
|
||||
});
|
||||
colorIndicatorPosition = Vec3.sum(colorIndicatorPosition, Vec3.multiply(-.1, Quat.getFront(rotation)));
|
||||
colorIndicatorPosition = Vec3.sum(colorIndicatorPosition, Vec3.multiply(-0.1, Quat.getFront(rotation)));
|
||||
var colorIndicatorBoxDimensions = Vec3.multiply(colorIndicatorBorderDimensions, 0.9);
|
||||
colorIndicatorBox = Entities.addEntity({
|
||||
type: "Box",
|
||||
name: "Color Indicator",
|
||||
name: "Whiteboard Color Indicator",
|
||||
color: colors[0],
|
||||
rotation: rotation,
|
||||
position: colorIndicatorPosition,
|
||||
|
@ -205,13 +200,13 @@ function setUp() {
|
|||
colorBoxPosition = Vec3.sum(colorBoxPosition, Vec3.multiply(palleteDepthOffset, Quat.getFront(rotation)));
|
||||
colorBoxPosition.y += palleteHeightOffset;
|
||||
var spaceBetweenColorBoxes = Vec3.multiply(direction, colorSquareDimensions.x * 1.76);
|
||||
var palleteXOffset = Vec3.multiply(direction, 0.43);
|
||||
var palleteXOffset = Vec3.multiply(direction, 0.33);
|
||||
colorBoxPosition = Vec3.sum(colorBoxPosition, palleteXOffset);
|
||||
var scriptURL = Script.resolvePath("colorSelectorEntityScript.js");
|
||||
for (var i = 0; i < colors.length; i++) {
|
||||
var colorBox = Entities.addEntity({
|
||||
type: "Box",
|
||||
name: "Color Selector",
|
||||
name: "Whiteboard Color Selector",
|
||||
position: colorBoxPosition,
|
||||
dimensions: colorSquareDimensions,
|
||||
rotation: rotation,
|
||||
|
|
124
examples/tests/performance/renderableMatrix.js
Normal file
124
examples/tests/performance/renderableMatrix.js
Normal file
|
@ -0,0 +1,124 @@
|
|||
"use strict";
|
||||
/*jslint nomen: true, plusplus: true, vars: true*/
|
||||
var Entities, Script, print, Vec3, MyAvatar, Camera, Quat;
|
||||
//
|
||||
// Created by Howard Stearns
|
||||
// Copyright 2016 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
|
||||
//
|
||||
// Creates a rectangular matrix of objects with no physical or entity changes after creation.
|
||||
// Useful for testing the rendering, LOD, and octree storage aspects of the system.
|
||||
//
|
||||
|
||||
var LIFETIME = 60;
|
||||
// Matrix will be axis-aligned, approximately all in this field of view.
|
||||
// As special case, if zero, grid is centered above your head.
|
||||
var MINIMUM_VIEW_ANGLE_IN_RADIANS = 30 * Math.PI / 180; // 30 degrees
|
||||
var ROWS_X = 10;
|
||||
var ROWS_Y = 10;
|
||||
var ROWS_Z = 10;
|
||||
var SEPARATION = 10;
|
||||
var SIZE = 1;
|
||||
var TYPES_TO_USE = [ // Entities will be populated from this list set by the script writer for different tests.
|
||||
'Box',
|
||||
'Sphere',
|
||||
//'Light',
|
||||
//'ParticleEffect',
|
||||
//'Web',
|
||||
//"https://hifi-content.s3.amazonaws.com/ozan/dev/sets/lowpoly_island/CypressTreeGroup.fbx",
|
||||
//"http://s3.amazonaws.com/hifi-public/marketplace/hificontent/Games/blocks/block.fbx",
|
||||
];
|
||||
var MODEL_SCALE = { x: 1, y: 2, z: 3 }; // how to stretch out models proportionally to SIZE
|
||||
// Note that when creating things quickly, the entity server will ignore data if we send updates too quickly.
|
||||
// like Internet MTU, these rates are set by th domain operator, so in this script there is a RATE_PER_SECOND
|
||||
// variable letting you set this speed. If entities are missing from the grid after a relog, this number
|
||||
// being too high may be the reason.
|
||||
var RATE_PER_SECOND = 1000; // The entity server will drop data if we create things too fast.
|
||||
var SCRIPT_INTERVAL = 100;
|
||||
|
||||
var ALLOWED_TYPES = ['Box', 'Sphere', 'Light', 'ParticleEffect', 'Web']; // otherwise assumed to be a model url
|
||||
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var z = 0;
|
||||
var xDim = ROWS_X * SEPARATION;
|
||||
var yDim = ROWS_Y * SEPARATION;
|
||||
var zDim = ROWS_Z * SEPARATION;
|
||||
var centered = !MINIMUM_VIEW_ANGLE_IN_RADIANS;
|
||||
var approximateNearDistance = !centered &&
|
||||
Math.max(xDim, 2 * yDim, zDim) / (2 * Math.tan(MINIMUM_VIEW_ANGLE_IN_RADIANS / 2)); // matrix is up, not vertically centered
|
||||
var o = Vec3.sum(MyAvatar.position,
|
||||
Vec3.sum({x: xDim / -2, y: 0, z: zDim / -2},
|
||||
centered ? {x: 0, y: SEPARATION, z: 0} : Vec3.multiply(approximateNearDistance, Quat.getFront(Camera.orientation))));
|
||||
var totalCreated = 0;
|
||||
var startTime = new Date();
|
||||
var totalToCreate = ROWS_X * ROWS_Y * ROWS_Z;
|
||||
print("Creating " + totalToCreate + " entities starting at " + startTime);
|
||||
|
||||
Script.setInterval(function () {
|
||||
if (!Entities.serversExist() || !Entities.canRez()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var numToCreate = Math.min(RATE_PER_SECOND * (SCRIPT_INTERVAL / 1000.0), totalToCreate - totalCreated);
|
||||
var chooseTypeRandomly = TYPES_TO_USE.length !== 2;
|
||||
var i, typeIndex, type, isModel, properties;
|
||||
for (i = 0; i < numToCreate; i++) {
|
||||
typeIndex = chooseTypeRandomly ? Math.floor(Math.random() * TYPES_TO_USE.length) : i % TYPES_TO_USE.length;
|
||||
type = TYPES_TO_USE[typeIndex];
|
||||
isModel = ALLOWED_TYPES.indexOf(type) === -1;
|
||||
properties = {
|
||||
position: { x: o.x + SIZE + (x * SEPARATION), y: o.y + SIZE + (y * SEPARATION), z: o.z + SIZE + (z * SEPARATION) },
|
||||
name: "renderable-" + x + "-" + y + "-" + z,
|
||||
type: isModel ? 'Model' : type,
|
||||
dimensions: isModel ? Vec3.multiply(SIZE, MODEL_SCALE) : { x: SIZE, y: SIZE, z: SIZE },
|
||||
ignoreCollisions: true,
|
||||
collisionsWillMove: false,
|
||||
lifetime: LIFETIME
|
||||
};
|
||||
if (isModel) {
|
||||
properties.modelURL = type;
|
||||
} else if (type === 'Web') {
|
||||
properties.sourceUrl = 'https://highfidelity.com';
|
||||
} else {
|
||||
properties.color = { red: x / ROWS_X * 255, green: y / ROWS_Y * 255, blue: z / ROWS_Z * 255 };
|
||||
if (type === 'ParticleEffect') {
|
||||
properties.emitOrientation = Quat.fromPitchYawRollDegrees(-90.0, 0.0, 0.0);
|
||||
properties.particleRadius = 0.04;
|
||||
properties.radiusSpread = 0.0;
|
||||
properties.emitRate = 100;
|
||||
properties.emitSpeed = 1;
|
||||
properties.speedSpread = 0.0;
|
||||
properties.emitAcceleration = { x: 0.0, y: -0.3, z: 0.0 };
|
||||
properties.accelerationSpread = { x: 0.0, y: 0.0, z: 0.0 };
|
||||
properties.textures = "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png";
|
||||
properties.lifespan = 5.0;
|
||||
properties.colorStart = properties.color;
|
||||
properties.colorFinish = properties.color;
|
||||
properties.alphaFinish = 0.0;
|
||||
properties.polarFinish = 2.0 * Math.PI / 180;
|
||||
} else if (type === 'Light') {
|
||||
properties.dimensions = Vec3.multiply(SEPARATION, properties.position);
|
||||
}
|
||||
}
|
||||
Entities.addEntity(properties);
|
||||
totalCreated++;
|
||||
|
||||
x++;
|
||||
if (x === ROWS_X) {
|
||||
x = 0;
|
||||
y++;
|
||||
if (y === ROWS_Y) {
|
||||
y = 0;
|
||||
z++;
|
||||
print("Created: " + totalCreated);
|
||||
}
|
||||
}
|
||||
if (z === ROWS_Z) {
|
||||
print("Total: " + totalCreated + " entities in " + ((new Date() - startTime) / 1000.0) + " seconds.");
|
||||
Script.stop();
|
||||
}
|
||||
}
|
||||
}, SCRIPT_INTERVAL);
|
97
examples/tests/performance/staticEdits.js
Normal file
97
examples/tests/performance/staticEdits.js
Normal file
|
@ -0,0 +1,97 @@
|
|||
"use strict";
|
||||
/*jslint nomen: true, plusplus: true, vars: true*/
|
||||
var Entities, Script, print, Vec3, MyAvatar;
|
||||
//
|
||||
// Created by Howard Stearns
|
||||
// Copyright 2016 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
|
||||
//
|
||||
// Creates a rectangular matrix of objects overhed, and edits them at EDIT_FREQUENCY_TARGET.
|
||||
// Reports ms since last edit, ms to edit all the created entities, and average ms to edit one entity,
|
||||
// so that you can measure how many edits can be made.
|
||||
//
|
||||
var LIFETIME = 15;
|
||||
var EDIT_FREQUENCY_TARGET = 60; // hertz
|
||||
var ROWS_X = 10;
|
||||
var ROWS_Y = 1;
|
||||
var ROWS_Z = 10;
|
||||
var SEPARATION = 10.0;
|
||||
var SIZE = 1.0;
|
||||
// Note that when creating things quickly, the entity server will ignore data if we send updates too quickly.
|
||||
// like Internet MTU, these rates are set by th domain operator, so in this script there is a RATE_PER_SECOND
|
||||
// variable letting you set this speed. If entities are missing from the grid after a relog, this number
|
||||
// being too high may be the reason.
|
||||
var RATE_PER_SECOND = 600; // The entity server will drop data if we create things too fast.
|
||||
var SCRIPT_INTERVAL = 100;
|
||||
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var z = 0;
|
||||
var o = Vec3.sum(MyAvatar.position, {x: ROWS_X * SEPARATION / -2, y: SEPARATION, z: ROWS_Z * SEPARATION / -2});
|
||||
var totalCreated = 0;
|
||||
var startTime = new Date();
|
||||
var totalToCreate = ROWS_X * ROWS_Y * ROWS_Z;
|
||||
print("Creating " + totalToCreate + " entities starting at " + startTime);
|
||||
|
||||
var ids = [], colors = [], flasher, lastService = Date.now();
|
||||
function doFlash() { // One could call this in an interval timer, an update, or even a separate entity script.
|
||||
var i, oldColor, newColor;
|
||||
var start = Date.now();
|
||||
for (i = 0; i < ids.length; i++) {
|
||||
oldColor = colors[i];
|
||||
newColor = {red: oldColor.green, green: oldColor.blue, blue: oldColor.red};
|
||||
colors[i] = newColor;
|
||||
Entities.editEntity(ids[i], {color: newColor});
|
||||
}
|
||||
var elapsed = Date.now() - start, serviceTime = start - lastService;
|
||||
lastService = start;
|
||||
print(serviceTime, elapsed, elapsed / totalCreated); // ms since last flash, ms to edit all entities, average ms to edit one entity
|
||||
}
|
||||
function stopFlash() {
|
||||
Script.clearTimeout(flasher);
|
||||
Script.stop();
|
||||
}
|
||||
var creator = Script.setInterval(function () {
|
||||
if (!Entities.serversExist() || !Entities.canRez()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var numToCreate = Math.min(RATE_PER_SECOND * (SCRIPT_INTERVAL / 1000.0), totalToCreate - totalCreated);
|
||||
var i, properties;
|
||||
for (i = 0; i < numToCreate; i++) {
|
||||
properties = {
|
||||
position: { x: o.x + SIZE + (x * SEPARATION), y: o.y + SIZE + (y * SEPARATION), z: o.z + SIZE + (z * SEPARATION) },
|
||||
name: "gridTest",
|
||||
type: 'Box',
|
||||
dimensions: {x: SIZE, y: SIZE, z: SIZE},
|
||||
ignoreCollisions: true,
|
||||
collisionsWillMove: false,
|
||||
lifetime: LIFETIME,
|
||||
color: {red: x / ROWS_X * 255, green: y / ROWS_Y * 255, blue: z / ROWS_Z * 255}
|
||||
};
|
||||
colors.push(properties.color);
|
||||
ids.push(Entities.addEntity(properties));
|
||||
totalCreated++;
|
||||
|
||||
x++;
|
||||
if (x === ROWS_X) {
|
||||
x = 0;
|
||||
y++;
|
||||
if (y === ROWS_Y) {
|
||||
y = 0;
|
||||
z++;
|
||||
print("Created: " + totalCreated);
|
||||
}
|
||||
}
|
||||
if (z === ROWS_Z) {
|
||||
print("Total: " + totalCreated + " entities in " + ((new Date() - startTime) / 1000.0) + " seconds.");
|
||||
Script.clearTimeout(creator);
|
||||
flasher = Script.setInterval(doFlash, Math.ceil((1 / EDIT_FREQUENCY_TARGET) * 1000));
|
||||
Script.setTimeout(stopFlash, LIFETIME * 1000);
|
||||
}
|
||||
}
|
||||
}, SCRIPT_INTERVAL);
|
||||
Script.scriptEnding.connect(function () { Script.clearTimeout(flasher); });
|
||||
|
96
examples/tests/performance/tribbles.js
Normal file
96
examples/tests/performance/tribbles.js
Normal file
|
@ -0,0 +1,96 @@
|
|||
"use strict";
|
||||
/*jslint nomen: true, plusplus: true, vars: true*/
|
||||
var Vec3, Quat, MyAvatar, Entities, Camera, Script, print;
|
||||
//
|
||||
// Created by Howard Stearns
|
||||
// Copyright 2016 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
|
||||
//
|
||||
// Drops a bunch of physical spheres in front of you, each running a script that will:
|
||||
// * Edit color at EDIT_RATE for EDIT_TIMEOUT.
|
||||
// * Randomly move at an average of MOVE_RATE for MOVE_TIMEOUT.
|
||||
// The _TIMEOUT parameters can be 0 for no activity, and -1 to be active indefinitely.
|
||||
//
|
||||
|
||||
var NUMBER_TO_CREATE = 120;
|
||||
var LIFETIME = 60; // seconds
|
||||
var EDIT_RATE = 60; // hz
|
||||
var EDIT_TIMEOUT = -1;
|
||||
var MOVE_RATE = 1; // hz
|
||||
var MOVE_TIMEOUT = LIFETIME / 2;
|
||||
|
||||
var SIZE = 0.5;
|
||||
var TYPE = "Sphere";
|
||||
// Note that when creating things quickly, the entity server will ignore data if we send updates too quickly.
|
||||
// like Internet MTU, these rates are set by th domain operator, so in this script there is a RATE_PER_SECOND
|
||||
// variable letting you set this speed. If entities are missing from the grid after a relog, this number
|
||||
// being too high may be the reason.
|
||||
var RATE_PER_SECOND = 600; // The entity server will drop data if we create things too fast.
|
||||
var SCRIPT_INTERVAL = 100;
|
||||
|
||||
var GRAVITY = { x: 0, y: -9.8, z: 0 };
|
||||
var VELOCITY = { x: 0.0, y: 0, z: 0 };
|
||||
var ANGULAR_VELOCITY = { x: 1, y: 1, z: 1 };
|
||||
|
||||
var DAMPING = 0.5;
|
||||
var ANGULAR_DAMPING = 0.5;
|
||||
|
||||
var RANGE = 3;
|
||||
var HOW_FAR_IN_FRONT_OF_ME = RANGE * 3;
|
||||
var HOW_FAR_UP = RANGE / 1.5; // higher (for uneven ground) above range/2 (for distribution)
|
||||
|
||||
var x = 0;
|
||||
var z = 0;
|
||||
var totalCreated = 0;
|
||||
var offset = Vec3.sum(Vec3.multiply(HOW_FAR_UP, Vec3.UNIT_Y),
|
||||
Vec3.multiply(HOW_FAR_IN_FRONT_OF_ME, Quat.getFront(Camera.orientation)));
|
||||
var center = Vec3.sum(MyAvatar.position, offset);
|
||||
|
||||
function randomVector(range) {
|
||||
return {
|
||||
x: (Math.random() - 0.5) * range.x,
|
||||
y: (Math.random() - 0.5) * range.y,
|
||||
z: (Math.random() - 0.5) * range.z
|
||||
};
|
||||
}
|
||||
|
||||
Script.setInterval(function () {
|
||||
if (!Entities.serversExist() || !Entities.canRez()) {
|
||||
return;
|
||||
}
|
||||
if (totalCreated >= NUMBER_TO_CREATE) {
|
||||
print("Created " + totalCreated + " tribbles.");
|
||||
Script.stop();
|
||||
}
|
||||
|
||||
var i, numToCreate = RATE_PER_SECOND * (SCRIPT_INTERVAL / 1000.0);
|
||||
var parameters = JSON.stringify({
|
||||
moveTimeout: MOVE_TIMEOUT,
|
||||
moveRate: MOVE_RATE,
|
||||
editTimeout: EDIT_TIMEOUT,
|
||||
editRate: EDIT_RATE
|
||||
});
|
||||
for (i = 0; (i < numToCreate) && (totalCreated < NUMBER_TO_CREATE); i++) {
|
||||
Entities.addEntity({
|
||||
userData: parameters,
|
||||
type: TYPE,
|
||||
name: "tribble-" + totalCreated,
|
||||
position: Vec3.sum(center, randomVector({ x: RANGE, y: RANGE, z: RANGE })),
|
||||
dimensions: {x: SIZE, y: SIZE, z: SIZE},
|
||||
color: {red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255},
|
||||
velocity: VELOCITY,
|
||||
angularVelocity: Vec3.multiply(Math.random(), ANGULAR_VELOCITY),
|
||||
damping: DAMPING,
|
||||
angularDamping: ANGULAR_DAMPING,
|
||||
gravity: GRAVITY,
|
||||
collisionsWillMove: true,
|
||||
lifetime: LIFETIME,
|
||||
script: "https://s3.amazonaws.com/hifi-public/scripts/entityScripts/tribble.js"
|
||||
});
|
||||
|
||||
totalCreated++;
|
||||
}
|
||||
}, SCRIPT_INTERVAL);
|
||||
|
|
@ -100,6 +100,21 @@ int RenderableModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned c
|
|||
return bytesRead;
|
||||
}
|
||||
|
||||
QVariantMap RenderableModelEntityItem::parseTexturesToMap(QString textures) {
|
||||
if (textures == "") {
|
||||
return QVariantMap();
|
||||
}
|
||||
|
||||
QString jsonTextures = "{\"" + textures.replace(":\"", "\":\"").replace(",\n", ",\"") + "}";
|
||||
QJsonParseError error;
|
||||
QJsonDocument texturesAsJson = QJsonDocument::fromJson(jsonTextures.toUtf8(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(entitiesrenderer) << "Could not evaluate textures property value:" << _textures;
|
||||
}
|
||||
QJsonObject texturesAsJsonObject = texturesAsJson.object();
|
||||
return texturesAsJsonObject.toVariantMap();
|
||||
}
|
||||
|
||||
void RenderableModelEntityItem::remapTextures() {
|
||||
if (!_model) {
|
||||
return; // nothing to do if we don't have a model
|
||||
|
@ -124,13 +139,8 @@ void RenderableModelEntityItem::remapTextures() {
|
|||
// since we're changing here, we need to run through our current texture map
|
||||
// and any textures in the recently mapped texture, that is not in our desired
|
||||
// textures, we need to "unset"
|
||||
QJsonDocument currentTexturesAsJson = QJsonDocument::fromJson(_currentTextures.toUtf8());
|
||||
QJsonObject currentTexturesAsJsonObject = currentTexturesAsJson.object();
|
||||
QVariantMap currentTextureMap = currentTexturesAsJsonObject.toVariantMap();
|
||||
|
||||
QJsonDocument texturesAsJson = QJsonDocument::fromJson(_textures.toUtf8());
|
||||
QJsonObject texturesAsJsonObject = texturesAsJson.object();
|
||||
QVariantMap textureMap = texturesAsJsonObject.toVariantMap();
|
||||
QVariantMap currentTextureMap = parseTexturesToMap(_currentTextures);
|
||||
QVariantMap textureMap = parseTexturesToMap(_textures);
|
||||
|
||||
foreach(const QString& key, currentTextureMap.keys()) {
|
||||
// if the desired texture map (what we're setting the textures to) doesn't
|
||||
|
|
|
@ -80,6 +80,7 @@ public:
|
|||
virtual void resizeJointArrays(int newSize = -1) override;
|
||||
|
||||
private:
|
||||
QVariantMap parseTexturesToMap(QString textures);
|
||||
void remapTextures();
|
||||
|
||||
Model* _model = nullptr;
|
||||
|
|
|
@ -70,7 +70,7 @@ void GeometryReader::run() {
|
|||
} else if (_url.path().toLower().endsWith(".obj")) {
|
||||
fbxgeo = OBJReader().readOBJ(_data, _mapping, _url);
|
||||
} else {
|
||||
QString errorStr("usupported format");
|
||||
QString errorStr("unsupported format");
|
||||
emit onError(NetworkGeometry::ModelParseError, errorStr);
|
||||
}
|
||||
emit onSuccess(fbxgeo);
|
||||
|
@ -168,22 +168,22 @@ QStringList NetworkGeometry::getTextureNames() const {
|
|||
for (auto&& material : _materials) {
|
||||
if (!material->diffuseTextureName.isEmpty() && material->diffuseTexture) {
|
||||
QString textureURL = material->diffuseTexture->getURL().toString();
|
||||
result << material->diffuseTextureName + ":" + textureURL;
|
||||
result << material->diffuseTextureName + ":\"" + textureURL + "\"";
|
||||
}
|
||||
|
||||
if (!material->normalTextureName.isEmpty() && material->normalTexture) {
|
||||
QString textureURL = material->normalTexture->getURL().toString();
|
||||
result << material->normalTextureName + ":" + textureURL;
|
||||
result << material->normalTextureName + ":\"" + textureURL + "\"";
|
||||
}
|
||||
|
||||
if (!material->specularTextureName.isEmpty() && material->specularTexture) {
|
||||
QString textureURL = material->specularTexture->getURL().toString();
|
||||
result << material->specularTextureName + ":" + textureURL;
|
||||
result << material->specularTextureName + ":\"" + textureURL + "\"";
|
||||
}
|
||||
|
||||
if (!material->emissiveTextureName.isEmpty() && material->emissiveTexture) {
|
||||
QString textureURL = material->emissiveTexture->getURL().toString();
|
||||
result << material->emissiveTextureName + ":" + textureURL;
|
||||
result << material->emissiveTextureName + ":\"" + textureURL + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,19 +42,15 @@ QmlWebWindowClass::QmlWebWindowClass(QObject* qmlWindow) : QmlWindowClass(qmlWin
|
|||
void QmlWebWindowClass::handleNavigation(const QString& url) {
|
||||
}
|
||||
|
||||
QString QmlWebWindowClass::getURL() const {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QString result;
|
||||
QMetaObject::invokeMethod(const_cast<QmlWebWindowClass*>(this), "getURL", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QString, result));
|
||||
return result;
|
||||
}
|
||||
|
||||
return _qmlWindow->property(URL_PROPERTY).toString();
|
||||
QString QmlWebWindowClass::getURL() const {
|
||||
QVariant result = DependencyManager::get<OffscreenUi>()->returnFromUiThread([&]()->QVariant {
|
||||
return _qmlWindow->property(URL_PROPERTY);
|
||||
});
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
void QmlWebWindowClass::setURL(const QString& urlString) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "setURL", Qt::QueuedConnection, Q_ARG(QString, urlString));
|
||||
}
|
||||
_qmlWindow->setProperty(URL_PROPERTY, urlString);
|
||||
}
|
||||
DependencyManager::get<OffscreenUi>()->executeOnUiThread([=] {
|
||||
_qmlWindow->setProperty(URL_PROPERTY, urlString);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue