mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into NUEtweaks
This commit is contained in:
commit
e478b72e67
9 changed files with 434 additions and 44 deletions
|
@ -210,9 +210,7 @@ const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensi
|
|||
|
||||
class DeadlockWatchdogThread : public QThread {
|
||||
public:
|
||||
static const unsigned long HEARTBEAT_CHECK_INTERVAL_SECS = 1;
|
||||
static const unsigned long HEARTBEAT_UPDATE_INTERVAL_SECS = 1;
|
||||
static const unsigned long HEARTBEAT_REPORT_INTERVAL_USECS = 5 * USECS_PER_SECOND;
|
||||
static const unsigned long MAX_HEARTBEAT_AGE_USECS = 30 * USECS_PER_SECOND;
|
||||
static const int WARNING_ELAPSED_HEARTBEAT = 500 * USECS_PER_MSEC; // warn if elapsed heartbeat average is large
|
||||
static const int HEARTBEAT_SAMPLES = 100000; // ~5 seconds worth of samples
|
||||
|
@ -239,8 +237,6 @@ public:
|
|||
*crashTrigger = 0xDEAD10CC;
|
||||
}
|
||||
|
||||
static void setSuppressStatus(bool suppress) { _suppressStatus = suppress; }
|
||||
|
||||
void run() override {
|
||||
while (!_quit) {
|
||||
QThread::sleep(HEARTBEAT_UPDATE_INTERVAL_SECS);
|
||||
|
@ -248,7 +244,6 @@ public:
|
|||
uint64_t lastHeartbeat = _heartbeat; // sample atomic _heartbeat, because we could context switch away and have it updated on us
|
||||
uint64_t now = usecTimestampNow();
|
||||
auto lastHeartbeatAge = (now > lastHeartbeat) ? now - lastHeartbeat : 0;
|
||||
auto sinceLastReport = (now > _lastReport) ? now - _lastReport : 0;
|
||||
auto elapsedMovingAverage = _movingAverage.getAverage();
|
||||
|
||||
if (elapsedMovingAverage > _maxElapsedAverage) {
|
||||
|
@ -274,21 +269,10 @@ public:
|
|||
if (elapsedMovingAverage > WARNING_ELAPSED_HEARTBEAT) {
|
||||
qDebug() << "DEADLOCK WATCHDOG WARNING:"
|
||||
<< "lastHeartbeatAge:" << lastHeartbeatAge
|
||||
<< "elapsedMovingAverage:" << elapsedMovingAverage << "** OVER EXPECTED VALUE**"
|
||||
<< "elapsedMovingAverage:" << elapsedMovingAverage << "** OVER EXPECTED VALUE **"
|
||||
<< "maxElapsed:" << _maxElapsed
|
||||
<< "maxElapsedAverage:" << _maxElapsedAverage
|
||||
<< "samples:" << _movingAverage.getSamples();
|
||||
_lastReport = now;
|
||||
}
|
||||
|
||||
if (!_suppressStatus && sinceLastReport > HEARTBEAT_REPORT_INTERVAL_USECS) {
|
||||
qDebug() << "DEADLOCK WATCHDOG STATUS:"
|
||||
<< "lastHeartbeatAge:" << lastHeartbeatAge
|
||||
<< "elapsedMovingAverage:" << elapsedMovingAverage
|
||||
<< "maxElapsed:" << _maxElapsed
|
||||
<< "maxElapsedAverage:" << _maxElapsedAverage
|
||||
<< "samples:" << _movingAverage.getSamples();
|
||||
_lastReport = now;
|
||||
}
|
||||
|
||||
if (lastHeartbeatAge > MAX_HEARTBEAT_AGE_USECS) {
|
||||
|
@ -310,9 +294,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
static std::atomic<bool> _suppressStatus;
|
||||
static std::atomic<uint64_t> _heartbeat;
|
||||
static std::atomic<uint64_t> _lastReport;
|
||||
static std::atomic<uint64_t> _maxElapsed;
|
||||
static std::atomic<int> _maxElapsedAverage;
|
||||
static ThreadSafeMovingAverage<int, HEARTBEAT_SAMPLES> _movingAverage;
|
||||
|
@ -320,17 +302,11 @@ public:
|
|||
bool _quit { false };
|
||||
};
|
||||
|
||||
std::atomic<bool> DeadlockWatchdogThread::_suppressStatus;
|
||||
std::atomic<uint64_t> DeadlockWatchdogThread::_heartbeat;
|
||||
std::atomic<uint64_t> DeadlockWatchdogThread::_lastReport;
|
||||
std::atomic<uint64_t> DeadlockWatchdogThread::_maxElapsed;
|
||||
std::atomic<int> DeadlockWatchdogThread::_maxElapsedAverage;
|
||||
ThreadSafeMovingAverage<int, DeadlockWatchdogThread::HEARTBEAT_SAMPLES> DeadlockWatchdogThread::_movingAverage;
|
||||
|
||||
void Application::toggleSuppressDeadlockWatchdogStatus(bool checked) {
|
||||
DeadlockWatchdogThread::setSuppressStatus(checked);
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
class MyNativeEventFilter : public QAbstractNativeEventFilter {
|
||||
public:
|
||||
|
|
|
@ -255,7 +255,6 @@ public slots:
|
|||
|
||||
void resetSensors(bool andReload = false);
|
||||
void setActiveFaceTracker() const;
|
||||
void toggleSuppressDeadlockWatchdogStatus(bool checked);
|
||||
|
||||
#ifdef HAVE_IVIEWHMD
|
||||
void setActiveEyeTracker();
|
||||
|
|
|
@ -568,8 +568,6 @@ Menu::Menu() {
|
|||
addCheckableActionToQMenuAndActionHash(timingMenu, MenuOption::PipelineWarnings);
|
||||
addCheckableActionToQMenuAndActionHash(timingMenu, MenuOption::LogExtraTimings);
|
||||
addCheckableActionToQMenuAndActionHash(timingMenu, MenuOption::SuppressShortTimings);
|
||||
addCheckableActionToQMenuAndActionHash(timingMenu, MenuOption::SupressDeadlockWatchdogStatus, 0, false,
|
||||
qApp, SLOT(toggleSuppressDeadlockWatchdogStatus(bool)));
|
||||
|
||||
|
||||
// Developer > Audio >>>
|
||||
|
|
|
@ -182,7 +182,6 @@ namespace MenuOption {
|
|||
const QString Stats = "Stats";
|
||||
const QString StopAllScripts = "Stop All Scripts";
|
||||
const QString SuppressShortTimings = "Suppress Timings Less than 10ms";
|
||||
const QString SupressDeadlockWatchdogStatus = "Supress Deadlock Watchdog Status";
|
||||
const QString ThirdPerson = "Third Person";
|
||||
const QString ThreePointCalibration = "3 Point Calibration";
|
||||
const QString ThrottleFPSIfNotFocus = "Throttle FPS If Not Focus"; // FIXME - this value duplicated in Basic2DWindowOpenGLDisplayPlugin.cpp
|
||||
|
|
|
@ -31,10 +31,12 @@ UpdateDialog::UpdateDialog(QQuickItem* parent) :
|
|||
|
||||
_releaseNotes = "";
|
||||
for (int i = latestVersion; i > currentVersion; i--) {
|
||||
QString releaseNotes = applicationUpdater.data()->getBuildData()[i]["releaseNotes"];
|
||||
releaseNotes.remove("<br />");
|
||||
releaseNotes.remove(QRegExp("^\n+"));
|
||||
_releaseNotes += "\n" + QString().sprintf("%d", i) + "\n" + releaseNotes + "\n";
|
||||
if (applicationUpdater.data()->getBuildData().contains(i)) {
|
||||
QString releaseNotes = applicationUpdater.data()->getBuildData()[i]["releaseNotes"];
|
||||
releaseNotes.remove("<br />");
|
||||
releaseNotes.remove(QRegExp("^\n+"));
|
||||
_releaseNotes += "\n" + QString().sprintf("%d", i) + "\n" + releaseNotes + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -995,7 +995,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
|||
}
|
||||
QList<QUrl> urls;
|
||||
bool knowsSensitivity = false;
|
||||
Qt::CaseSensitivity sensitivity;
|
||||
Qt::CaseSensitivity sensitivity { Qt::CaseSensitive };
|
||||
auto getSensitivity = [&]() {
|
||||
if (!knowsSensitivity) {
|
||||
QString path = currentSandboxURL.path();
|
||||
|
@ -1012,6 +1012,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
|||
const auto strippingFlags = QUrl::RemoveFilename | QUrl::RemoveQuery | QUrl::RemoveFragment;
|
||||
for (QString file : includeFiles) {
|
||||
QUrl thisURL;
|
||||
bool isStandardLibrary = false;
|
||||
if (file.startsWith("/~/")) {
|
||||
thisURL = expandScriptUrl(QUrl::fromLocalFile(expandScriptPath(file)));
|
||||
QUrl defaultScriptsLoc = defaultScriptsLocation();
|
||||
|
@ -1019,21 +1020,17 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
|||
qDebug() << "ScriptEngine::include -- skipping" << file << "-- outside of standard libraries";
|
||||
continue;
|
||||
}
|
||||
isStandardLibrary = true;
|
||||
} else {
|
||||
thisURL = resolvePath(file);
|
||||
}
|
||||
|
||||
if (!_includedURLs.contains(thisURL)) {
|
||||
if (!currentSandboxURL.isEmpty() && (thisURL.scheme() == "file") &&
|
||||
(
|
||||
(currentSandboxURL.scheme() != "file") ||
|
||||
(
|
||||
!thisURL.toString(strippingFlags).startsWith(defaultScriptsLocation().toString(), getSensitivity()) &&
|
||||
!thisURL.toString(strippingFlags).startsWith(currentSandboxURL.toString(strippingFlags), getSensitivity())
|
||||
)
|
||||
)
|
||||
) {
|
||||
qCWarning(scriptengine) << "Script.include() ignoring file path" << thisURL << "outside of original entity script" << currentSandboxURL;
|
||||
if (!isStandardLibrary && !currentSandboxURL.isEmpty() && (thisURL.scheme() == "file") &&
|
||||
(currentSandboxURL.scheme() != "file" ||
|
||||
!thisURL.toString(strippingFlags).startsWith(currentSandboxURL.toString(strippingFlags), getSensitivity()))) {
|
||||
qCWarning(scriptengine) << "Script.include() ignoring file path"
|
||||
<< thisURL << "outside of original entity script" << currentSandboxURL;
|
||||
} else {
|
||||
// We could also check here for CORS, but we don't yet.
|
||||
// It turns out that QUrl.resolve will not change hosts and copy authority, so we don't need to check that here.
|
||||
|
|
181
scripts/tutorials/NBody/gravity.js
Normal file
181
scripts/tutorials/NBody/gravity.js
Normal file
|
@ -0,0 +1,181 @@
|
|||
// gravity.js
|
||||
//
|
||||
// Created by Philip Rosedale on March 29, 2016
|
||||
// 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
|
||||
//
|
||||
// This entity script causes the object to move with gravitational force and be attracted to other spheres nearby.
|
||||
// The force is scaled by GRAVITY_STRENGTH, and only entities of type "Sphere" within GRAVITY_RANGE will affect it.
|
||||
// The person who has most recently grabbed this object will simulate it.
|
||||
//
|
||||
|
||||
function Timer() {
|
||||
var time;
|
||||
var count = 0;
|
||||
var totalTime = 0;
|
||||
this.reset = function() {
|
||||
count = 0;
|
||||
totalTime = 0;
|
||||
}
|
||||
this.start = function() {
|
||||
time = new Date().getTime();
|
||||
}
|
||||
this.record = function() {
|
||||
var elapsed = new Date().getTime() - time;
|
||||
totalTime += elapsed;
|
||||
count++;
|
||||
return elapsed;
|
||||
}
|
||||
this.count = function() {
|
||||
return count;
|
||||
}
|
||||
this.average = function() {
|
||||
return (count == 0) ? 0 : totalTime / count;
|
||||
}
|
||||
this.elapsed = function() {
|
||||
return new Date().getTime() - time;
|
||||
}
|
||||
}
|
||||
|
||||
(function () {
|
||||
var entityID,
|
||||
wantDebug = true,
|
||||
CHECK_INTERVAL = 10.00,
|
||||
SEARCH_INTERVAL = 1000,
|
||||
GRAVITY_RANGE = 20.0,
|
||||
GRAVITY_STRENGTH = 1.0,
|
||||
MIN_VELOCITY = 0.01,
|
||||
timeoutID = null,
|
||||
timeSinceLastSearch = 0,
|
||||
timer = new Timer(),
|
||||
simulate = false,
|
||||
spheres = [];
|
||||
|
||||
var printDebug = function(message) {
|
||||
if (wantDebug) {
|
||||
print(message);
|
||||
}
|
||||
}
|
||||
|
||||
var greatestDimension = function(dimensions) {
|
||||
return Math.max(Math.max(dimensions.x, dimensions.y), dimensions.z);
|
||||
}
|
||||
|
||||
var mass2 = function(dimensions) {
|
||||
return dimensions.x * dimensions.y * dimensions.z;
|
||||
}
|
||||
|
||||
var findSpheres = function(position) {
|
||||
var entities = Entities.findEntities(position, GRAVITY_RANGE);
|
||||
spheres = [];
|
||||
for (var i = 0; i < entities.length; i++) {
|
||||
if (entityID == spheres[i]) {
|
||||
// this entity doesn't experience its own gravity.
|
||||
continue;
|
||||
}
|
||||
var props = Entities.getEntityProperties(entities[i]);
|
||||
if (props && (props.shapeType == "sphere" || props.type == "Sphere")) {
|
||||
spheres.push(entities[i]);
|
||||
}
|
||||
}
|
||||
// print("FOUND " + spheres.length + " SPHERES");
|
||||
}
|
||||
|
||||
var applyGravity = function() {
|
||||
if (!simulate) {
|
||||
return;
|
||||
}
|
||||
|
||||
var properties = Entities.getEntityProperties(entityID);
|
||||
if (!properties || !properties.position) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update the list of nearby spheres
|
||||
var deltaTime = timer.elapsed() / 1000.0;
|
||||
if (deltaTime == 0.0) {
|
||||
return;
|
||||
}
|
||||
timeSinceLastSearch += CHECK_INTERVAL;
|
||||
if (timeSinceLastSearch >= SEARCH_INTERVAL) {
|
||||
findSpheres(properties.position);
|
||||
timeSinceLastSearch = 0;
|
||||
}
|
||||
|
||||
var deltaVelocity = { x: 0, y: 0, z: 0 };
|
||||
var otherCount = 0;
|
||||
var mass = mass2(properties.dimensions);
|
||||
|
||||
for (var i = 0; i < spheres.length; i++) {
|
||||
otherProperties = Entities.getEntityProperties(spheres[i]);
|
||||
if (!otherProperties || !otherProperties.position) {
|
||||
continue; // sphere was deleted
|
||||
}
|
||||
otherCount++;
|
||||
var radius = Vec3.distance(properties.position, otherProperties.position);
|
||||
var otherMass = mass2(otherProperties.dimensions);
|
||||
var r = (greatestDimension(properties.dimensions) + greatestDimension(otherProperties.dimensions)) / 2;
|
||||
if (radius > r) {
|
||||
var n0 = Vec3.normalize(Vec3.subtract(otherProperties.position, properties.position));
|
||||
var n1 = Vec3.multiply(deltaTime * GRAVITY_STRENGTH * otherMass / (radius * radius), n0);
|
||||
deltaVelocity = Vec3.sum(deltaVelocity, n1);
|
||||
}
|
||||
}
|
||||
Entities.editEntity(entityID, { velocity: Vec3.sum(properties.velocity, deltaVelocity) });
|
||||
if (Vec3.length(properties.velocity) < MIN_VELOCITY) {
|
||||
print("Gravity simulation stopped due to velocity");
|
||||
simulate = false;
|
||||
} else {
|
||||
timer.start();
|
||||
timeoutID = Script.setTimeout(applyGravity, CHECK_INTERVAL);
|
||||
}
|
||||
}
|
||||
this.applyGravity = applyGravity;
|
||||
|
||||
var releaseGrab = function() {
|
||||
printDebug("Gravity simulation started.");
|
||||
var properties = Entities.getEntityProperties(entityID);
|
||||
findSpheres(properties.position);
|
||||
timer.start();
|
||||
timeoutID = Script.setTimeout(applyGravity, CHECK_INTERVAL);
|
||||
simulate = true;
|
||||
}
|
||||
this.releaseGrab = releaseGrab;
|
||||
|
||||
var preload = function (givenEntityID) {
|
||||
printDebug("load gravity...");
|
||||
entityID = givenEntityID;
|
||||
};
|
||||
this.preload = preload;
|
||||
|
||||
var unload = function () {
|
||||
printDebug("Unload gravity...");
|
||||
if (timeoutID !== undefined) {
|
||||
Script.clearTimeout(timeoutID);
|
||||
}
|
||||
if (simulate) {
|
||||
Entities.editEntity(entityID, { velocity: { x: 0, y: 0, z: 0 } });
|
||||
}
|
||||
};
|
||||
this.unload = unload;
|
||||
|
||||
var handleMessages = function(channel, message, sender) {
|
||||
if (channel === 'Hifi-Object-Manipulation') {
|
||||
try {
|
||||
var parsedMessage = JSON.parse(message);
|
||||
if (parsedMessage.action === 'grab' && parsedMessage.grabbedEntity == entityID) {
|
||||
print("Gravity simulation stopped due to grab");
|
||||
simulate = false;
|
||||
}
|
||||
} catch (e) {
|
||||
print('error parsing Hifi-Object-Manipulation message: ' + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.handleMessages = handleMessages;
|
||||
|
||||
Messages.messageReceived.connect(this.handleMessages);
|
||||
Messages.subscribe('Hifi-Object-Manipulation');
|
||||
});
|
72
scripts/tutorials/NBody/gravity.svg
Normal file
72
scripts/tutorials/NBody/gravity.svg
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="64"
|
||||
height="64"
|
||||
viewBox="0 0 64.000001 64.000001"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.91 r13725"
|
||||
sodipodi:docname="gravity.svg">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="1.4"
|
||||
inkscape:cx="192.07838"
|
||||
inkscape:cy="33.619203"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:window-width="2782"
|
||||
inkscape:window-height="1764"
|
||||
inkscape:window-x="98"
|
||||
inkscape:window-y="36"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-988.36216)">
|
||||
<ellipse
|
||||
style="fill:#a09898;fill-opacity:1;stroke:#000000;stroke-opacity:1;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
id="path4690"
|
||||
cx="12.142858"
|
||||
cy="1039.1478"
|
||||
rx="8.5714283"
|
||||
ry="8.2142859" />
|
||||
<ellipse
|
||||
style="fill:#3131d9;fill-opacity:1;stroke:#000000;stroke-width:3;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
id="path4692"
|
||||
cx="39.285717"
|
||||
cy="1014.1478"
|
||||
rx="21.358366"
|
||||
ry="21.001223" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.1 KiB |
166
scripts/tutorials/NBody/makePlanets.js
Normal file
166
scripts/tutorials/NBody/makePlanets.js
Normal file
|
@ -0,0 +1,166 @@
|
|||
// makePlanets.js
|
||||
//
|
||||
// Created by Philip Rosedale on March 29, 2016
|
||||
// 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
|
||||
//
|
||||
// Make an earth and moon, where you can grab and throw moon into orbit. Entity
|
||||
// script attached to moon gives it gravitation behavior and will also make it attracted to
|
||||
// other spheres placed nearby.
|
||||
//
|
||||
|
||||
var SCALE = 3.0;
|
||||
var EARTH_SIZE = 3.959 / SCALE;
|
||||
var MOON_SIZE = 1.079 / SCALE;
|
||||
|
||||
var BUTTON_SIZE = 32;
|
||||
var PADDING = 3;
|
||||
|
||||
var earth = null;
|
||||
var moon = null;
|
||||
|
||||
var SCRIPT_URL = Script.resolvePath("gravity.js");
|
||||
|
||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||
Script.include(["/~/system/libraries/toolBars.js"]);
|
||||
var toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL, "highfidelity.makePlanets.js");
|
||||
|
||||
var makePlanetsIconURL = Script.resolvePath("gravity.svg");
|
||||
var button = toolBar.addOverlay("image", {
|
||||
width: BUTTON_SIZE,
|
||||
height: BUTTON_SIZE,
|
||||
imageURL: makePlanetsIconURL,
|
||||
color: {
|
||||
red: 255,
|
||||
green: 255,
|
||||
blue: 255
|
||||
},
|
||||
alpha: 1
|
||||
});
|
||||
|
||||
var deleteButton = toolBar.addOverlay("image", {
|
||||
width: BUTTON_SIZE,
|
||||
height: BUTTON_SIZE,
|
||||
imageURL: HIFI_PUBLIC_BUCKET + "images/delete.png",
|
||||
color: {
|
||||
red: 255,
|
||||
green: 255,
|
||||
blue: 255
|
||||
},
|
||||
alpha: 1
|
||||
});
|
||||
|
||||
function inFrontOfMe(distance) {
|
||||
return Vec3.sum(Camera.getPosition(), Vec3.multiply(distance, Quat.getFront(Camera.getOrientation())));
|
||||
}
|
||||
|
||||
function onButtonClick() {
|
||||
earth = Entities.addEntity({
|
||||
type: "Model",
|
||||
name: "Earth",
|
||||
modelURL: "https://s3-us-west-1.amazonaws.com/hifi-content/seth/production/NBody/earth.fbx",
|
||||
position: inFrontOfMe(2 * EARTH_SIZE),
|
||||
dimensions: { x: EARTH_SIZE, y: EARTH_SIZE, z: EARTH_SIZE },
|
||||
shapeType: "sphere",
|
||||
lifetime: 86400, // 1 day
|
||||
angularDamping: 0,
|
||||
angularVelocity: { x: 0, y: 0.1, z: 0 },
|
||||
});
|
||||
moon = Entities.addEntity({
|
||||
type: "Model",
|
||||
name: "Moon",
|
||||
modelURL: "https://s3-us-west-1.amazonaws.com/hifi-content/seth/production/NBody/moon.fbx",
|
||||
position: inFrontOfMe(EARTH_SIZE - MOON_SIZE),
|
||||
dimensions: { x: MOON_SIZE, y: MOON_SIZE, z: MOON_SIZE },
|
||||
dynamic: true,
|
||||
damping: 0, // 0.01,
|
||||
angularDamping: 0, // 0.01,
|
||||
script: SCRIPT_URL,
|
||||
shapeType: "sphere"
|
||||
});
|
||||
Entities.addEntity({
|
||||
"accelerationSpread": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"alpha": 1,
|
||||
"alphaFinish": 0,
|
||||
"alphaStart": 1,
|
||||
"azimuthFinish": 0,
|
||||
"azimuthStart": 0,
|
||||
"color": {
|
||||
"blue": 255,
|
||||
"green": 255,
|
||||
"red": 255
|
||||
},
|
||||
"colorFinish": {
|
||||
"blue": 255,
|
||||
"green": 255,
|
||||
"red": 255
|
||||
},
|
||||
"colorStart": {
|
||||
"blue": 255,
|
||||
"green": 255,
|
||||
"red": 255
|
||||
},
|
||||
"dimensions": {
|
||||
"x": 0.10890001058578491,
|
||||
"y": 0.10890001058578491,
|
||||
"z": 0.10890001058578491
|
||||
},
|
||||
"emitAcceleration": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"emitOrientation": {
|
||||
"w": 0.99999994039535522,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"emitRate": 300,
|
||||
"emitSpeed": 0,
|
||||
"emitterShouldTrail": 1,
|
||||
"maxParticles": 10000,
|
||||
"name": "moon trail",
|
||||
"parentID": moon,
|
||||
"particleRadius": 0.005,
|
||||
"radiusFinish": 0.005,
|
||||
"radiusSpread": 0.005,
|
||||
"radiusStart": 0.005,
|
||||
"speedSpread": 0,
|
||||
"lifespan": 20,
|
||||
"textures": "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
|
||||
"type": "ParticleEffect",
|
||||
"userData": "{\"grabbableKey\":{\"grabbable\":false}}"
|
||||
});
|
||||
}
|
||||
|
||||
function onDeleteButton() {
|
||||
Entities.deleteEntity(earth);
|
||||
Entities.deleteEntity(moon);
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
var clickedText = false;
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({
|
||||
x: event.x,
|
||||
y: event.y
|
||||
});
|
||||
if (clickedOverlay == button) {
|
||||
onButtonClick();
|
||||
} else if (clickedOverlay == deleteButton) {
|
||||
onDeleteButton();
|
||||
}
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
toolBar.cleanup();
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
Loading…
Reference in a new issue