mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 07:53:52 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into tot
This commit is contained in:
commit
8617c319d4
119 changed files with 3466 additions and 2268 deletions
.gitignore
examples
ControlACs.jsRecorder.jsbutterflies.jscollidingEntities.jsdeveloperMenuItems.jseditModels.jseditVoxels.js
entityScripts
fallingSand.jsgrowTrees.jsheadMove.jshtml
libraries
ExportMenu.jsToolTip.jsentityCameraTool.jsentityPropertyDialogBox.jsentitySelectionTool.jsgridTool.jsprogressDialog.jstoolBars.js
lobby.jsnewEditEntities.jsnotifications.jsorbitingSound.jsoverlaysExample.jstestModelOverlaySubMeshes.jstextInputOverlayExample.jsvirtualKeyboard.jsinterface
CMakeLists.txt
src
Application.cppApplication.hCamera.cppMenu.hMetavoxelSystem.cpp
devices
entities
EntityTreeRenderer.cppEntityTreeRenderer.hRenderableLightEntityItem.cppRenderableLightEntityItem.hRenderableModelEntityItem.cppRenderableModelEntityItem.h
renderer
scripting
ui
libraries
audio/src
entities/src
EntityCollisionSystem.cppEntityCollisionSystem.hEntityItem.cppEntityItem.hEntityScriptingInterface.cppEntityScriptingInterface.hEntitySimulation.cppEntitySimulation.hEntityTree.cppEntityTree.hEntityTreeElement.cppEntityTreeElement.hLightEntityItem.cppLightEntityItem.hModelEntityItem.cppModelEntityItem.hMovingEntitiesOperator.cppMovingEntitiesOperator.hSimpleEntitySimulation.cppSimpleEntitySimulation.hSphereEntityItem.cppSphereEntityItem.hTextEntityItem.cppTextEntityItem.h
fbx/src
gpu
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -32,5 +32,9 @@ DerivedData
|
|||
interface/external/*/*
|
||||
!interface/external/*/readme.txt
|
||||
|
||||
# ignore interface optional resources
|
||||
interface/resources/visage/*
|
||||
!interface/resources/visage/tracker.cfg
|
||||
|
||||
# Ignore interfaceCache for Linux users
|
||||
interface/interfaceCache/
|
||||
|
|
|
@ -117,6 +117,7 @@ function setupToolBars() {
|
|||
leftMargin: TEXT_MARGIN,
|
||||
topMargin: TEXT_MARGIN,
|
||||
alpha: ALPHA_OFF,
|
||||
backgroundAlpha: ALPHA_OFF,
|
||||
visible: true
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ Script.include("libraries/toolBars.js");
|
|||
var recordingFile = "recording.rec";
|
||||
|
||||
function setPlayerOptions() {
|
||||
MyAvatar.setPlayFromCurrentLocation(true);
|
||||
MyAvatar.setPlayerUseDisplayName(false);
|
||||
MyAvatar.setPlayerUseAttachments(false);
|
||||
MyAvatar.setPlayerUseHeadModel(false);
|
||||
MyAvatar.setPlayerUseSkeletonModel(false);
|
||||
MyAvatar.setPlayFromCurrentLocation(true);
|
||||
MyAvatar.setPlayerUseDisplayName(false);
|
||||
MyAvatar.setPlayerUseAttachments(false);
|
||||
MyAvatar.setPlayerUseHeadModel(false);
|
||||
MyAvatar.setPlayerUseSkeletonModel(false);
|
||||
}
|
||||
|
||||
var windowDimensions = Controller.getViewportDimensions();
|
||||
|
@ -47,115 +47,118 @@ setupTimer();
|
|||
var watchStop = false;
|
||||
|
||||
function setupToolBar() {
|
||||
if (toolBar != null) {
|
||||
print("Multiple calls to Recorder.js:setupToolBar()");
|
||||
return;
|
||||
}
|
||||
if (toolBar != null) {
|
||||
print("Multiple calls to Recorder.js:setupToolBar()");
|
||||
return;
|
||||
}
|
||||
Tool.IMAGE_HEIGHT /= 2;
|
||||
Tool.IMAGE_WIDTH /= 2;
|
||||
|
||||
toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL);
|
||||
toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL);
|
||||
|
||||
toolBar.setBack(COLOR_TOOL_BAR, ALPHA_OFF);
|
||||
|
||||
recordIcon = toolBar.addTool({
|
||||
imageURL: TOOL_ICON_URL + "recording-record.svg",
|
||||
subImage: { x: 0, y: 0, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
|
||||
x: 0, y: 0,
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: MyAvatar.isPlaying() ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, true, !MyAvatar.isRecording());
|
||||
imageURL: TOOL_ICON_URL + "recording-record.svg",
|
||||
subImage: { x: 0, y: 0, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
|
||||
x: 0, y: 0,
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: MyAvatar.isPlaying() ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, true, !MyAvatar.isRecording());
|
||||
|
||||
var playLoopWidthFactor = 1.65;
|
||||
playIcon = toolBar.addTool({
|
||||
imageURL: TOOL_ICON_URL + "play-pause.svg",
|
||||
width: playLoopWidthFactor * Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
imageURL: TOOL_ICON_URL + "play-pause.svg",
|
||||
width: playLoopWidthFactor * Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
|
||||
playLoopIcon = toolBar.addTool({
|
||||
imageURL: TOOL_ICON_URL + "play-and-loop.svg",
|
||||
subImage: { x: 0, y: 0, width: playLoopWidthFactor * Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
|
||||
width: playLoopWidthFactor * Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
imageURL: TOOL_ICON_URL + "play-and-loop.svg",
|
||||
subImage: { x: 0, y: 0, width: playLoopWidthFactor * Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
|
||||
width: playLoopWidthFactor * Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
|
||||
timerOffset = toolBar.width;
|
||||
spacing = toolBar.addSpacing(0);
|
||||
|
||||
saveIcon = toolBar.addTool({
|
||||
imageURL: TOOL_ICON_URL + "recording-save.svg",
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.isPlaying() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
imageURL: TOOL_ICON_URL + "recording-save.svg",
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.isPlaying() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
|
||||
loadIcon = toolBar.addTool({
|
||||
imageURL: TOOL_ICON_URL + "recording-upload.svg",
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.isPlaying()) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
imageURL: TOOL_ICON_URL + "recording-upload.svg",
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.isPlaying()) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
}
|
||||
|
||||
function setupTimer() {
|
||||
timer = Overlays.addOverlay("text", {
|
||||
font: { size: 15 },
|
||||
text: (0.00).toFixed(3),
|
||||
backgroundColor: COLOR_OFF,
|
||||
x: 0, y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
alpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
timer = Overlays.addOverlay("text", {
|
||||
font: { size: 15 },
|
||||
text: (0.00).toFixed(3),
|
||||
backgroundColor: COLOR_OFF,
|
||||
x: 0, y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
|
||||
slider = { x: 0, y: 0,
|
||||
w: 200, h: 20,
|
||||
pos: 0.0, // 0.0 <= pos <= 1.0
|
||||
w: 200, h: 20,
|
||||
pos: 0.0, // 0.0 <= pos <= 1.0
|
||||
};
|
||||
slider.background = Overlays.addOverlay("text", {
|
||||
text: "",
|
||||
backgroundColor: { red: 128, green: 128, blue: 128 },
|
||||
x: slider.x, y: slider.y,
|
||||
width: slider.w,
|
||||
height: slider.h,
|
||||
alpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
text: "",
|
||||
backgroundColor: { red: 128, green: 128, blue: 128 },
|
||||
x: slider.x, y: slider.y,
|
||||
width: slider.w,
|
||||
height: slider.h,
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
slider.foreground = Overlays.addOverlay("text", {
|
||||
text: "",
|
||||
backgroundColor: { red: 200, green: 200, blue: 200 },
|
||||
x: slider.x, y: slider.y,
|
||||
width: slider.pos * slider.w,
|
||||
height: slider.h,
|
||||
alpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
text: "",
|
||||
backgroundColor: { red: 200, green: 200, blue: 200 },
|
||||
x: slider.x, y: slider.y,
|
||||
width: slider.pos * slider.w,
|
||||
height: slider.h,
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function updateTimer() {
|
||||
var text = "";
|
||||
if (MyAvatar.isRecording()) {
|
||||
text = formatTime(MyAvatar.recorderElapsed());
|
||||
var text = "";
|
||||
if (MyAvatar.isRecording()) {
|
||||
text = formatTime(MyAvatar.recorderElapsed());
|
||||
|
||||
} else {
|
||||
text = formatTime(MyAvatar.playerElapsed()) + " / " +
|
||||
formatTime(MyAvatar.playerLength());
|
||||
}
|
||||
} else {
|
||||
text = formatTime(MyAvatar.playerElapsed()) + " / " +
|
||||
formatTime(MyAvatar.playerLength());
|
||||
}
|
||||
|
||||
Overlays.editOverlay(timer, {
|
||||
text: text
|
||||
})
|
||||
Overlays.editOverlay(timer, {
|
||||
text: text
|
||||
})
|
||||
toolBar.changeSpacing(text.length * 8 + ((MyAvatar.isRecording()) ? 15 : 0), spacing);
|
||||
|
||||
if (MyAvatar.isRecording()) {
|
||||
|
@ -165,57 +168,56 @@ function updateTimer() {
|
|||
}
|
||||
|
||||
Overlays.editOverlay(slider.foreground, {
|
||||
width: slider.pos * slider.w
|
||||
});
|
||||
width: slider.pos * slider.w
|
||||
});
|
||||
}
|
||||
|
||||
function formatTime(time) {
|
||||
var MIN_PER_HOUR = 60;
|
||||
var SEC_PER_MIN = 60;
|
||||
var MSEC_PER_SEC = 1000;
|
||||
var MIN_PER_HOUR = 60;
|
||||
var SEC_PER_MIN = 60;
|
||||
var MSEC_PER_SEC = 1000;
|
||||
|
||||
var hours = Math.floor(time / (MSEC_PER_SEC * SEC_PER_MIN * MIN_PER_HOUR));
|
||||
time -= hours * (MSEC_PER_SEC * SEC_PER_MIN * MIN_PER_HOUR);
|
||||
var hours = Math.floor(time / (MSEC_PER_SEC * SEC_PER_MIN * MIN_PER_HOUR));
|
||||
time -= hours * (MSEC_PER_SEC * SEC_PER_MIN * MIN_PER_HOUR);
|
||||
|
||||
var minutes = Math.floor(time / (MSEC_PER_SEC * SEC_PER_MIN));
|
||||
time -= minutes * (MSEC_PER_SEC * SEC_PER_MIN);
|
||||
var minutes = Math.floor(time / (MSEC_PER_SEC * SEC_PER_MIN));
|
||||
time -= minutes * (MSEC_PER_SEC * SEC_PER_MIN);
|
||||
|
||||
var seconds = Math.floor(time / MSEC_PER_SEC);
|
||||
seconds = time / MSEC_PER_SEC;
|
||||
var seconds = Math.floor(time / MSEC_PER_SEC);
|
||||
seconds = time / MSEC_PER_SEC;
|
||||
|
||||
var text = "";
|
||||
text += (hours > 0) ? hours + ":" :
|
||||
"";
|
||||
text += (minutes > 0) ? ((minutes < 10 && text != "") ? "0" : "") + minutes + ":" :
|
||||
"";
|
||||
text += ((seconds < 10 && text != "") ? "0" : "") + seconds.toFixed(3);
|
||||
return text;
|
||||
var text = "";
|
||||
text += (hours > 0) ? hours + ":" :
|
||||
"";
|
||||
text += (minutes > 0) ? ((minutes < 10 && text != "") ? "0" : "") + minutes + ":" :
|
||||
"";
|
||||
text += ((seconds < 10 && text != "") ? "0" : "") + seconds.toFixed(3);
|
||||
return text;
|
||||
}
|
||||
|
||||
function moveUI() {
|
||||
var relative = { x: 70, y: 40 };
|
||||
toolBar.move(relative.x,
|
||||
windowDimensions.y - relative.y);
|
||||
Overlays.editOverlay(timer, {
|
||||
x: relative.x + timerOffset - ToolBar.SPACING,
|
||||
y: windowDimensions.y - relative.y - ToolBar.SPACING
|
||||
});
|
||||
var relative = { x: 70, y: 40 };
|
||||
toolBar.move(relative.x, windowDimensions.y - relative.y);
|
||||
Overlays.editOverlay(timer, {
|
||||
x: relative.x + timerOffset - ToolBar.SPACING,
|
||||
y: windowDimensions.y - relative.y - ToolBar.SPACING
|
||||
});
|
||||
|
||||
slider.x = relative.x - ToolBar.SPACING;
|
||||
slider.y = windowDimensions.y - relative.y - slider.h - ToolBar.SPACING;
|
||||
|
||||
Overlays.editOverlay(slider.background, {
|
||||
x: slider.x,
|
||||
y: slider.y,
|
||||
});
|
||||
x: slider.x,
|
||||
y: slider.y,
|
||||
});
|
||||
Overlays.editOverlay(slider.foreground, {
|
||||
x: slider.x,
|
||||
y: slider.y,
|
||||
});
|
||||
x: slider.x,
|
||||
y: slider.y,
|
||||
});
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||
|
||||
if (recordIcon === toolBar.clicked(clickedOverlay, false) && !MyAvatar.isPlaying()) {
|
||||
if (!MyAvatar.isRecording()) {
|
||||
|
@ -267,7 +269,7 @@ function mousePressEvent(event) {
|
|||
if (!MyAvatar.isRecording() && !MyAvatar.isPlaying() && MyAvatar.playerLength() != 0) {
|
||||
recordingFile = Window.save("Save recording to file", ".", "Recordings (*.hfr)");
|
||||
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
|
||||
MyAvatar.saveRecording(recordingFile);
|
||||
MyAvatar.saveRecording(recordingFile);
|
||||
}
|
||||
}
|
||||
} else if (loadIcon === toolBar.clicked(clickedOverlay)) {
|
||||
|
@ -283,8 +285,8 @@ function mousePressEvent(event) {
|
|||
}
|
||||
}
|
||||
} else if (MyAvatar.playerLength() > 0 &&
|
||||
slider.x < event.x && event.x < slider.x + slider.w &&
|
||||
slider.y < event.y && event.y < slider.y + slider.h) {
|
||||
slider.x < event.x && event.x < slider.x + slider.w &&
|
||||
slider.y < event.y && event.y < slider.y + slider.h) {
|
||||
isSliding = true;
|
||||
slider.pos = (event.x - slider.x) / slider.w;
|
||||
MyAvatar.setPlayerTime(slider.pos * MyAvatar.playerLength());
|
||||
|
@ -308,14 +310,13 @@ function mouseReleaseEvent(event) {
|
|||
}
|
||||
|
||||
function update() {
|
||||
var newDimensions = Controller.getViewportDimensions();
|
||||
if (windowDimensions.x != newDimensions.x ||
|
||||
windowDimensions.y != newDimensions.y) {
|
||||
windowDimensions = newDimensions;
|
||||
moveUI();
|
||||
}
|
||||
var newDimensions = Controller.getViewportDimensions();
|
||||
if (windowDimensions.x != newDimensions.x || windowDimensions.y != newDimensions.y) {
|
||||
windowDimensions = newDimensions;
|
||||
moveUI();
|
||||
}
|
||||
|
||||
updateTimer();
|
||||
updateTimer();
|
||||
|
||||
if (watchStop && !MyAvatar.isPlaying()) {
|
||||
watchStop = false;
|
||||
|
@ -326,12 +327,12 @@ function update() {
|
|||
}
|
||||
|
||||
function scriptEnding() {
|
||||
if (MyAvatar.isRecording()) {
|
||||
MyAvatar.stopRecording();
|
||||
}
|
||||
if (MyAvatar.isPlaying()) {
|
||||
MyAvatar.stopPlaying();
|
||||
}
|
||||
if (MyAvatar.isRecording()) {
|
||||
MyAvatar.stopRecording();
|
||||
}
|
||||
if (MyAvatar.isPlaying()) {
|
||||
MyAvatar.stopPlaying();
|
||||
}
|
||||
toolBar.cleanup();
|
||||
Overlays.deleteOverlay(timer);
|
||||
Overlays.deleteOverlay(slider.background);
|
||||
|
|
|
@ -13,18 +13,13 @@
|
|||
//
|
||||
|
||||
|
||||
var numButterflies = 20;
|
||||
var numButterflies = 25;
|
||||
|
||||
|
||||
function getRandomFloat(min, max) {
|
||||
return Math.random() * (max - min) + min;
|
||||
}
|
||||
|
||||
// Multiply vector by scalar
|
||||
function vScalarMult(v, s) {
|
||||
var rval = { x: v.x * s, y: v.y * s, z: v.z * s };
|
||||
return rval;
|
||||
}
|
||||
|
||||
// Create a random vector with individual lengths between a,b
|
||||
function randVector(a, b) {
|
||||
|
@ -32,50 +27,36 @@ function randVector(a, b) {
|
|||
return rval;
|
||||
}
|
||||
|
||||
// Returns a vector which is fraction of the way between a and b
|
||||
function vInterpolate(a, b, fraction) {
|
||||
var rval = { x: a.x + (b.x - a.x) * fraction, y: a.y + (b.y - a.y) * fraction, z: a.z + (b.z - a.z) * fraction };
|
||||
return rval;
|
||||
}
|
||||
|
||||
var startTimeInSeconds = new Date().getTime() / 1000;
|
||||
|
||||
var NATURAL_SIZE_OF_BUTTERFLY = { x: 1.76, y: 0.825, z: 0.20 };
|
||||
var lifeTime = 600; // lifetime of the butterflies in seconds
|
||||
var range = 3.0; // Over what distance in meters do you want the flock to fly around
|
||||
var NATURAL_SIZE_OF_BUTTERFLY = { x: 1.0, y: 0.4, z: 0.2 };
|
||||
|
||||
var lifeTime = 3600; // One hour lifespan
|
||||
var range = 7.0; // Over what distance in meters do you want the flock to fly around
|
||||
var frame = 0;
|
||||
|
||||
var CHANCE_OF_MOVING = 0.9;
|
||||
var BUTTERFLY_GRAVITY = 0;
|
||||
var BUTTERFLY_FLAP_SPEED = 0.5;
|
||||
var BUTTERFLY_VELOCITY = 0.55;
|
||||
var DISTANCE_IN_FRONT_OF_ME = 1.5;
|
||||
var DISTANCE_ABOVE_ME = 1.5;
|
||||
var flockPosition = Vec3.sum(MyAvatar.position,Vec3.sum(
|
||||
var FIXED_LOCATION = false;
|
||||
|
||||
if (!FIXED_LOCATION) {
|
||||
var flockPosition = Vec3.sum(MyAvatar.position,Vec3.sum(
|
||||
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_ABOVE_ME),
|
||||
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_IN_FRONT_OF_ME)));
|
||||
|
||||
} else {
|
||||
var flockPosition = { x: 4999.6, y: 4986.5, z: 5003.5 };
|
||||
}
|
||||
|
||||
// set these pitch, yaw, roll to the needed values to orient the model as you want it
|
||||
var pitchInDegrees = 270.0;
|
||||
var yawInDegrees = 0.0;
|
||||
var rollInDegrees = 0.0;
|
||||
var pitchInRadians = pitchInDegrees / 180.0 * Math.PI;
|
||||
var yawInRadians = yawInDegrees / 180.0 * Math.PI;
|
||||
var rollInRadians = rollInDegrees / 180.0 * Math.PI;
|
||||
|
||||
var rotation = Quat.fromPitchYawRollDegrees(pitchInDegrees, yawInDegrees, rollInDegrees);//experimental
|
||||
|
||||
// This is our butterfly object
|
||||
function defineButterfly(entityID, targetPosition) {
|
||||
this.entityID = entityID;
|
||||
this.previousFlapOffset = 0;
|
||||
this.targetPosition = targetPosition;
|
||||
this.moving = false;
|
||||
}
|
||||
|
||||
// Array of butterflies
|
||||
var butterflies = [];
|
||||
|
||||
function addButterfly() {
|
||||
// Decide the size of butterfly
|
||||
var color = { red: 100, green: 100, blue: 100 };
|
||||
|
@ -88,26 +69,24 @@ function addButterfly() {
|
|||
size = MINSIZE + Math.random() * RANGESIZE;
|
||||
|
||||
var dimensions = Vec3.multiply(NATURAL_SIZE_OF_BUTTERFLY, (size / maxSize));
|
||||
|
||||
flockPosition = Vec3.sum(MyAvatar.position,Vec3.sum(
|
||||
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_ABOVE_ME),
|
||||
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_IN_FRONT_OF_ME)));
|
||||
|
||||
|
||||
var GRAVITY = -0.2;
|
||||
var newFrameRate = 20 + Math.random() * 30;
|
||||
var properties = {
|
||||
type: "Model",
|
||||
lifetime: lifeTime,
|
||||
position: Vec3.sum(randVector(-range, range), flockPosition),
|
||||
velocity: { x: 0, y: 0.0, z: 0 },
|
||||
gravity: { x: 0, y: 1.0, z: 0 },
|
||||
damping: 0.1,
|
||||
rotation: Quat.fromPitchYawRollDegrees(-80 + Math.random() * 20, Math.random() * 360.0, 0.0),
|
||||
velocity: { x: 0, y: 0, z: 0 },
|
||||
gravity: { x: 0, y: GRAVITY, z: 0 },
|
||||
damping: 0.9999,
|
||||
dimensions: dimensions,
|
||||
color: color,
|
||||
rotation: rotation,
|
||||
animationURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/models/content/butterfly/butterfly.fbx",
|
||||
animationIsPlaying: true,
|
||||
animationSettings: "{\"firstFrame\":0,\"fps\":" + newFrameRate + ",\"frameIndex\":0,\"hold\":false,\"lastFrame\":10000,\"loop\":true,\"running\":true,\"startAutomatically\":false}",
|
||||
modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/models/content/butterfly/butterfly.fbx"
|
||||
};
|
||||
butterflies.push(new defineButterfly(Entities.addEntity(properties), properties.position));
|
||||
butterflies.push(Entities.addEntity(properties));
|
||||
}
|
||||
|
||||
// Generate the butterflies
|
||||
|
@ -116,117 +95,37 @@ for (var i = 0; i < numButterflies; i++) {
|
|||
}
|
||||
|
||||
// Main update function
|
||||
function updateButterflies(deltaTime) {
|
||||
// Check to see if we've been running long enough that our butterflies are dead
|
||||
var nowTimeInSeconds = new Date().getTime() / 1000;
|
||||
if ((nowTimeInSeconds - startTimeInSeconds) >= lifeTime) {
|
||||
Script.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
function updateButterflies(deltaTime) {
|
||||
frame++;
|
||||
// Only update every third frame because we don't need to do it too quickly
|
||||
if ((frame % 3) == 0) {
|
||||
flockPosition = Vec3.sum(MyAvatar.position,Vec3.sum(Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_ABOVE_ME),
|
||||
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_IN_FRONT_OF_ME)));
|
||||
|
||||
// Update all the butterflies
|
||||
var CHANCE_OF_IMPULSE = 0.04;
|
||||
for (var i = 0; i < numButterflies; i++) {
|
||||
entityID = Entities.identifyEntity(butterflies[i].entityID);
|
||||
butterflies[i].entityID = entityID;
|
||||
var properties = Entities.getEntityProperties(entityID);
|
||||
|
||||
if (properties.position.y > flockPosition.y + getRandomFloat(0.0,0.3)){ //0.3 //ceiling
|
||||
properties.gravity.y = - 3.0;
|
||||
properties.damping.y = 1.0;
|
||||
properties.velocity.y = 0;
|
||||
properties.velocity.x = properties.velocity.x;
|
||||
properties.velocity.z = properties.velocity.z;
|
||||
if (properties.velocity.x < 0.5){
|
||||
butterflies[i].moving = false;
|
||||
if (Math.random() < CHANCE_OF_IMPULSE) {
|
||||
if (!butterflies[i].isKnownID) {
|
||||
butterflies[i] = Entities.identifyEntity(butterflies[i]);
|
||||
}
|
||||
if (properties.velocity.z < 0.5){
|
||||
butterflies[i].moving = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (properties.velocity.y <= -0.2) {
|
||||
properties.velocity.y = 0.22;
|
||||
properties.velocity.x = properties.velocity.x;
|
||||
properties.velocity.z = properties.velocity.z;
|
||||
}
|
||||
|
||||
if (properties.position.y < flockPosition.y - getRandomFloat(0.0,0.3)) { //-0.3 // floor
|
||||
properties.velocity.y = 0.9;
|
||||
properties.gravity.y = - 4.0;
|
||||
properties.velocity.x = properties.velocity.x;
|
||||
properties.velocity.z = properties.velocity.z;
|
||||
if (properties.velocity.x < 0.5){
|
||||
butterflies[i].moving = false;
|
||||
}
|
||||
if (properties.velocity.z < 0.5){
|
||||
butterflies[i].moving = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Begin movement by getting a target
|
||||
if (butterflies[i].moving == false) {
|
||||
if (Math.random() < CHANCE_OF_MOVING) {
|
||||
var targetPosition = Vec3.sum(randVector(-range, range), flockPosition);
|
||||
if (targetPosition.x < 0) {
|
||||
targetPosition.x = 0;
|
||||
}
|
||||
if (targetPosition.y < 0) {
|
||||
targetPosition.y = 0;
|
||||
}
|
||||
if (targetPosition.z < 0) {
|
||||
targetPosition.z = 0;
|
||||
}
|
||||
if (targetPosition.x > TREE_SCALE) {
|
||||
targetPosition.x = TREE_SCALE;
|
||||
}
|
||||
if (targetPosition.y > TREE_SCALE) {
|
||||
targetPosition.y = TREE_SCALE;
|
||||
}
|
||||
if (targetPosition.z > TREE_SCALE) {
|
||||
targetPosition.z = TREE_SCALE;
|
||||
}
|
||||
butterflies[i].targetPosition = targetPosition;
|
||||
butterflies[i].moving = true;
|
||||
var properties = Entities.getEntityProperties(butterflies[i]);
|
||||
if (Vec3.length(Vec3.subtract(properties.position, flockPosition)) > range) {
|
||||
Entities.editEntity(butterflies[i], { position: flockPosition } );
|
||||
} else if (properties.velocity.y < 0.0) {
|
||||
// If falling, Create a new direction and impulse
|
||||
var HORIZ_SCALE = 0.50;
|
||||
var VERT_SCALE = 0.50;
|
||||
var newHeading = Math.random() * 360.0;
|
||||
var newVelocity = Vec3.multiply(HORIZ_SCALE, Quat.getFront(Quat.fromPitchYawRollDegrees(0.0, newHeading, 0.0)));
|
||||
newVelocity.y = (Math.random() + 0.5) * VERT_SCALE;
|
||||
Entities.editEntity(butterflies[i], { rotation: Quat.fromPitchYawRollDegrees(-80 + Math.random() * 20, newHeading, (Math.random() - 0.5) * 10),
|
||||
velocity: newVelocity } );
|
||||
}
|
||||
}
|
||||
|
||||
// If we are moving, move towards the target
|
||||
if (butterflies[i].moving) {
|
||||
|
||||
var holding = properties.velocity.y;
|
||||
|
||||
var desiredVelocity = Vec3.subtract(butterflies[i].targetPosition, properties.position);
|
||||
desiredVelocity = vScalarMult(Vec3.normalize(desiredVelocity), BUTTERFLY_VELOCITY);
|
||||
|
||||
properties.velocity = vInterpolate(properties.velocity, desiredVelocity, 0.5);
|
||||
properties.velocity.y = holding ;
|
||||
|
||||
|
||||
// If we are near the target, we should get a new target
|
||||
var halfLargestDimension = Vec3.length(properties.dimensions) / 2.0;
|
||||
if (Vec3.length(Vec3.subtract(properties.position, butterflies[i].targetPosition)) < (halfLargestDimension)) {
|
||||
butterflies[i].moving = false;
|
||||
}
|
||||
|
||||
var yawRads = Math.atan2(properties.velocity.z, properties.velocity.x);
|
||||
yawRads = yawRads + Math.PI / 2.0;
|
||||
var newOrientation = Quat.fromPitchYawRollRadians(pitchInRadians, yawRads, rollInRadians);
|
||||
properties.rotation = newOrientation;
|
||||
}
|
||||
|
||||
// Use a cosine wave offset to make it look like its flapping.
|
||||
var offset = Math.cos(nowTimeInSeconds * BUTTERFLY_FLAP_SPEED) * (halfLargestDimension);
|
||||
properties.position.y = properties.position.y + (offset - butterflies[i].previousFlapOffset);
|
||||
// Change position relative to previous offset.
|
||||
butterflies[i].previousFlapOffset = offset;
|
||||
Entities.editEntity(entityID, properties);
|
||||
}
|
||||
// Check to see if we've been running long enough that our butterflies are dead
|
||||
var nowTimeInSeconds = new Date().getTime() / 1000;
|
||||
if ((nowTimeInSeconds - startTimeInSeconds) >= lifeTime) {
|
||||
Script.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -237,6 +136,6 @@ Script.update.connect(updateButterflies);
|
|||
// Delete our little friends if script is stopped
|
||||
Script.scriptEnding.connect(function() {
|
||||
for (var i = 0; i < numButterflies; i++) {
|
||||
Entities.deleteEntity(butterflies[i].entityID);
|
||||
Entities.deleteEntity(butterflies[i]);
|
||||
}
|
||||
});
|
|
@ -22,11 +22,6 @@ var velocity = {
|
|||
y: 0,
|
||||
z: 1 };
|
||||
|
||||
var gravity = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0 };
|
||||
|
||||
var damping = 0.1;
|
||||
|
||||
var color = {
|
||||
|
@ -42,22 +37,17 @@ function draw(deltaTime) {
|
|||
var colorGreen = { red: 0, green: 255, blue: 0 };
|
||||
var startPosition = {
|
||||
x: 2,
|
||||
y: 0,
|
||||
y: 1,
|
||||
z: 2 };
|
||||
var largeRadius = 0.5;
|
||||
var verySlow = {
|
||||
x: 0.01,
|
||||
y: 0,
|
||||
z: 0.01 };
|
||||
|
||||
var properties = {
|
||||
type: "Sphere",
|
||||
collisionsWillMove: true,
|
||||
position: startPosition,
|
||||
dimensions: {x: largeRadius, y: largeRadius, z: largeRadius},
|
||||
registrationPoint: { x: 0.5, y: 0.5, z: 0.5 },
|
||||
color: colorGreen,
|
||||
velocity: verySlow,
|
||||
gravity: gravity,
|
||||
damping: damping,
|
||||
lifetime: 20
|
||||
};
|
||||
|
@ -71,7 +61,7 @@ function draw(deltaTime) {
|
|||
|
||||
var center = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
y: 1,
|
||||
z: 0 };
|
||||
|
||||
var entitySize = 0.1;
|
||||
|
@ -97,9 +87,9 @@ function draw(deltaTime) {
|
|||
collisionsWillMove: true,
|
||||
position: center,
|
||||
dimensions: {x: entitySize, y: entitySize, z: entitySize},
|
||||
registrationPoint: { x: 0.5, y: 0.5, z: 0.5 },
|
||||
color: color,
|
||||
velocity: velocity,
|
||||
gravity: gravity,
|
||||
damping: damping,
|
||||
lifetime: 20
|
||||
};
|
||||
|
|
|
@ -19,14 +19,17 @@ function setupMenus() {
|
|||
if (!Menu.menuExists("Developer > Entities")) {
|
||||
Menu.addMenu("Developer > Entities");
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Bounds", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Triangles", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Bounds", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Children", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Disable Light Entities", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Do Precision Picking", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt to Reduce Material Switches", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt Render Entities as Scene", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Do Precision Picking", isCheckable: true, isChecked: false });
|
||||
Menu.addMenu("Developer > Entities > Culling");
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities > Culling", menuItemName: "Don't Cull Out Of View Mesh Parts", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities > Culling", menuItemName: "Don't Cull Too Small Mesh Parts", isCheckable: true, isChecked: false });
|
||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Disable Light Entities", isCheckable: true, isChecked: false });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -206,6 +206,7 @@ var progressDialog = (function () {
|
|||
height: backgroundHeight,
|
||||
imageURL: backgroundUrl,
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
|
@ -216,6 +217,7 @@ var progressDialog = (function () {
|
|||
textColor: textColor,
|
||||
backgroundColor: textBackground,
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
|
@ -226,6 +228,7 @@ var progressDialog = (function () {
|
|||
textColor: textColor,
|
||||
backgroundColor: textBackground,
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
|
@ -1169,24 +1172,22 @@ var toolBar = (function () {
|
|||
menuItemHeight = Tool.IMAGE_HEIGHT / 2 - 2;
|
||||
|
||||
loadURLMenuItem = Overlays.addOverlay("text", {
|
||||
x: newModelButton.x - menuItemWidth,
|
||||
y: newModelButton.y + menuItemOffset,
|
||||
height: menuItemHeight,
|
||||
backgroundColor: menuBackgroundColor,
|
||||
topMargin: menuItemMargin,
|
||||
text: "Model URL",
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
loadFileMenuItem = Overlays.addOverlay("text", {
|
||||
x: newModelButton.x - menuItemWidth,
|
||||
y: newModelButton.y + menuItemOffset + menuItemHeight,
|
||||
height: menuItemHeight,
|
||||
backgroundColor: menuBackgroundColor,
|
||||
topMargin: menuItemMargin,
|
||||
text: "Model File",
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
|
@ -1493,6 +1494,7 @@ var ExportMenu = function (opts) {
|
|||
width: scaleViewWidth,
|
||||
height: height,
|
||||
alpha: 0.0,
|
||||
backgroundAlpha: 0.0,
|
||||
color: { red: 255, green: 255, blue: 255 },
|
||||
text: "1"
|
||||
});
|
||||
|
@ -2480,6 +2482,7 @@ function Tooltip() {
|
|||
text: "",
|
||||
color: { red: 228, green: 228, blue: 228 },
|
||||
alpha: 0.8,
|
||||
backgroundAlpha: 0.8,
|
||||
visible: false
|
||||
});
|
||||
this.show = function (doShow) {
|
||||
|
@ -2554,7 +2557,7 @@ function mousePressEvent(event) {
|
|||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
Vec3.print("[Mouse] Looking at: ", pickRay.origin);
|
||||
var foundIntersection = Entities.findRayIntersection(pickRay);
|
||||
var foundIntersection = Entities.findRayIntersection(pickRay, true); // we want precision picking here
|
||||
|
||||
if(!foundIntersection.accurate) {
|
||||
return;
|
||||
|
|
|
@ -319,7 +319,7 @@ function ScaleSelector() {
|
|||
width: this.SECOND_PART, height: this.height,
|
||||
topMargin: 13,
|
||||
text: this.scale.toString(),
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.0,
|
||||
visible: editToolsOn
|
||||
});
|
||||
this.powerOverlay = Overlays.addOverlay("text", {
|
||||
|
@ -327,7 +327,7 @@ function ScaleSelector() {
|
|||
width: this.SECOND_PART, height: this.height,
|
||||
leftMargin: 28,
|
||||
text: this.power.toString(),
|
||||
alpha: 0.0,
|
||||
backgroundAlpha: 0.0,
|
||||
visible: false
|
||||
});
|
||||
this.setScale = function(scale) {
|
||||
|
|
20
examples/entityScripts/changeColorOnCollision.js
Normal file
20
examples/entityScripts/changeColorOnCollision.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// changeColorOnCollision.js
|
||||
// examples/entityScripts
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/8/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
(function(){
|
||||
function getRandomInt(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
this.collisionWithEntity = function(myID, otherID, collisionInfo) {
|
||||
Entities.editEntity(myID, { color: { red: getRandomInt(128,255), green: getRandomInt(128,255), blue: getRandomInt(128,255)} });
|
||||
};
|
||||
})
|
|
@ -117,7 +117,7 @@ function ScaleSelector() {
|
|||
width: this.SECOND_PART, height: this.height,
|
||||
topMargin: 13,
|
||||
text: this.scale.toString(),
|
||||
alpha: 0.0,
|
||||
backgroundAlpha: 0.0,
|
||||
visible: editToolsOn,
|
||||
color: activeUIColor
|
||||
});
|
||||
|
@ -126,7 +126,7 @@ function ScaleSelector() {
|
|||
width: this.SECOND_PART, height: this.height,
|
||||
leftMargin: 28,
|
||||
text: this.power.toString(),
|
||||
alpha: 0.0,
|
||||
backgroundAlpha: 0.0,
|
||||
visible: false,
|
||||
color: activeUIColor
|
||||
});
|
||||
|
|
|
@ -116,7 +116,7 @@ function ScaleSelector() {
|
|||
width: this.SECOND_PART, height: this.height,
|
||||
topMargin: 13,
|
||||
text: this.scale.toString(),
|
||||
alpha: 0.0,
|
||||
backgroundAlpha: 0.0,
|
||||
visible: editToolsOn,
|
||||
color: activeUIColor
|
||||
});
|
||||
|
@ -125,7 +125,7 @@ function ScaleSelector() {
|
|||
width: this.SECOND_PART, height: this.height,
|
||||
leftMargin: 28,
|
||||
text: this.power.toString(),
|
||||
alpha: 0.0,
|
||||
backgroundAlpha: 0.0,
|
||||
visible: false,
|
||||
color: activeUIColor
|
||||
});
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var gamepads = {};
|
||||
|
||||
var debug = false;
|
||||
var willMove = false;
|
||||
|
||||
|
@ -19,7 +21,6 @@ var warpPosition = { x: 0, y: 0, z: 0 };
|
|||
|
||||
var hipsToEyes;
|
||||
var restoreCountdownTimer;
|
||||
var headTurningTimer = 0.0;
|
||||
|
||||
// Overlays to show target location
|
||||
|
||||
|
@ -62,13 +63,6 @@ function restoreCameraState() {
|
|||
Camera.mode = oldMode;
|
||||
}
|
||||
|
||||
function activateWarp() {
|
||||
if (warpActive) return;
|
||||
warpActive = true;
|
||||
|
||||
updateWarp();
|
||||
}
|
||||
|
||||
var WATCH_AVATAR_DISTANCE = 2.5;
|
||||
|
||||
var sound = SoundCache.getSound("http://public.highfidelity.io/sounds/Footsteps/FootstepW2Right-12db.wav");
|
||||
|
@ -132,6 +126,22 @@ function updateWarp() {
|
|||
});
|
||||
}
|
||||
|
||||
function activateWarp() {
|
||||
if (warpActive) return;
|
||||
warpActive = true;
|
||||
movingWithHead = true;
|
||||
hipsToEyes = MyAvatar.getEyePosition().y - MyAvatar.position.y;
|
||||
headStartPosition = MyAvatar.getTrackedHeadPosition();
|
||||
headStartDeltaPitch = MyAvatar.getHeadDeltaPitch();
|
||||
headStartFinalPitch = MyAvatar.getHeadFinalPitch();
|
||||
headStartRoll = MyAvatar.getHeadFinalRoll();
|
||||
headStartYaw = MyAvatar.getHeadFinalYaw();
|
||||
deltaYaw = 0.0;
|
||||
warpPosition = MyAvatar.position;
|
||||
warpPosition.y += hipsToEyes;
|
||||
updateWarp();
|
||||
}
|
||||
|
||||
function finishWarp() {
|
||||
if (!warpActive) return;
|
||||
warpActive = false;
|
||||
|
@ -152,6 +162,9 @@ function finishWarp() {
|
|||
cameraPosition = Vec3.subtract(MyAvatar.position, Vec3.multiplyQbyV(Camera.getOrientation(), { x: 0, y: -hipsToEyes, z: -hipsToEyes * WATCH_AVATAR_DISTANCE }));
|
||||
Camera.setPosition(cameraPosition);
|
||||
playSound();
|
||||
if (watchAvatar) {
|
||||
restoreCountdownTimer = RESTORE_TIME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,35 +182,11 @@ function update(deltaTime) {
|
|||
restoreCountDownTimer = 0.0;
|
||||
}
|
||||
}
|
||||
var HEAD_TURN_TIME = 0.10;
|
||||
var HEAD_TURN_DEGREES = 4.0;
|
||||
var HEAD_TURN_START_ANGLE = 45.0;
|
||||
var currentYaw = MyAvatar.getHeadFinalYaw();
|
||||
if (Math.abs(currentYaw) > HEAD_TURN_START_ANGLE) {
|
||||
headTurningTimer += deltaTime;
|
||||
if (headTurningTimer > HEAD_TURN_TIME) {
|
||||
headTurningTimer = 0.0;
|
||||
MyAvatar.orientation = Quat.multiply(Quat.fromPitchYawRollDegrees(0, (currentYaw > 0) ? HEAD_TURN_DEGREES: -HEAD_TURN_DEGREES, 0),
|
||||
MyAvatar.orientation);
|
||||
}
|
||||
} else {
|
||||
headTurningTimer = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
Controller.keyPressEvent.connect(function(event) {
|
||||
if (event.text == "SPACE" && !event.isAutoRepeat && !movingWithHead) {
|
||||
keyDownTime = 0.0;
|
||||
movingWithHead = true;
|
||||
hipsToEyes = MyAvatar.getEyePosition().y - MyAvatar.position.y;
|
||||
headStartPosition = MyAvatar.getTrackedHeadPosition();
|
||||
headStartDeltaPitch = MyAvatar.getHeadDeltaPitch();
|
||||
headStartFinalPitch = MyAvatar.getHeadFinalPitch();
|
||||
headStartRoll = MyAvatar.getHeadFinalRoll();
|
||||
headStartYaw = MyAvatar.getHeadFinalYaw();
|
||||
deltaYaw = 0.0;
|
||||
warpPosition = MyAvatar.position;
|
||||
warpPosition.y += hipsToEyes;
|
||||
activateWarp();
|
||||
}
|
||||
});
|
||||
|
@ -223,11 +212,40 @@ Controller.keyReleaseEvent.connect(function(event) {
|
|||
}
|
||||
timeSinceLastUp = 0.0;
|
||||
finishWarp();
|
||||
if (watchAvatar) {
|
||||
restoreCountdownTimer = RESTORE_TIME;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function reportButtonValue(button, newValue, oldValue) {
|
||||
if (button == Joysticks.BUTTON_FACE_RIGHT) {
|
||||
if (newValue) {
|
||||
activateWarp();
|
||||
} else {
|
||||
finishWarp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Script.update.connect(update);
|
||||
|
||||
function addJoystick(gamepad) {
|
||||
gamepad.buttonStateChanged.connect(reportButtonValue);
|
||||
|
||||
gamepads[gamepad.instanceId] = gamepad;
|
||||
|
||||
print("Added gamepad: " + gamepad.name + " (" + gamepad.instanceId + ")");
|
||||
}
|
||||
|
||||
function removeJoystick(gamepad) {
|
||||
delete gamepads[gamepad.instanceId]
|
||||
|
||||
print("Removed gamepad: " + gamepad.name + " (" + gamepad.instanceId + ")");
|
||||
}
|
||||
|
||||
var allJoysticks = Joysticks.getAllJoysticks();
|
||||
for (var i = 0; i < allJoysticks.length; i++) {
|
||||
addJoystick(allJoysticks[i]);
|
||||
}
|
||||
|
||||
Joysticks.joystickAdded.connect(addJoystick);
|
||||
Joysticks.joystickRemoved.connect(removeJoystick);
|
||||
|
||||
|
|
|
@ -103,13 +103,14 @@
|
|||
var elIgnoreForCollisions = document.getElementById("property-ignore-for-collisions");
|
||||
var elCollisionsWillMove = document.getElementById("property-collisions-will-move");
|
||||
var elLifetime = document.getElementById("property-lifetime");
|
||||
var elScriptURL = document.getElementById("property-script-url");
|
||||
|
||||
var elBoxSection = document.getElementById("box-section");
|
||||
var elBoxSections = document.querySelectorAll(".box-section");
|
||||
var elBoxColorRed = document.getElementById("property-box-red");
|
||||
var elBoxColorGreen = document.getElementById("property-box-green");
|
||||
var elBoxColorBlue = document.getElementById("property-box-blue");
|
||||
|
||||
var elLightSection = document.getElementById('light-section');
|
||||
var elLightSections = document.querySelectorAll(".light-section");
|
||||
var elLightSpotLight = document.getElementById("property-light-spot-light");
|
||||
var elLightDiffuseRed = document.getElementById("property-light-diffuse-red");
|
||||
var elLightDiffuseGreen = document.getElementById("property-light-diffuse-green");
|
||||
|
@ -129,14 +130,14 @@
|
|||
var elLightExponent = document.getElementById("property-light-exponent");
|
||||
var elLightCutoff = document.getElementById("property-light-cutoff");
|
||||
|
||||
var elModelSection = document.getElementById("model-section");
|
||||
var elModelSections = document.querySelectorAll(".model-section");
|
||||
var elModelURL = document.getElementById("property-model-url");
|
||||
var elModelAnimationURL = document.getElementById("property-model-animation-url");
|
||||
var elModelAnimationPlaying = document.getElementById("property-model-animation-playing");
|
||||
var elModelAnimationFPS = document.getElementById("property-model-animation-fps");
|
||||
var elModelAnimationFrame = document.getElementById("property-model-animation-frame");
|
||||
|
||||
var elTextSection = document.getElementById("text-section");
|
||||
var elTextSections = document.querySelectorAll(".text-section");
|
||||
var elTextText = document.getElementById("property-text-text");
|
||||
var elTextLineHeight = document.getElementById("property-text-line-height");
|
||||
var elTextTextColorRed = document.getElementById("property-text-text-color-red");
|
||||
|
@ -160,102 +161,120 @@
|
|||
elLocked.checked = properties.locked;
|
||||
|
||||
if (properties.locked) {
|
||||
disableChildren(document.getElementById("properties"), 'input');
|
||||
disableChildren(document.getElementById("properties-table"), 'input');
|
||||
elLocked.removeAttribute('disabled');
|
||||
} else {
|
||||
enableChildren(document.getElementById("properties"), 'input');
|
||||
enableChildren(document.getElementById("properties-table"), 'input');
|
||||
}
|
||||
|
||||
elVisible.checked = properties.visible;
|
||||
elVisible.checked = properties.visible;
|
||||
|
||||
elPositionX.value = properties.position.x.toFixed(2);
|
||||
elPositionY.value = properties.position.y.toFixed(2);
|
||||
elPositionZ.value = properties.position.z.toFixed(2);
|
||||
elPositionX.value = properties.position.x.toFixed(2);
|
||||
elPositionY.value = properties.position.y.toFixed(2);
|
||||
elPositionZ.value = properties.position.z.toFixed(2);
|
||||
|
||||
elDimensionsX.value = properties.dimensions.x.toFixed(2);
|
||||
elDimensionsY.value = properties.dimensions.y.toFixed(2);
|
||||
elDimensionsZ.value = properties.dimensions.z.toFixed(2);
|
||||
elDimensionsX.value = properties.dimensions.x.toFixed(2);
|
||||
elDimensionsY.value = properties.dimensions.y.toFixed(2);
|
||||
elDimensionsZ.value = properties.dimensions.z.toFixed(2);
|
||||
|
||||
elRegistrationX.value = properties.registrationPoint.x.toFixed(2);
|
||||
elRegistrationY.value = properties.registrationPoint.y.toFixed(2);
|
||||
elRegistrationZ.value = properties.registrationPoint.z.toFixed(2);
|
||||
elRegistrationX.value = properties.registrationPoint.x.toFixed(2);
|
||||
elRegistrationY.value = properties.registrationPoint.y.toFixed(2);
|
||||
elRegistrationZ.value = properties.registrationPoint.z.toFixed(2);
|
||||
|
||||
elLinearVelocityX.value = properties.velocity.x.toFixed(2);
|
||||
elLinearVelocityY.value = properties.velocity.y.toFixed(2);
|
||||
elLinearVelocityZ.value = properties.velocity.z.toFixed(2);
|
||||
elLinearDamping.value = properties.damping.toFixed(2);
|
||||
elLinearVelocityX.value = properties.velocity.x.toFixed(2);
|
||||
elLinearVelocityY.value = properties.velocity.y.toFixed(2);
|
||||
elLinearVelocityZ.value = properties.velocity.z.toFixed(2);
|
||||
elLinearDamping.value = properties.damping.toFixed(2);
|
||||
|
||||
elAngularVelocityX.value = properties.angularVelocity.x.toFixed(2);
|
||||
elAngularVelocityY.value = properties.angularVelocity.y.toFixed(2);
|
||||
elAngularVelocityZ.value = properties.angularVelocity.z.toFixed(2);
|
||||
elAngularDamping.value = properties.angularDamping.toFixed(2);
|
||||
elAngularVelocityX.value = properties.angularVelocity.x.toFixed(2);
|
||||
elAngularVelocityY.value = properties.angularVelocity.y.toFixed(2);
|
||||
elAngularVelocityZ.value = properties.angularVelocity.z.toFixed(2);
|
||||
elAngularDamping.value = properties.angularDamping.toFixed(2);
|
||||
|
||||
elGravityX.value = properties.gravity.x.toFixed(2);
|
||||
elGravityY.value = properties.gravity.y.toFixed(2);
|
||||
elGravityZ.value = properties.gravity.z.toFixed(2);
|
||||
elGravityX.value = properties.gravity.x.toFixed(2);
|
||||
elGravityY.value = properties.gravity.y.toFixed(2);
|
||||
elGravityZ.value = properties.gravity.z.toFixed(2);
|
||||
|
||||
elMass.value = properties.mass.toFixed(2);
|
||||
elIgnoreForCollisions.checked = properties.ignoreForCollisions;
|
||||
elCollisionsWillMove.checked = properties.collisionsWillMove;
|
||||
elLifetime.value = properties.lifetime;
|
||||
elMass.value = properties.mass.toFixed(2);
|
||||
elIgnoreForCollisions.checked = properties.ignoreForCollisions;
|
||||
elCollisionsWillMove.checked = properties.collisionsWillMove;
|
||||
elLifetime.value = properties.lifetime;
|
||||
elScriptURL.value = properties.script;
|
||||
|
||||
if (properties.type != "Box") {
|
||||
elBoxSection.style.display = 'none';
|
||||
} else {
|
||||
elBoxSection.style.display = 'block';
|
||||
|
||||
elBoxColorRed.value = properties.color.red;
|
||||
elBoxColorGreen.value = properties.color.green;
|
||||
elBoxColorBlue.value = properties.color.blue;
|
||||
if (properties.type != "Box") {
|
||||
for (var i = 0; i < elBoxSections.length; i++) {
|
||||
elBoxSections[i].style.display = 'none';
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < elBoxSections.length; i++) {
|
||||
elBoxSections[i].style.display = 'table-row';
|
||||
}
|
||||
|
||||
if (properties.type != "Model") {
|
||||
elModelSection.style.display = 'none';
|
||||
} else {
|
||||
elModelSection.style.display = 'block';
|
||||
elModelURL.value = properties.modelURL;
|
||||
elModelAnimationURL.value = properties.animationURL;
|
||||
elModelAnimationPlaying.checked = properties.animationIsPlaying;
|
||||
elModelAnimationFPS.value = properties.animationFPS;
|
||||
elBoxColorRed.value = properties.color.red;
|
||||
elBoxColorGreen.value = properties.color.green;
|
||||
elBoxColorBlue.value = properties.color.blue;
|
||||
}
|
||||
|
||||
if (properties.type != "Model") {
|
||||
for (var i = 0; i < elModelSections.length; i++) {
|
||||
elModelSections[i].style.display = 'none';
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < elModelSections.length; i++) {
|
||||
elModelSections[i].style.display = 'table-row';
|
||||
}
|
||||
|
||||
if (properties.type != "Text") {
|
||||
elTextSection.style.display = 'none';
|
||||
} else {
|
||||
elTextSection.style.display = 'block';
|
||||
elModelURL.value = properties.modelURL;
|
||||
elModelAnimationURL.value = properties.animationURL;
|
||||
elModelAnimationPlaying.checked = properties.animationIsPlaying;
|
||||
elModelAnimationFPS.value = properties.animationFPS;
|
||||
}
|
||||
|
||||
elTextText.value = properties.text;
|
||||
elTextLineHeight.value = properties.lineHeight;
|
||||
elTextTextColorRed.value = properties.textColor.red;
|
||||
elTextTextColorGreen.value = properties.textColor.green;
|
||||
elTextTextColorBlue.value = properties.textColor.blue;
|
||||
elTextBackgroundColorRed.value = properties.backgroundColor.red;
|
||||
elTextBackgroundColorGreen.value = properties.backgroundColor.green;
|
||||
elTextBackgroundColorBlue.value = properties.backgroundColor.blue;
|
||||
if (properties.type != "Text") {
|
||||
for (var i = 0; i < elTextSections.length; i++) {
|
||||
elTextSections[i].style.display = 'none';
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < elTextSections.length; i++) {
|
||||
elTextSections[i].style.display = 'table-row';
|
||||
}
|
||||
|
||||
if (properties.type != "Light") {
|
||||
elLightSection.style.display = 'none';
|
||||
} else {
|
||||
elLightSection.style.display = 'block';
|
||||
elTextText.value = properties.text;
|
||||
elTextLineHeight.value = properties.lineHeight;
|
||||
elTextTextColorRed.value = properties.textColor.red;
|
||||
elTextTextColorGreen.value = properties.textColor.green;
|
||||
elTextTextColorBlue.value = properties.textColor.blue;
|
||||
elTextBackgroundColorRed.value = properties.backgroundColor.red;
|
||||
elTextBackgroundColorGreen.value = properties.backgroundColor.green;
|
||||
elTextBackgroundColorBlue.value = properties.backgroundColor.blue;
|
||||
}
|
||||
|
||||
elLightDiffuseRed.value = properties.diffuseColor.red;
|
||||
elLightDiffuseGreen.value = properties.diffuseColor.green;
|
||||
elLightDiffuseBlue.value = properties.diffuseColor.blue;
|
||||
|
||||
elLightAmbientRed.value = properties.ambientColor.red;
|
||||
elLightAmbientGreen.value = properties.ambientColor.green;
|
||||
elLightAmbientBlue.value = properties.ambientColor.blue;
|
||||
|
||||
elLightSpecularRed.value = properties.specularColor.red;
|
||||
elLightSpecularGreen.value = properties.specularColor.green;
|
||||
elLightSpecularBlue.value = properties.specularColor.blue;
|
||||
|
||||
elLightConstantAttenuation.value = properties.constantAttenuation;
|
||||
elLightLinearAttenuation.value = properties.linearAttenuation;
|
||||
elLightQuadraticAttenuation.value = properties.quadraticAttenuation;
|
||||
elLightExponent.value = properties.exponent;
|
||||
elLightCutoff.value = properties.cutoff;
|
||||
if (properties.type != "Light") {
|
||||
for (var i = 0; i < elLightSections.length; i++) {
|
||||
elLightSections[i].style.display = 'none';
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < elLightSections.length; i++) {
|
||||
elLightSections[i].style.display = 'table-row';
|
||||
}
|
||||
|
||||
elLightDiffuseRed.value = properties.diffuseColor.red;
|
||||
elLightDiffuseGreen.value = properties.diffuseColor.green;
|
||||
elLightDiffuseBlue.value = properties.diffuseColor.blue;
|
||||
|
||||
elLightAmbientRed.value = properties.ambientColor.red;
|
||||
elLightAmbientGreen.value = properties.ambientColor.green;
|
||||
elLightAmbientBlue.value = properties.ambientColor.blue;
|
||||
|
||||
elLightSpecularRed.value = properties.specularColor.red;
|
||||
elLightSpecularGreen.value = properties.specularColor.green;
|
||||
elLightSpecularBlue.value = properties.specularColor.blue;
|
||||
|
||||
elLightConstantAttenuation.value = properties.constantAttenuation;
|
||||
elLightLinearAttenuation.value = properties.linearAttenuation;
|
||||
elLightQuadraticAttenuation.value = properties.quadraticAttenuation;
|
||||
elLightExponent.value = properties.exponent;
|
||||
elLightCutoff.value = properties.cutoff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -307,6 +326,7 @@
|
|||
elIgnoreForCollisions.addEventListener('change', createEmitCheckedPropertyUpdateFunction('ignoreForCollisions'));
|
||||
elCollisionsWillMove.addEventListener('change', createEmitCheckedPropertyUpdateFunction('collisionsWillMove'));
|
||||
elLifetime.addEventListener('change', createEmitNumberPropertyUpdateFunction('lifetime'));
|
||||
elScriptURL.addEventListener('change', createEmitTextPropertyUpdateFunction('script'));
|
||||
|
||||
var boxColorChangeFunction = createEmitColorPropertyUpdateFunction(
|
||||
'color', elBoxColorRed, elBoxColorGreen, elBoxColorBlue);
|
||||
|
@ -345,7 +365,7 @@
|
|||
elModelAnimationPlaying.addEventListener('change', createEmitCheckedPropertyUpdateFunction('animationIsPlaying'));
|
||||
elModelAnimationFPS.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFPS'));
|
||||
elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex'));
|
||||
|
||||
|
||||
elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text'));
|
||||
elTextLineHeight.addEventListener('change', createEmitNumberPropertyUpdateFunction('lineHeight'));
|
||||
|
||||
|
@ -361,6 +381,50 @@
|
|||
elTextBackgroundColorGreen.addEventListener('change', textBackgroundColorChangeFunction);
|
||||
elTextBackgroundColorBlue.addEventListener('change', textBackgroundColorChangeFunction);
|
||||
|
||||
|
||||
var resizing = false;
|
||||
var startX = 0;
|
||||
var originalWidth = 0;
|
||||
var resizeHandleWidth = 10;
|
||||
|
||||
var col1 = document.querySelector("#col-label");
|
||||
|
||||
document.body.addEventListener('mousemove', function(event) {
|
||||
if (resizing) {
|
||||
var dX = event.x - startX;
|
||||
col1.style.width = (originalWidth + dX) + "px";
|
||||
}
|
||||
});
|
||||
document.body.addEventListener('mouseup', function(event) {
|
||||
resizing = false;
|
||||
});
|
||||
document.body.addEventListener('mouseleave', function(event) {
|
||||
resizing = false;
|
||||
});
|
||||
var els = document.querySelectorAll("#properties-table td");
|
||||
for (var i = 0; i < els.length; i++) {
|
||||
var el = els[i];
|
||||
el.addEventListener('mousemove', function(event) {
|
||||
if (!resizing) {
|
||||
var distance = this.offsetWidth - event.offsetX;
|
||||
if (distance < resizeHandleWidth) {
|
||||
document.body.style.cursor = "ew-resize";
|
||||
} else {
|
||||
document.body.style.cursor = "initial";
|
||||
}
|
||||
}
|
||||
});
|
||||
el.addEventListener('mousedown', function(event) {
|
||||
var distance = this.offsetWidth - event.offsetX;
|
||||
if (distance < resizeHandleWidth) {
|
||||
startX = event.x;
|
||||
originalWidth = this.offsetWidth;
|
||||
resizing = true;
|
||||
target = this;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
@ -368,272 +432,267 @@
|
|||
<div class="section-header">
|
||||
<label>Entity Properties</label>
|
||||
</div>
|
||||
<div id="properties" class="grid-section">
|
||||
<div class="property-section">
|
||||
<label>Type</label>
|
||||
<span>
|
||||
<label id="property-type"></input>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Locked</label>
|
||||
<span>
|
||||
<table id="properties-table">
|
||||
<colgroup>
|
||||
<col id="col-label">
|
||||
<col>
|
||||
</colgroup>
|
||||
<tr>
|
||||
<td class="label">
|
||||
Type
|
||||
</td>
|
||||
<td>
|
||||
<label id="property-type"></label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label">Locked</td>
|
||||
<td>
|
||||
<input type='checkbox' id="property-locked">
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Visible</label>
|
||||
<span>
|
||||
<tr>
|
||||
<td class="label">Visible</td>
|
||||
<td>
|
||||
<input type='checkbox' id="property-visible">
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Position</label>
|
||||
<span>
|
||||
X <input class="coord" type='number' id="property-pos-x"></input>
|
||||
Y <input class="coord" type='number' id="property-pos-y"></input>
|
||||
Z <input class="coord" type='number' id="property-pos-z"></input>
|
||||
</span>
|
||||
</div>
|
||||
<tr>
|
||||
<td class="label">Position</td>
|
||||
<td>
|
||||
<div class="input-area">X <input class="coord" type='number' id="property-pos-x"></input></div>
|
||||
<div class="input-area">Y <input class="coord" type='number' id="property-pos-y"></input></div>
|
||||
<div class="input-area">Z <input class="coord" type='number' id="property-pos-z"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Registration</label>
|
||||
<span>
|
||||
X <input class="coord" type='number' id="property-reg-x"></input>
|
||||
Y <input class="coord" type='number' id="property-reg-y"></input>
|
||||
Z <input class="coord" type='number' id="property-reg-z"></input>
|
||||
</span>
|
||||
</div>
|
||||
<tr>
|
||||
<td class="label">Registration</td>
|
||||
<td>
|
||||
<div class="input-area">X <input class="coord" type='number' id="property-reg-x"></input></div>
|
||||
<div class="input-area">Y <input class="coord" type='number' id="property-reg-y"></input></div>
|
||||
<div class="input-area">Z <input class="coord" type='number' id="property-reg-z"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Width</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-dim-x"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Height</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-dim-y"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Depth</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-dim-z"></input>
|
||||
</span>
|
||||
</div>
|
||||
<tr>
|
||||
<td class="label">Dimensions</td>
|
||||
<td>
|
||||
<div class="input-area">X <input class="coord" type='number' id="property-dim-x"></input></div>
|
||||
<div class="input-area">Y <input class="coord" type='number' id="property-dim-y"></input></div>
|
||||
<div class="input-area">Z <input class="coord" type='number' id="property-dim-z"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Linear</label>
|
||||
<span>
|
||||
X <input class="coord" type='number' id="property-lvel-x"></input>
|
||||
Y <input class="coord" type='number' id="property-lvel-y"></input>
|
||||
Z <input class="coord" type='number' id="property-lvel-z"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Linear Damping</label>
|
||||
<span>
|
||||
<tr>
|
||||
<td class="label">Linear Velocity</td>
|
||||
<td>
|
||||
<div class="input-area">X <input class="coord" type='number' id="property-lvel-x"></input></div>
|
||||
<div class="input-area">Y <input class="coord" type='number' id="property-lvel-y"></input></div>
|
||||
<div class="input-area">Z <input class="coord" type='number' id="property-lvel-z"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label">Linear Damping</td>
|
||||
<td>
|
||||
<input class="coord" type='number' id="property-ldamping"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Angular</label>
|
||||
<span>
|
||||
Pitch <input class="coord" type='number' id="property-avel-x"></input>
|
||||
Roll <input class="coord" type='number' id="property-avel-z"></input>
|
||||
Yaw <input class="coord" type='number' id="property-avel-y"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Angular Damping</label>
|
||||
<span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label">Angular Velocity</td>
|
||||
<td>
|
||||
<div class="input-area">Pitch <input class="coord" type='number' id="property-avel-x"></input></div>
|
||||
<div class="input-area">Yaw <input class="coord" type='number' id="property-avel-y"></input></div>
|
||||
<div class="input-area">Roll <input class="coord" type='number' id="property-avel-z"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label">Angular Damping</td>
|
||||
<td>
|
||||
<input class="coord" type='number' id="property-adamping"></input>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Gravity</label>
|
||||
<span>
|
||||
X <input class="coord" type='number' id="property-grav-x"></input>
|
||||
Y <input class="coord" type='number' id="property-grav-y"></input>
|
||||
Z <input class="coord" type='number' id="property-grav-z"></input>
|
||||
</span>
|
||||
</div>
|
||||
<tr>
|
||||
<td class="label">Gravity</td>
|
||||
<td>
|
||||
<div class="input-area">X <input class="coord" type='number' id="property-grav-x"></input></div>
|
||||
<div class="input-area">Y <input class="coord" type='number' id="property-grav-y"></input></div>
|
||||
<div class="input-area">Z <input class="coord" type='number' id="property-grav-z"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Mass</label>
|
||||
<span>
|
||||
<tr>
|
||||
<td class="label">Mass</td>
|
||||
<td>
|
||||
<input type='number' id="property-mass"></input>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Ignore For Collisions</label>
|
||||
<span>
|
||||
<tr>
|
||||
<td class="label">Ignore For Collisions</td>
|
||||
<td>
|
||||
<input type='checkbox' id="property-ignore-for-collisions"></input>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Collisions Will Move</label>
|
||||
<span>
|
||||
<tr>
|
||||
<td class="label">Collisions Will Move</td>
|
||||
<td>
|
||||
<input type='checkbox' id="property-collisions-will-move"></input>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="property-section">
|
||||
<label>Lifetime</label>
|
||||
<span>
|
||||
<tr>
|
||||
<td class="label">Lifetime</td>
|
||||
<td>
|
||||
<input type='number' id="property-lifetime"></input>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="label">Script URL</td>
|
||||
<td>
|
||||
<input id="property-script-url"></input>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<div id="box-section" class="multi-property-section">
|
||||
<div class="property-section">
|
||||
<label>Color</label>
|
||||
<span>
|
||||
Red <input class="coord" type='number' id="property-box-red"></input>
|
||||
Green <input class="coord" type='number' id="property-box-green"></input>
|
||||
Blue <input class="coord" type='number' id="property-box-blue"></input>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<tr class="box-section">
|
||||
<td class="label">Color</td>
|
||||
<td>
|
||||
<div class="input-area">R <input class="coord" type='number' id="property-box-red"></input></div>
|
||||
<div class="input-area">G <input class="coord" type='number' id="property-box-green"></input></div>
|
||||
<div class="input-area">B <input class="coord" type='number' id="property-box-blue"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<div id="model-section" class="multi-property-section">
|
||||
<div class="property-section">
|
||||
<label>Model URL</label>
|
||||
<span>
|
||||
<input type="text" id="property-model-url"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Animation URL</label>
|
||||
<span>
|
||||
<input type="text" id="property-model-animation-url"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Animation Playing</label>
|
||||
<span>
|
||||
<input type='checkbox' id="property-model-animation-playing">
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Animation FPS</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-model-animation-fps"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Animation Frame</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-model-animation-frame"></input>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="text-section" class="multi-property-section">
|
||||
<div class="property-section">
|
||||
<label>Text</label>
|
||||
<span>
|
||||
<input type="text" id="property-text-text"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Line Height</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-text-line-height"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Text Color</label>
|
||||
<span>
|
||||
Red <input class="coord" type='number' id="property-text-text-color-red"></input>
|
||||
Green <input class="coord" type='number' id="property-text-text-color-green"></input>
|
||||
Blue <input class="coord" type='number' id="property-text-text-color-blue"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Background Color</label>
|
||||
<span>
|
||||
Red <input class="coord" type='number' id="property-text-background-color-red"></input>
|
||||
Green <input class="coord" type='number' id="property-text-background-color-green"></input>
|
||||
Blue <input class="coord" type='number' id="property-text-background-color-blue"></input>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<tr class="model-section">
|
||||
<td class="label">Model URL</td>
|
||||
<td>
|
||||
<input type="text" id="property-model-url"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="model-section">
|
||||
<td class="label">Animation URL</td>
|
||||
<td>
|
||||
<input type="text" id="property-model-animation-url"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="model-section">
|
||||
<td class="label">Animation Playing</td>
|
||||
<td>
|
||||
<input type='checkbox' id="property-model-animation-playing">
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="model-section">
|
||||
<td class="label">Animation FPS</td>
|
||||
<td>
|
||||
<input class="coord" type='number' id="property-model-animation-fps"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="model-section">
|
||||
<td class="label">Animation Frame</td>
|
||||
<td>
|
||||
<input class="coord" type='number' id="property-model-animation-frame"></input>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<div id="light-section" class="multi-property-section">
|
||||
<div class="property-section">
|
||||
<label>Spot Light</label>
|
||||
<span>
|
||||
<input type='checkbox' id="property-light-spot-light">
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Diffuse</label>
|
||||
<span>
|
||||
Red <input class="coord" type='number' id="property-light-diffuse-red"></input>
|
||||
Green <input class="coord" type='number' id="property-light-diffuse-green"></input>
|
||||
Blue <input class="coord" type='number' id="property-light-diffuse-blue"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Ambient</label>
|
||||
<span>
|
||||
Red <input class="coord" type='number' id="property-light-ambient-red"></input>
|
||||
Green <input class="coord" type='number' id="property-light-ambient-green"></input>
|
||||
Blue <input class="coord" type='number' id="property-light-ambient-blue"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Specular</label>
|
||||
<span>
|
||||
Red <input class="coord" type='number' id="property-light-specular-red"></input>
|
||||
Green <input class="coord" type='number' id="property-light-specular-green"></input>
|
||||
Blue <input class="coord" type='number' id="property-light-specular-blue"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Constant Attenuation</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-light-constant-attenuation"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Linear Attenuation</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-light-linear-attenuation"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Quadratic Attenuation</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-light-quadratic-attenuation"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Exponent</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-light-exponent"></input>
|
||||
</span>
|
||||
</div>
|
||||
<div class="property-section">
|
||||
<label>Cutoff (degrees)</label>
|
||||
<span>
|
||||
<input class="coord" type='number' id="property-light-cutoff"></input>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<tr class="text-section">
|
||||
<td class="label">Text</td>
|
||||
<td>
|
||||
<input type="text" id="property-text-text"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="text-section">
|
||||
<td class="label">Line Height</td>
|
||||
<td>
|
||||
<input class="coord" type='number' id="property-text-line-height"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="text-section">
|
||||
<td class="label">Text Color</td>
|
||||
<td>
|
||||
<div class="input-area">R <input class="coord" type='number' id="property-text-text-color-red"></input></div>
|
||||
<div class="input-area">G <input class="coord" type='number' id="property-text-text-color-green"></input></div>
|
||||
<div class="input-area">B <input class="coord" type='number' id="property-text-text-color-blue"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="text-section">
|
||||
<td class="label">Background Color</td>
|
||||
<td>
|
||||
<div class="input-area">R <input class="coord" type='number' id="property-text-background-color-red"></input></div>
|
||||
<div class="input-area">G <input class="coord" type='number' id="property-text-background-color-green"></input></div>
|
||||
<div class="input-area">B <input class="coord" type='number' id="property-text-background-color-blue"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="light-section">
|
||||
<td class="label">Spot Light</td>
|
||||
<td>
|
||||
<input type='checkbox' id="property-light-spot-light">
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="light-section">
|
||||
<td class="label">Diffuse</td>
|
||||
<td>
|
||||
<div class="input-area">R <input class="coord" type='number' id="property-light-diffuse-red"></input></div>
|
||||
<div class="input-area">G <input class="coord" type='number' id="property-light-diffuse-green"></input></div>
|
||||
<div class="input-area">B <input class="coord" type='number' id="property-light-diffuse-blue"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="light-section">
|
||||
<td class="label">Ambient</td>
|
||||
<td>
|
||||
<div class="input-area">R <input class="coord" type='number' id="property-light-ambient-red"></input></div>
|
||||
<div class="input-area">G <input class="coord" type='number' id="property-light-ambient-green"></input></div>
|
||||
<div class="input-area">B <input class="coord" type='number' id="property-light-ambient-blue"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="light-section">
|
||||
<td class="label">Specular</td>
|
||||
<td>
|
||||
<div class="input-area">R <input class="coord" type='number' id="property-light-specular-red"></input></div>
|
||||
<div class="input-area">G <input class="coord" type='number' id="property-light-specular-green"></input></div>
|
||||
<div class="input-area">B <input class="coord" type='number' id="property-light-specular-blue"></input></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="light-section">
|
||||
<td class="label">Constant Attenuation</td>
|
||||
<td>
|
||||
<input class="coord" type='number' id="property-light-constant-attenuation"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="light-section">
|
||||
<td class="label">Linear Attenuation</td>
|
||||
<td>
|
||||
<input class="coord" type='number' id="property-light-linear-attenuation"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="light-section">
|
||||
<td class="label">Quadratic Attenuation</td>
|
||||
<td>
|
||||
<input class="coord" type='number' id="property-light-quadratic-attenuation"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="light-section">
|
||||
<td class="label">Exponent</td>
|
||||
<td>
|
||||
<input class="coord" type='number' id="property-light-exponent"></input>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="light-section">
|
||||
<td class="label">Cutoff (degrees)</td>
|
||||
<td>
|
||||
<input class="coord" type='number' id="property-light-cutoff"></input>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -29,11 +29,11 @@
|
|||
elPosY.value = origin.y.toFixed(2);
|
||||
}
|
||||
|
||||
if (data.minorGridSpacing) {
|
||||
if (data.minorGridSpacing !== undefined) {
|
||||
elMinorSpacing.value = data.minorGridSpacing;
|
||||
}
|
||||
|
||||
if (data.majorGridEvery) {
|
||||
if (data.majorGridEvery !== undefined) {
|
||||
elMajorSpacing.value = data.majorGridEvery;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
|||
gridColor = data.gridColor;
|
||||
}
|
||||
|
||||
if (data.elSnapToGrid !== undefined) {
|
||||
if (data.snapToGrid !== undefined) {
|
||||
elSnapToGrid.checked = data.snapToGrid == true;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,15 +17,6 @@ body {
|
|||
user-select: none;
|
||||
}
|
||||
|
||||
input {
|
||||
line-height: 2;
|
||||
}
|
||||
|
||||
.input-left {
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
.color-box {
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
|
@ -63,7 +54,6 @@ input {
|
|||
|
||||
.property-section label {
|
||||
font-weight: bold;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.property-section span {
|
||||
|
@ -89,9 +79,10 @@ input[type=button] {
|
|||
font-size: .9em;
|
||||
}
|
||||
|
||||
input.coord {
|
||||
width: 6em;
|
||||
height: 2em;
|
||||
input {
|
||||
padding: 2px;
|
||||
border: 1px solid #999;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
table#entity-table {
|
||||
|
@ -105,7 +96,7 @@ table#entity-table {
|
|||
cursor: pointer;
|
||||
}
|
||||
|
||||
tr.selected {
|
||||
#entity-table tr.selected {
|
||||
background-color: #AAA;
|
||||
}
|
||||
|
||||
|
@ -130,3 +121,48 @@ th#entity-type {
|
|||
|
||||
th#entity-url {
|
||||
}
|
||||
|
||||
|
||||
div.input-area {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
input {
|
||||
}
|
||||
|
||||
|
||||
|
||||
table#properties-table {
|
||||
border: none;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
background-color: #efefef;
|
||||
font-family: Arial;
|
||||
font-size: 12px;
|
||||
table-layout: fixed;
|
||||
}
|
||||
|
||||
#properties-table tr {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
#properties-table td.label {
|
||||
padding-right: 10px;
|
||||
border-right: 1px solid #999;
|
||||
text-align: right;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
vertical-align: middle;
|
||||
height: 1.2em;
|
||||
}
|
||||
|
||||
#properties-table td {
|
||||
padding: 5px 0px 5px 10px;
|
||||
}
|
||||
|
||||
col#col-label {
|
||||
width: 130px;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ ExportMenu = function (opts) {
|
|||
y: pos.y + margin,
|
||||
width: scaleViewWidth,
|
||||
height: height,
|
||||
alpha: 0.0,
|
||||
backgroundAlpha: 0.0,
|
||||
color: { red: 255, green: 255, blue: 255 },
|
||||
text: "1"
|
||||
});
|
||||
|
|
|
@ -26,6 +26,7 @@ function Tooltip() {
|
|||
text: "",
|
||||
color: { red: 128, green: 128, blue: 128 },
|
||||
alpha: 0.2,
|
||||
backgroundAlpha: 0.2,
|
||||
visible: false
|
||||
});
|
||||
this.show = function (doShow) {
|
||||
|
|
|
@ -390,6 +390,7 @@ var ZoomTool = function(opts) {
|
|||
leftMargin: 4,
|
||||
text: "+",
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true,
|
||||
});
|
||||
var decreaseButton = Overlays.addOverlay("text", {
|
||||
|
@ -403,6 +404,7 @@ var ZoomTool = function(opts) {
|
|||
leftMargin: 4,
|
||||
text: "-",
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true,
|
||||
});
|
||||
var zoomBar = Overlays.addOverlay("text", {
|
||||
|
@ -416,6 +418,7 @@ var ZoomTool = function(opts) {
|
|||
leftMargin: 4,
|
||||
text: "",
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true,
|
||||
});
|
||||
var zoomHandle = Overlays.addOverlay("text", {
|
||||
|
@ -428,6 +431,7 @@ var ZoomTool = function(opts) {
|
|||
leftMargin: 4,
|
||||
text: "",
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true,
|
||||
});
|
||||
|
||||
|
@ -501,6 +505,7 @@ var ArrowTool = function(opts) {
|
|||
leftMargin: 4,
|
||||
text: "^",
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true,
|
||||
});
|
||||
var leftButton = Overlays.addOverlay("text", {
|
||||
|
@ -514,6 +519,7 @@ var ArrowTool = function(opts) {
|
|||
leftMargin: 4,
|
||||
text: "<",
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true,
|
||||
});
|
||||
var rightButton = Overlays.addOverlay("text", {
|
||||
|
@ -540,6 +546,7 @@ var ArrowTool = function(opts) {
|
|||
leftMargin: 4,
|
||||
text: "v",
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true,
|
||||
});
|
||||
var centerButton = Overlays.addOverlay("text", {
|
||||
|
@ -553,6 +560,7 @@ var ArrowTool = function(opts) {
|
|||
leftMargin: 4,
|
||||
text: "",
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true,
|
||||
});
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ EntityPropertyDialogBox = (function () {
|
|||
|
||||
array.push({ label: "Entity Type:" + properties.type, type: "header" });
|
||||
index++;
|
||||
array.push({ label: "ID:", value: properties.id });
|
||||
index++;
|
||||
array.push({ label: "Locked:", type: "checkbox", value: properties.locked });
|
||||
index++;
|
||||
|
||||
|
@ -265,6 +267,7 @@ EntityPropertyDialogBox = (function () {
|
|||
var properties = propertiesForEditedEntity;
|
||||
var index = 0;
|
||||
index++; // skip type header
|
||||
index++; // skip id item
|
||||
properties.locked = array[index++].value;
|
||||
if (properties.type == "Model") {
|
||||
properties.modelURL = array[index++].value;
|
||||
|
|
|
@ -368,6 +368,7 @@ SelectionDisplay = (function () {
|
|||
color: { red: 0, green: 0, blue: 0},
|
||||
backgroundColor: { red: 255, green: 255, blue: 255 },
|
||||
alpha: 0.7,
|
||||
backgroundAlpha: 0.7,
|
||||
visible: false,
|
||||
isFacingAvatar: true,
|
||||
drawInFront: true,
|
||||
|
@ -1748,13 +1749,6 @@ SelectionDisplay = (function () {
|
|||
pushCommandForSelections();
|
||||
},
|
||||
onMove: function(event) {
|
||||
var debug = Menu.isOptionChecked("Debug Ryans Rotation Problems");
|
||||
|
||||
if (debug) {
|
||||
print("rotateYaw()...");
|
||||
print(" event.x,y:" + event.x + "," + event.y);
|
||||
}
|
||||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
Overlays.editOverlay(selectionBox, { ignoreRayIntersection: true, visible: false});
|
||||
Overlays.editOverlay(baseOfEntityProjectionOverlay, { ignoreRayIntersection: true, visible: false });
|
||||
|
@ -1762,29 +1756,16 @@ SelectionDisplay = (function () {
|
|||
|
||||
var result = Overlays.findRayIntersection(pickRay);
|
||||
|
||||
if (debug) {
|
||||
print(" findRayIntersection() .... result.intersects:" + result.intersects);
|
||||
}
|
||||
|
||||
if (result.intersects) {
|
||||
var center = yawCenter;
|
||||
var zero = yawZero;
|
||||
var centerToZero = Vec3.subtract(center, zero);
|
||||
var centerToIntersect = Vec3.subtract(center, result.intersection);
|
||||
var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal);
|
||||
|
||||
var distanceFromCenter = Vec3.distance(center, result.intersection);
|
||||
var snapToInner = distanceFromCenter < innerRadius;
|
||||
var snapAngle = snapToInner ? innerSnapAngle : 1.0;
|
||||
angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle;
|
||||
|
||||
// for debugging
|
||||
if (debug) {
|
||||
Vec3.print(" result.intersection:",result.intersection);
|
||||
Overlays.editOverlay(rotateCurrentOverlay, { visible: true, start: center, end: result.intersection });
|
||||
print(" angleFromZero:" + angleFromZero);
|
||||
}
|
||||
|
||||
var yawChange = Quat.fromVec3Degrees({ x: 0, y: angleFromZero, z: 0 });
|
||||
|
||||
// Entities should only reposition if we are rotating multiple selections around
|
||||
|
@ -1895,23 +1876,12 @@ SelectionDisplay = (function () {
|
|||
pushCommandForSelections();
|
||||
},
|
||||
onMove: function(event) {
|
||||
var debug = Menu.isOptionChecked("Debug Ryans Rotation Problems");
|
||||
|
||||
if (debug) {
|
||||
print("rotatePitch()...");
|
||||
print(" event.x,y:" + event.x + "," + event.y);
|
||||
}
|
||||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
Overlays.editOverlay(selectionBox, { ignoreRayIntersection: true, visible: false});
|
||||
Overlays.editOverlay(baseOfEntityProjectionOverlay, { ignoreRayIntersection: true, visible: false });
|
||||
Overlays.editOverlay(rotateOverlayTarget, { ignoreRayIntersection: false });
|
||||
var result = Overlays.findRayIntersection(pickRay);
|
||||
|
||||
if (debug) {
|
||||
print(" findRayIntersection() .... result.intersects:" + result.intersects);
|
||||
}
|
||||
|
||||
if (result.intersects) {
|
||||
var properties = Entities.getEntityProperties(selectionManager.selections[0]);
|
||||
var center = pitchCenter;
|
||||
|
@ -1925,13 +1895,6 @@ SelectionDisplay = (function () {
|
|||
var snapAngle = snapToInner ? innerSnapAngle : 1.0;
|
||||
angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle;
|
||||
|
||||
// for debugging
|
||||
if (debug) {
|
||||
Vec3.print(" result.intersection:",result.intersection);
|
||||
Overlays.editOverlay(rotateCurrentOverlay, { visible: true, start: center, end: result.intersection });
|
||||
print(" angleFromZero:" + angleFromZero);
|
||||
}
|
||||
|
||||
var pitchChange = Quat.fromVec3Degrees({ x: angleFromZero, y: 0, z: 0 });
|
||||
|
||||
for (var i = 0; i < SelectionManager.selections.length; i++) {
|
||||
|
@ -2032,23 +1995,12 @@ SelectionDisplay = (function () {
|
|||
pushCommandForSelections();
|
||||
},
|
||||
onMove: function(event) {
|
||||
var debug = Menu.isOptionChecked("Debug Ryans Rotation Problems");
|
||||
|
||||
if (debug) {
|
||||
print("rotateRoll()...");
|
||||
print(" event.x,y:" + event.x + "," + event.y);
|
||||
}
|
||||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
Overlays.editOverlay(selectionBox, { ignoreRayIntersection: true, visible: false});
|
||||
Overlays.editOverlay(baseOfEntityProjectionOverlay, { ignoreRayIntersection: true, visible: false });
|
||||
Overlays.editOverlay(rotateOverlayTarget, { ignoreRayIntersection: false });
|
||||
var result = Overlays.findRayIntersection(pickRay);
|
||||
|
||||
if (debug) {
|
||||
print(" findRayIntersection() .... result.intersects:" + result.intersects);
|
||||
}
|
||||
|
||||
if (result.intersects) {
|
||||
var properties = Entities.getEntityProperties(selectionManager.selections[0]);
|
||||
var center = rollCenter;
|
||||
|
@ -2062,13 +2014,6 @@ SelectionDisplay = (function () {
|
|||
var snapAngle = snapToInner ? innerSnapAngle : 1.0;
|
||||
angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle;
|
||||
|
||||
// for debugging
|
||||
if (debug) {
|
||||
Vec3.print(" result.intersection:",result.intersection);
|
||||
Overlays.editOverlay(rotateCurrentOverlay, { visible: true, start: center, end: result.intersection });
|
||||
print(" angleFromZero:" + angleFromZero);
|
||||
}
|
||||
|
||||
var rollChange = Quat.fromVec3Degrees({ x: 0, y: 0, z: angleFromZero });
|
||||
for (var i = 0; i < SelectionManager.selections.length; i++) {
|
||||
var entityID = SelectionManager.selections[i];
|
||||
|
@ -2299,14 +2244,6 @@ SelectionDisplay = (function () {
|
|||
Overlays.editOverlay(rotateOverlayInner, { visible: true, rotation: overlayOrientation, position: overlayCenter });
|
||||
Overlays.editOverlay(rotateOverlayOuter, { visible: true, rotation: overlayOrientation, position: overlayCenter, startAt: 0, endAt: 360 });
|
||||
Overlays.editOverlay(rotateOverlayCurrent, { visible: true, rotation: overlayOrientation, position: overlayCenter, startAt: 0, endAt: 0 });
|
||||
|
||||
// for debugging
|
||||
var debug = Menu.isOptionChecked("Debug Ryans Rotation Problems");
|
||||
if (debug) {
|
||||
Overlays.editOverlay(rotateZeroOverlay, { visible: true, start: overlayCenter, end: result.intersection });
|
||||
Overlays.editOverlay(rotateCurrentOverlay, { visible: true, start: overlayCenter, end: result.intersection });
|
||||
}
|
||||
|
||||
Overlays.editOverlay(yawHandle, { visible: false });
|
||||
Overlays.editOverlay(pitchHandle, { visible: false });
|
||||
Overlays.editOverlay(rollHandle, { visible: false });
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
var SETTING_GRID_VISIBLE = 'gridVisible';
|
||||
var SETTING_GRID_SNAP_TO_GRID = 'gridSnapToGrid';
|
||||
var SETTING_GRID_MINOR_WIDTH= 'gridMinorWidth';
|
||||
var SETTING_GRID_MAJOR_EVERY = 'gridMajorEvery';
|
||||
var SETTING_GRID_COLOR = 'gridColor';
|
||||
|
||||
Grid = function(opts) {
|
||||
var that = {};
|
||||
|
||||
|
@ -12,9 +18,6 @@ Grid = function(opts) {
|
|||
|
||||
var worldSize = 16384;
|
||||
|
||||
var minorGridWidth = 0.5;
|
||||
var majorGridWidth = 1.5;
|
||||
|
||||
var snapToGrid = false;
|
||||
|
||||
var gridOverlay = Overlays.addOverlay("grid", {
|
||||
|
@ -23,7 +26,7 @@ Grid = function(opts) {
|
|||
color: { red: 0, green: 0, blue: 128 },
|
||||
alpha: 1.0,
|
||||
rotation: Quat.fromPitchYawRollDegrees(90, 0, 0),
|
||||
minorGridWidth: 0.1,
|
||||
minorGridSpacing: 0.1,
|
||||
majorGridEvery: 2,
|
||||
});
|
||||
|
||||
|
@ -40,16 +43,37 @@ Grid = function(opts) {
|
|||
that.getSnapToGrid = function() { return snapToGrid; };
|
||||
|
||||
that.setEnabled = function(enabled) {
|
||||
that.enabled = enabled;
|
||||
updateGrid();
|
||||
if (that.enabled != enabled) {
|
||||
that.enabled = enabled;
|
||||
|
||||
if (enabled) {
|
||||
if (selectionManager.hasSelection()) {
|
||||
that.setPosition(selectionManager.getBottomPosition());
|
||||
} else {
|
||||
that.setPosition(MyAvatar.position);
|
||||
}
|
||||
}
|
||||
|
||||
updateGrid();
|
||||
}
|
||||
}
|
||||
|
||||
that.setVisible = function(visible, noUpdate) {
|
||||
that.visible = visible;
|
||||
updateGrid();
|
||||
if (visible != that.visible) {
|
||||
that.visible = visible;
|
||||
updateGrid();
|
||||
|
||||
if (!noUpdate) {
|
||||
that.emitUpdate();
|
||||
if (visible) {
|
||||
if (selectionManager.hasSelection()) {
|
||||
that.setPosition(selectionManager.getBottomPosition());
|
||||
} else {
|
||||
that.setPosition(MyAvatar.position);
|
||||
}
|
||||
}
|
||||
|
||||
if (!noUpdate) {
|
||||
that.emitUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +195,7 @@ Grid = function(opts) {
|
|||
Overlays.editOverlay(gridOverlay, {
|
||||
position: { x: origin.y, y: origin.y, z: -origin.y },
|
||||
visible: that.visible && that.enabled,
|
||||
minorGridWidth: minorGridSpacing,
|
||||
minorGridSpacing: minorGridSpacing,
|
||||
majorGridEvery: majorGridEvery,
|
||||
color: gridColor,
|
||||
alpha: gridAlpha,
|
||||
|
@ -181,15 +205,43 @@ Grid = function(opts) {
|
|||
}
|
||||
|
||||
function cleanup() {
|
||||
saveSettings();
|
||||
|
||||
Overlays.deleteOverlay(gridOverlay);
|
||||
}
|
||||
|
||||
function loadSettings() {
|
||||
that.setVisible(Settings.getValue(SETTING_GRID_VISIBLE) == "true", true);
|
||||
snapToGrid = Settings.getValue(SETTING_GRID_SNAP_TO_GRID) == "true";
|
||||
minorGridSpacing = parseFloat(Settings.getValue(SETTING_GRID_MINOR_WIDTH), 10);
|
||||
majorGridEvery = parseInt(Settings.getValue(SETTING_GRID_MAJOR_EVERY), 10);
|
||||
try {
|
||||
var newColor = JSON.parse(Settings.getValue(SETTING_GRID_COLOR));
|
||||
if (newColor.red !== undefined && newColor.green !== undefined && newColor.blue !== undefined) {
|
||||
gridColor.red = newColor.red;
|
||||
gridColor.green = newColor.green;
|
||||
gridColor.blue = newColor.blue;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
updateGrid();
|
||||
}
|
||||
|
||||
function saveSettings() {
|
||||
Settings.setValue(SETTING_GRID_VISIBLE, that.visible);
|
||||
Settings.setValue(SETTING_GRID_SNAP_TO_GRID, snapToGrid);
|
||||
Settings.setValue(SETTING_GRID_MINOR_WIDTH, minorGridSpacing);
|
||||
Settings.setValue(SETTING_GRID_MAJOR_EVERY, majorGridEvery);
|
||||
Settings.setValue(SETTING_GRID_COLOR, JSON.stringify(gridColor));
|
||||
}
|
||||
|
||||
that.addListener = function(callback) {
|
||||
that.onUpdate = callback;
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
updateGrid();
|
||||
|
||||
loadSettings();
|
||||
|
||||
that.onUpdate = null;
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ progressDialog = (function () {
|
|||
textColor: textColor,
|
||||
backgroundColor: textBackground,
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
|
@ -50,6 +51,7 @@ progressDialog = (function () {
|
|||
textColor: textColor,
|
||||
backgroundColor: textBackground,
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
|
|
|
@ -138,6 +138,7 @@ ToolBar = function(x, y, direction) {
|
|||
width: this.width,
|
||||
height: this.height,
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: false
|
||||
});
|
||||
this.spacing = [];
|
||||
|
@ -243,7 +244,10 @@ ToolBar = function(x, y, direction) {
|
|||
this.tools[tool].setAlpha(alpha);
|
||||
}
|
||||
if (this.back != null) {
|
||||
Overlays.editOverlay(this.back, { alpha: alpha});
|
||||
Overlays.editOverlay(this.back, {
|
||||
alpha: alpha,
|
||||
backgroundAlpha: alpha
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.tools[tool].setAlpha(alpha);
|
||||
|
@ -263,7 +267,7 @@ ToolBar = function(x, y, direction) {
|
|||
((direction == ToolBar.VERTICAL) ? 1 : 2) * ToolBar.SPACING,
|
||||
visible: true,
|
||||
backgroundColor: color,
|
||||
alpha: alpha
|
||||
backgroundAlpha: alpha
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ function drawLobby() {
|
|||
};
|
||||
|
||||
var orbShellProps = {
|
||||
url: HIFI_PUBLIC_BUCKET + "models/sets/Lobby/Lobby_v8/forStephen1/LobbyShell1.fbx",
|
||||
url: HIFI_PUBLIC_BUCKET + "models/sets/Lobby/Lobby_v8/forStephen1/LobbyShell1.4_LightTag.fbx",
|
||||
position: orbPosition,
|
||||
rotation: towardsMe,
|
||||
dimensions: orbDimensions,
|
||||
|
@ -113,6 +113,7 @@ function drawLobby() {
|
|||
text: "",
|
||||
lineHeight: lineHeight,
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.9,
|
||||
ignoreRayIntersection: true,
|
||||
visible: false,
|
||||
isFacingAvatar: true
|
||||
|
|
|
@ -140,24 +140,22 @@ var toolBar = (function () {
|
|||
menuItemHeight = Tool.IMAGE_HEIGHT / 2 - 2;
|
||||
|
||||
loadURLMenuItem = Overlays.addOverlay("text", {
|
||||
x: newModelButton.x - menuItemWidth,
|
||||
y: newModelButton.y + menuItemOffset,
|
||||
height: menuItemHeight,
|
||||
backgroundColor: menuBackgroundColor,
|
||||
topMargin: menuItemMargin,
|
||||
text: "Model URL",
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
loadFileMenuItem = Overlays.addOverlay("text", {
|
||||
x: newModelButton.x - menuItemWidth,
|
||||
y: newModelButton.y + menuItemOffset + menuItemHeight,
|
||||
height: menuItemHeight,
|
||||
backgroundColor: menuBackgroundColor,
|
||||
topMargin: menuItemMargin,
|
||||
text: "Model File",
|
||||
alpha: 0.9,
|
||||
backgroundAlpha: 0.9,
|
||||
visible: false
|
||||
});
|
||||
|
||||
|
@ -215,6 +213,28 @@ var toolBar = (function () {
|
|||
Overlays.editOverlay(loadFileMenuItem, { visible: active });
|
||||
}
|
||||
|
||||
|
||||
that.setActive = function(active) {
|
||||
if (active != isActive) {
|
||||
isActive = active;
|
||||
if (!isActive) {
|
||||
entityListTool.setVisible(false);
|
||||
gridTool.setVisible(false);
|
||||
grid.setEnabled(false);
|
||||
propertiesTool.setVisible(false);
|
||||
selectionManager.clearSelections();
|
||||
cameraManager.disable();
|
||||
} else {
|
||||
cameraManager.enable();
|
||||
entityListTool.setVisible(true);
|
||||
gridTool.setVisible(true);
|
||||
propertiesTool.setVisible(true);
|
||||
grid.setEnabled(true);
|
||||
}
|
||||
}
|
||||
toolBar.selectTool(activeButton, active);
|
||||
};
|
||||
|
||||
var RESIZE_INTERVAL = 50;
|
||||
var RESIZE_TIMEOUT = 20000;
|
||||
var RESIZE_MAX_CHECKS = RESIZE_TIMEOUT / RESIZE_INTERVAL;
|
||||
|
@ -290,21 +310,7 @@ var toolBar = (function () {
|
|||
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||
|
||||
if (activeButton === toolBar.clicked(clickedOverlay)) {
|
||||
isActive = !isActive;
|
||||
if (!isActive) {
|
||||
entityListTool.setVisible(false);
|
||||
gridTool.setVisible(false);
|
||||
grid.setEnabled(false);
|
||||
propertiesTool.setVisible(false);
|
||||
selectionManager.clearSelections();
|
||||
cameraManager.disable();
|
||||
} else {
|
||||
cameraManager.enable();
|
||||
entityListTool.setVisible(true);
|
||||
gridTool.setVisible(true);
|
||||
grid.setEnabled(true);
|
||||
propertiesTool.setVisible(true);
|
||||
}
|
||||
that.setActive(!isActive);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -465,7 +471,7 @@ function rayPlaneIntersection(pickRay, point, normal) {
|
|||
function findClickedEntity(event) {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
|
||||
var foundIntersection = Entities.findRayIntersection(pickRay);
|
||||
var foundIntersection = Entities.findRayIntersection(pickRay, true); // want precision picking
|
||||
|
||||
if (!foundIntersection.accurate) {
|
||||
return null;
|
||||
|
@ -668,7 +674,6 @@ function setupModelMenus() {
|
|||
Menu.addMenuItem({ menuName: "File", menuItemName: "Models", isSeparator: true, beforeItem: "Settings" });
|
||||
Menu.addMenuItem({ menuName: "File", menuItemName: "Export Models", shortcutKey: "CTRL+META+E", afterItem: "Models" });
|
||||
Menu.addMenuItem({ menuName: "File", menuItemName: "Import Models", shortcutKey: "CTRL+META+I", afterItem: "Export Models" });
|
||||
Menu.addMenuItem({ menuName: "Developer", menuItemName: "Debug Ryans Rotation Problems", isCheckable: true });
|
||||
|
||||
Menu.addMenuItem({ menuName: "View", menuItemName: MENU_EASE_ON_FOCUS, afterItem: MENU_INSPECT_TOOL_ENABLED,
|
||||
isCheckable: true, isChecked: Settings.getValue(SETTING_EASE_ON_FOCUS) == "true" });
|
||||
|
@ -695,7 +700,6 @@ function cleanupModelMenus() {
|
|||
Menu.removeSeparator("File", "Models");
|
||||
Menu.removeMenuItem("File", "Export Models");
|
||||
Menu.removeMenuItem("File", "Import Models");
|
||||
Menu.removeMenuItem("Developer", "Debug Ryans Rotation Problems");
|
||||
|
||||
Menu.removeMenuItem("View", MENU_INSPECT_TOOL_ENABLED);
|
||||
Menu.removeMenuItem("View", MENU_EASE_ON_FOCUS);
|
||||
|
@ -817,6 +821,13 @@ function handeMenuEvent(menuItem) {
|
|||
|
||||
Menu.menuItemEvent.connect(handeMenuEvent);
|
||||
|
||||
Controller.keyPressEvent.connect(function(event) {
|
||||
if (event.text == 'w' || event.text == 'a' || event.text == 's' || event.text == 'd'
|
||||
|| event.text == 'UP' || event.text == 'DOWN' || event.text == 'LEFT' || event.text == 'RIGHT') {
|
||||
toolBar.setActive(false);
|
||||
}
|
||||
});
|
||||
|
||||
Controller.keyReleaseEvent.connect(function (event) {
|
||||
// since sometimes our menu shortcut keys don't work, trap our menu items here also and fire the appropriate menu items
|
||||
if (event.text == "`") {
|
||||
|
|
|
@ -115,6 +115,7 @@ function createNotification(text) {
|
|||
color: textColor,
|
||||
backgroundColor: backColor,
|
||||
alpha: backgroundAlpha,
|
||||
backgroundAlpha: backgroundAlpha,
|
||||
topMargin: topMargin,
|
||||
leftMargin: leftMargin,
|
||||
font: {size: fontSize},
|
||||
|
@ -160,7 +161,7 @@ function fadeIn(noticeIn, buttonIn) {
|
|||
pauseTimer = Script.setInterval(function() {
|
||||
q++;
|
||||
qFade = q / 10.0;
|
||||
Overlays.editOverlay(noticeIn, {alpha: qFade});
|
||||
Overlays.editOverlay(noticeIn, {alpha: qFade, backgroundAlpha: qFade});
|
||||
Overlays.editOverlay(buttonIn, {alpha: qFade});
|
||||
if (q >= 9.0) {
|
||||
Script.clearInterval(pauseTimer);
|
||||
|
@ -344,7 +345,7 @@ function fadeOut(noticeOut, buttonOut, arraysOut) {
|
|||
pauseTimer = Script.setInterval(function() {
|
||||
r--;
|
||||
rFade = r / 10.0;
|
||||
Overlays.editOverlay(noticeOut, {alpha: rFade});
|
||||
Overlays.editOverlay(noticeOut, {alpha: rFade, backgroundAlpha: rFade});
|
||||
Overlays.editOverlay(buttonOut, {alpha: rFade});
|
||||
if (r < 0) {
|
||||
dismiss(noticeOut, buttonOut, arraysOut);
|
||||
|
|
45
examples/orbitingSound.js
Normal file
45
examples/orbitingSound.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// orbitingSound.js
|
||||
// examples
|
||||
//
|
||||
// Created by Philip Rosedale on December 4, 2014
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// An object playing a sound appears and circles you, changing brightness with the audio playing.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
var RADIUS = 2.0;
|
||||
var orbitCenter = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.getOrientation()), RADIUS));
|
||||
var time = 0;
|
||||
var SPEED = 1.0;
|
||||
var currentPosition = { x: 0, y: 0, z: 0 };
|
||||
var trailingLoudness = 0.0;
|
||||
|
||||
var soundClip = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Tabla+Loops/Tabla1.wav");
|
||||
|
||||
var properties = {
|
||||
type: "Box",
|
||||
position: orbitCenter,
|
||||
dimensions: { x: 0.25, y: 0.25, z: 0.25 },
|
||||
color: { red: 100, green: 0, blue : 0 }
|
||||
};
|
||||
|
||||
var objectId = Entities.addEntity(properties);
|
||||
var sound = Audio.playSound(soundClip, { position: orbitCenter, loop: true, volume: 0.5 });
|
||||
|
||||
function update(deltaTime) {
|
||||
time += deltaTime;
|
||||
currentPosition = { x: orbitCenter.x + Math.cos(time * SPEED) * RADIUS, y: orbitCenter.y, z: orbitCenter.z + Math.sin(time * SPEED) * RADIUS };
|
||||
trailingLoudness = 0.9 * trailingLoudness + 0.1 * Audio.getLoudness(sound);
|
||||
Entities.editEntity( objectId, { position: currentPosition, color: { red: Math.min(trailingLoudness * 2000, 255), green: 0, blue: 0 } } );
|
||||
Audio.setInjectorOptions(sound, { position: currentPosition });
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(function() {
|
||||
Entities.deleteEntity(objectId);
|
||||
Audio.stopInjector(sound);
|
||||
});
|
||||
|
||||
Script.update.connect(update);
|
|
@ -69,7 +69,8 @@ var text = Overlays.addOverlay("text", {
|
|||
topMargin: 4,
|
||||
leftMargin: 4,
|
||||
text: "Here is some text.\nAnd a second line.",
|
||||
alpha: 0.7
|
||||
alpha: 0.7,
|
||||
backgroundAlpha: 0.5
|
||||
});
|
||||
|
||||
// This will create an image overlay, which starts out as invisible
|
||||
|
@ -170,6 +171,7 @@ var clipboardPreview = Overlays.addOverlay("clipboard", {
|
|||
// Demonstrate retrieving overlay properties
|
||||
print("Text overlay text property value =\n" + Overlays.getProperty(text, "text"));
|
||||
print("Text overlay alpha =\n" + Overlays.getProperty(text, "alpha"));
|
||||
print("Text overlay background alpha =\n" + Overlays.getProperty(text, "backgroundAlpha"));
|
||||
print("Text overlay visible =\n" + Overlays.getProperty(text, "visible"));
|
||||
print("Text overlay font size =\n" + Overlays.getProperty(text, "font").size);
|
||||
print("Text overlay anchor =\n" + Overlays.getProperty(text, "anchor"));
|
||||
|
|
|
@ -57,6 +57,7 @@ var statusText = Overlays.addOverlay("text", {
|
|||
height: 20,
|
||||
backgroundColor: { red: 0, green: 0, blue: 0},
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
color: { red: 255, green: 255, blue: 255},
|
||||
topMargin: 4,
|
||||
leftMargin: 4,
|
||||
|
|
|
@ -32,167 +32,168 @@ var clickedButton = false;
|
|||
var cursor = "|";
|
||||
// add more characters to the string if required
|
||||
var keyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
|
||||
~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,./"; //permitted characters
|
||||
~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,./"; //permitted characters
|
||||
|
||||
|
||||
// This will create a text overlay that displays what you type
|
||||
var inputWindow = Overlays.addOverlay("text", {
|
||||
x: locationX,
|
||||
y: locationY,
|
||||
width: width,
|
||||
height: height,
|
||||
color: textColor,
|
||||
backgroundColor: backColor,
|
||||
alpha: backgroundAlpha,
|
||||
topMargin: topMargin,
|
||||
leftMargin: leftMargin,
|
||||
font: {size: fontSize},
|
||||
text: writing,
|
||||
visible: true
|
||||
});
|
||||
x: locationX,
|
||||
y: locationY,
|
||||
width: width,
|
||||
height: height,
|
||||
color: textColor,
|
||||
backgroundColor: backColor,
|
||||
alpha: backgroundAlpha,
|
||||
backgroundAlpha: backgroundAlpha,
|
||||
topMargin: topMargin,
|
||||
leftMargin: leftMargin,
|
||||
font: {size: fontSize},
|
||||
text: writing,
|
||||
visible: true
|
||||
});
|
||||
// This will create an image overlay of a button.
|
||||
var button1 = Overlays.addOverlay("image", { // green button
|
||||
x: buttonLocationX,
|
||||
y: locationY + 10,
|
||||
width: 40,
|
||||
height: 35,
|
||||
subImage: { x: 0, y: 0, width: 39, height: 35 },
|
||||
imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png",
|
||||
color: readyColor,
|
||||
visible: true
|
||||
});
|
||||
x: buttonLocationX,
|
||||
y: locationY + 10,
|
||||
width: 40,
|
||||
height: 35,
|
||||
subImage: { x: 0, y: 0, width: 39, height: 35 },
|
||||
imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png",
|
||||
color: readyColor,
|
||||
visible: true
|
||||
});
|
||||
// This will create an image overlay of another button.
|
||||
var button2 = Overlays.addOverlay("image", { // red button
|
||||
x: buttonLocationX,
|
||||
y: locationY + 60,
|
||||
width: 40,
|
||||
height: 35,
|
||||
subImage: { x: 0, y: 0, width: 39, height: 35 },
|
||||
imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png",
|
||||
color: { red: 250, green: 2, blue: 2},
|
||||
visible: true,
|
||||
});
|
||||
x: buttonLocationX,
|
||||
y: locationY + 60,
|
||||
width: 40,
|
||||
height: 35,
|
||||
subImage: { x: 0, y: 0, width: 39, height: 35 },
|
||||
imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png",
|
||||
color: { red: 250, green: 2, blue: 2},
|
||||
visible: true,
|
||||
});
|
||||
// When our script shuts down, we should clean up all of our overlays
|
||||
function scriptEnding() {
|
||||
Overlays.deleteOverlay(inputWindow);
|
||||
Overlays.deleteOverlay(button1);
|
||||
Overlays.deleteOverlay(button2);
|
||||
//Return control of keys to default on script ending
|
||||
for(var i=0; i<keyString.length; i++){
|
||||
var nextChar = keyString.charAt(i);
|
||||
Controller.releaseKeyEvents({ text: nextChar});
|
||||
}
|
||||
Controller.releaseKeyEvents({"key": 0x5c}); // forward slash
|
||||
Controller.releaseKeyEvents({ text: "SHIFT"});
|
||||
Controller.releaseKeyEvents({ text: "BACKSPACE"});
|
||||
Controller.releaseKeyEvents({ text: "SPACE"});
|
||||
Controller.releaseKeyEvents({"key":16777220} ); //Enter
|
||||
Controller.releaseKeyEvents({"key":16777219} ); //Backspace
|
||||
Overlays.deleteOverlay(inputWindow);
|
||||
Overlays.deleteOverlay(button1);
|
||||
Overlays.deleteOverlay(button2);
|
||||
//Return control of keys to default on script ending
|
||||
for(var i=0; i<keyString.length; i++){
|
||||
var nextChar = keyString.charAt(i);
|
||||
Controller.releaseKeyEvents({ text: nextChar});
|
||||
}
|
||||
Controller.releaseKeyEvents({"key": 0x5c}); // forward slash
|
||||
Controller.releaseKeyEvents({ text: "SHIFT"});
|
||||
Controller.releaseKeyEvents({ text: "BACKSPACE"});
|
||||
Controller.releaseKeyEvents({ text: "SPACE"});
|
||||
Controller.releaseKeyEvents({"key":16777220} ); //Enter
|
||||
Controller.releaseKeyEvents({"key":16777219} ); //Backspace
|
||||
}
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
|
||||
function resetForm(){
|
||||
writing = ""; // Start with a blank string
|
||||
Overlays.editOverlay(button1, {color: readyColor} );
|
||||
Overlays.editOverlay(inputWindow, {backgroundColor: readyColor});
|
||||
clickedText = true;
|
||||
writing = ""; // Start with a blank string
|
||||
Overlays.editOverlay(button1, {color: readyColor} );
|
||||
Overlays.editOverlay(inputWindow, {backgroundColor: readyColor});
|
||||
clickedText = true;
|
||||
}
|
||||
|
||||
function submitForm(){
|
||||
print("form submitted");
|
||||
writingOutput = writing; // writingOutput is the data output
|
||||
writing = writing + ".\nYour data has been stored.\n\nClick here to reset form or \n\n\nClick red button to close,";
|
||||
Overlays.editOverlay(button1, { color: clickedColor} );
|
||||
Overlays.editOverlay(inputWindow, {backgroundColor: clickedColor});
|
||||
clickedText = false;
|
||||
clickedButton = true;
|
||||
print("form submitted");
|
||||
writingOutput = writing; // writingOutput is the data output
|
||||
writing = writing + ".\nYour data has been stored.\n\nClick here to reset form or \n\n\nClick red button to close,";
|
||||
Overlays.editOverlay(button1, { color: clickedColor} );
|
||||
Overlays.editOverlay(inputWindow, {backgroundColor: clickedColor});
|
||||
clickedText = false;
|
||||
clickedButton = true;
|
||||
}
|
||||
|
||||
// handle click detection
|
||||
function mousePressEvent(event) {
|
||||
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); //identify which overlay was clicked
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); //identify which overlay was clicked
|
||||
|
||||
if (clickedOverlay == inputWindow) { // if the user clicked on the text window, prepare the overlay
|
||||
if (clickedText == false){ // first time clicked?
|
||||
resetForm();
|
||||
}
|
||||
}
|
||||
if (clickedOverlay == inputWindow) { // if the user clicked on the text window, prepare the overlay
|
||||
if (clickedText == false){ // first time clicked?
|
||||
resetForm();
|
||||
}
|
||||
}
|
||||
|
||||
if (clickedOverlay == button1) { // if the user clicked on the green button
|
||||
if (clickedText == true){ // nothing happens unless the text window was clicked first
|
||||
submitForm();
|
||||
// clickedText == false;
|
||||
}
|
||||
else { // if the form has been submitted already
|
||||
resetForm();
|
||||
}
|
||||
}
|
||||
if (clickedOverlay == button1) { // if the user clicked on the green button
|
||||
if (clickedText == true){ // nothing happens unless the text window was clicked first
|
||||
submitForm();
|
||||
// clickedText == false;
|
||||
}
|
||||
else { // if the form has been submitted already
|
||||
resetForm();
|
||||
}
|
||||
}
|
||||
|
||||
if (clickedOverlay == button2) { // if the user clicked on the red button
|
||||
print ("script ending");
|
||||
Script.stop();
|
||||
}
|
||||
if (clickedOverlay == button2) { // if the user clicked on the red button
|
||||
print ("script ending");
|
||||
Script.stop();
|
||||
}
|
||||
}
|
||||
|
||||
//handle key press detection
|
||||
function keyPressEvent(key) {
|
||||
|
||||
if (clickedText == true){
|
||||
if (clickedText == true){
|
||||
|
||||
if (key.text == "SPACE") { //special conditions for space bar
|
||||
writing = writing + " ";
|
||||
key.text ="";
|
||||
}
|
||||
else if (key.text == "BACKSPACE") { // Backspace
|
||||
var myString = writing;
|
||||
writing = myString.substr(0, myString.length-1);
|
||||
key.text ="";
|
||||
}
|
||||
if (key.text == "SPACE") { //special conditions for space bar
|
||||
writing = writing + " ";
|
||||
key.text ="";
|
||||
}
|
||||
else if (key.text == "BACKSPACE") { // Backspace
|
||||
var myString = writing;
|
||||
writing = myString.substr(0, myString.length-1);
|
||||
key.text ="";
|
||||
}
|
||||
|
||||
if (key.text == "\r") { //special conditions for enter key
|
||||
writing = writing + "\n";
|
||||
key.text ="";
|
||||
}
|
||||
else if ( keyString.indexOf(key.text) == -1) { // prevent all other keys not in keyString
|
||||
key.text ="";
|
||||
}
|
||||
// build the string
|
||||
writing = writing + key.text;
|
||||
}
|
||||
if (key.text == "\r") { //special conditions for enter key
|
||||
writing = writing + "\n";
|
||||
key.text ="";
|
||||
}
|
||||
else if ( keyString.indexOf(key.text) == -1) { // prevent all other keys not in keyString
|
||||
key.text ="";
|
||||
}
|
||||
// build the string
|
||||
writing = writing + key.text;
|
||||
}
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
function updateWriting(deltaTime){
|
||||
count++;
|
||||
// every half second or so, remove and replace the pipe to create a blinking cursor
|
||||
if (count % 30 == 0) {
|
||||
if (cursor == "|") {
|
||||
cursor="";
|
||||
} else {
|
||||
cursor = "|";
|
||||
}
|
||||
}
|
||||
// attempt at some overflow control of the text
|
||||
if ((writing.length % 53) == 0) {
|
||||
writing = writing + "\n";
|
||||
}
|
||||
// add blinking cursor to window during typing
|
||||
var addCursor = writing + cursor;
|
||||
if (clickedText == true){
|
||||
Overlays.editOverlay(inputWindow, { text: addCursor});
|
||||
}else{
|
||||
Overlays.editOverlay(inputWindow, { text: writing});
|
||||
}
|
||||
count++;
|
||||
// every half second or so, remove and replace the pipe to create a blinking cursor
|
||||
if (count % 30 == 0) {
|
||||
if (cursor == "|") {
|
||||
cursor="";
|
||||
} else {
|
||||
cursor = "|";
|
||||
}
|
||||
}
|
||||
// attempt at some overflow control of the text
|
||||
if ((writing.length % 53) == 0) {
|
||||
writing = writing + "\n";
|
||||
}
|
||||
// add blinking cursor to window during typing
|
||||
var addCursor = writing + cursor;
|
||||
if (clickedText == true){
|
||||
Overlays.editOverlay(inputWindow, { text: addCursor});
|
||||
}else{
|
||||
Overlays.editOverlay(inputWindow, { text: writing});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// test keystroke against keyString and capture permitted keys
|
||||
for (var i=0; i<keyString.length; i++){
|
||||
var nextChar = keyString.charAt(i);
|
||||
Controller.captureKeyEvents({ text: nextChar});
|
||||
var nextChar = keyString.charAt(i);
|
||||
Controller.captureKeyEvents({ text: nextChar});
|
||||
}
|
||||
// capture special keys
|
||||
Controller.captureKeyEvents({ "key": 0x5c}); //forward slash key
|
||||
|
|
598
examples/virtualKeyboard.js
Normal file
598
examples/virtualKeyboard.js
Normal file
|
@ -0,0 +1,598 @@
|
|||
//
|
||||
// virtualKeyboard.js
|
||||
// examples
|
||||
//
|
||||
// Created by Thijs Wenker on 11/18/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Control a virtual keyboard using your favorite HMD.
|
||||
// Usage: Enable VR-mode and go to First person mode,
|
||||
// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard.
|
||||
//
|
||||
// leased some code from newEditEntities.js for Text Entity example
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
Script.include("libraries/globals.js");
|
||||
|
||||
const KBD_UPPERCASE_DEFAULT = 0;
|
||||
const KBD_LOWERCASE_DEFAULT = 1;
|
||||
const KBD_UPPERCASE_HOVER = 2;
|
||||
const KBD_LOWERCASE_HOVER = 3;
|
||||
const KBD_BACKGROUND = 4;
|
||||
|
||||
const KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg";
|
||||
const CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg";
|
||||
|
||||
const SPACEBAR_CHARCODE = 32;
|
||||
|
||||
const KEYBOARD_WIDTH = 1174.7;
|
||||
const KEYBOARD_HEIGHT = 434.1;
|
||||
|
||||
const CURSOR_WIDTH = 33.9;
|
||||
const CURSOR_HEIGHT = 33.9;
|
||||
|
||||
// VIEW_ANGLE can be adjusted to your likings, the smaller the faster movement.
|
||||
// Try setting it to 60 if it goes too fast for you.
|
||||
const VIEW_ANGLE = 40.0;
|
||||
const VIEW_ANGLE_BY_TWO = VIEW_ANGLE / 2;
|
||||
|
||||
const SPAWN_DISTANCE = 1;
|
||||
const DEFAULT_TEXT_DIMENSION_Z = 0.02;
|
||||
|
||||
const BOUND_X = 0;
|
||||
const BOUND_Y = 1;
|
||||
const BOUND_W = 2;
|
||||
const BOUND_H = 3;
|
||||
|
||||
const KEY_STATE_LOWER = 0;
|
||||
const KEY_STATE_UPPER = 1;
|
||||
|
||||
const TEXT_MARGIN_TOP = 0.15;
|
||||
const TEXT_MARGIN_LEFT = 0.15;
|
||||
const TEXT_MARGIN_RIGHT = 0.17;
|
||||
const TEXT_MARGIN_BOTTOM = 0.17;
|
||||
|
||||
var windowDimensions = Controller.getViewportDimensions();
|
||||
var cursor = null;
|
||||
var keyboard = new Keyboard();
|
||||
var textFontSize = 9;
|
||||
var text = null;
|
||||
var textText = "";
|
||||
var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false});
|
||||
|
||||
function appendChar(char) {
|
||||
textText += char;
|
||||
updateTextOverlay();
|
||||
Overlays.editOverlay(text, {text: textText});
|
||||
}
|
||||
|
||||
function deleteChar() {
|
||||
if (textText.length > 0) {
|
||||
textText = textText.substring(0, textText.length - 1);
|
||||
updateTextOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
function updateTextOverlay() {
|
||||
var textLines = textText.split("\n");
|
||||
var maxLineWidth = 0;
|
||||
for (textLine in textLines) {
|
||||
var lineWidth = Overlays.textWidth(text, textLines[textLine]);
|
||||
if (lineWidth > maxLineWidth) {
|
||||
maxLineWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90;
|
||||
var maxFontSize = 190 / textLines.length;
|
||||
textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize;
|
||||
var topMargin = (250 - (textFontSize * textLines.length)) / 4;
|
||||
Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin});
|
||||
var maxLineWidth = 0;
|
||||
for (textLine in textLines) {
|
||||
var lineWidth = Overlays.textWidth(text, textLines[textLine]);
|
||||
if (lineWidth > maxLineWidth) {
|
||||
maxLineWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2});
|
||||
}
|
||||
|
||||
keyboard.onKeyPress = function(event) {
|
||||
if (event.event == 'keypress') {
|
||||
appendChar(event.char);
|
||||
} else if (event.event == 'enter') {
|
||||
appendChar("\n");
|
||||
}
|
||||
};
|
||||
|
||||
keyboard.onKeyRelease = function(event) {
|
||||
print("Key release event test");
|
||||
// you can cancel a key by releasing its focusing before releasing it
|
||||
if (event.focus) {
|
||||
if (event.event == 'delete') {
|
||||
deleteChar();
|
||||
} else if (event.event == 'submit') {
|
||||
print(textText);
|
||||
|
||||
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
||||
|
||||
var textLines = textText.split("\n");
|
||||
var maxLineWidth = 0;
|
||||
for (textLine in textLines) {
|
||||
var lineWidth = Overlays.textWidth(textSizeMeasureOverlay, textLines[textLine]);
|
||||
if (lineWidth > maxLineWidth) {
|
||||
maxLineWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
var usernameLine = "--" + GlobalServices.myUsername;
|
||||
var usernameWidth = Overlays.textWidth(textSizeMeasureOverlay, usernameLine);
|
||||
if (maxLineWidth < usernameWidth) {
|
||||
maxLineWidth = usernameWidth;
|
||||
} else {
|
||||
var spaceableWidth = maxLineWidth - usernameWidth;
|
||||
var spaceWidth = Overlays.textWidth(textSizeMeasureOverlay, " ");
|
||||
var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth);
|
||||
for (var i = 0; i < numberOfSpaces; i++) {
|
||||
usernameLine = " " + usernameLine;
|
||||
}
|
||||
}
|
||||
var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT;
|
||||
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||
Entities.addEntity({
|
||||
type: "Text",
|
||||
rotation: MyAvatar.orientation,
|
||||
position: position,
|
||||
dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z },
|
||||
backgroundColor: { red: 0, green: 0, blue: 0 },
|
||||
textColor: { red: 255, green: 255, blue: 255 },
|
||||
text: textText + "\n" + usernameLine
|
||||
});
|
||||
}
|
||||
textText = "";
|
||||
updateTextOverlay();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
keyboard.onFullyLoaded = function() {
|
||||
print("Virtual-keyboard fully loaded.");
|
||||
var dimensions = Controller.getViewportDimensions();
|
||||
text = Overlays.addOverlay("text", {
|
||||
x: 0,
|
||||
y: dimensions.y - keyboard.height() - 260,
|
||||
width: dimensions.x,
|
||||
height: 250,
|
||||
backgroundColor: { red: 255, green: 255, blue: 255},
|
||||
color: { red: 0, green: 0, blue: 0},
|
||||
topMargin: 5,
|
||||
leftMargin: 0,
|
||||
font: {size: textFontSize},
|
||||
text: "",
|
||||
alpha: 0.8
|
||||
});
|
||||
updateTextOverlay();
|
||||
// the cursor is being loaded after the keyboard, else it will be on the background of the keyboard
|
||||
cursor = new Cursor();
|
||||
cursor.onUpdate = function(position) {
|
||||
keyboard.setFocusPosition(position.x, position.y);
|
||||
};
|
||||
};
|
||||
|
||||
function KeyboardKey(keyboard, keyProperties) {
|
||||
var tthis = this;
|
||||
this._focus = false;
|
||||
this._beingPressed = false;
|
||||
this.event = keyProperties.event != undefined ?
|
||||
keyProperties.event : 'keypress';
|
||||
this.bounds = keyProperties.bounds;
|
||||
this.states = keyProperties.states;
|
||||
this.keyboard = keyboard;
|
||||
this.keyState = keyProperties.keyState != undefined ? keyProperties.keyState : KBD_LOWERCASE_DEFAULT;
|
||||
// one overlay per bound vector [this.bounds]
|
||||
this.overlays = [];
|
||||
this.getKeyEvent = function() {
|
||||
if (tthis.event == 'keypress') {
|
||||
var state = tthis.states[(tthis.keyboard.shift ? 1 : 2) % tthis.states.length];
|
||||
return {key: state.charCode, char: state.char, event: tthis.event, focus: tthis._focus};
|
||||
}
|
||||
return {event: tthis.event, focus: tthis._focus};
|
||||
};
|
||||
this.containsCoord = function(x, y) {
|
||||
for (var i = 0; i < this.bounds.length; i++) {
|
||||
if (x >= this.bounds[i][BOUND_X] &&
|
||||
x <= (this.bounds[i][BOUND_X] + this.bounds[i][BOUND_W]) &&
|
||||
y >= this.bounds[i][BOUND_Y] &&
|
||||
y <= (this.bounds[i][BOUND_Y] + this.bounds[i][BOUND_H]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
this.updateState = function() {
|
||||
tthis.setState(eval('KBD_' + (tthis.keyboard.shift ? 'UPPERCASE' : 'LOWERCASE') + '_' + (tthis._focus ? 'HOVER' : 'DEFAULT')));
|
||||
};
|
||||
this.updateColor = function() {
|
||||
var colorIntensity = this._beingPressed ? 128 : 255;
|
||||
for (var i = 0; i < tthis.bounds.length; i++) {
|
||||
Overlays.editOverlay(tthis.overlays[i],
|
||||
{color: {red: colorIntensity, green: colorIntensity, blue: colorIntensity}}
|
||||
);
|
||||
}
|
||||
};
|
||||
this.press = function() {
|
||||
tthis._beingPressed = true;
|
||||
tthis.updateColor();
|
||||
};
|
||||
this.release = function() {
|
||||
tthis._beingPressed = false;
|
||||
tthis.updateColor();
|
||||
};
|
||||
this.blur = function() {
|
||||
tthis._focus = false;
|
||||
tthis.updateState();
|
||||
};
|
||||
this.focus = function() {
|
||||
tthis._focus = true;
|
||||
tthis.updateState();
|
||||
};
|
||||
this.setState = function(state) {
|
||||
tthis.keyState = state;
|
||||
for (var i = 0; i < tthis.bounds.length; i++) {
|
||||
Overlays.editOverlay(tthis.overlays[i], {
|
||||
subImage: {width: tthis.bounds[i][BOUND_W], height: tthis.bounds[i][BOUND_H], x: tthis.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * tthis.keyState) + tthis.bounds[i][BOUND_Y]}
|
||||
});
|
||||
}
|
||||
};
|
||||
this.rescale = function() {
|
||||
for (var i = 0; i < tthis.bounds.length; i++) {
|
||||
Overlays.editOverlay(tthis.overlays[i], {
|
||||
x: tthis.keyboard.getX() + tthis.bounds[i][BOUND_X] * keyboard.scale,
|
||||
y: tthis.keyboard.getY() + tthis.bounds[i][BOUND_Y] * keyboard.scale,
|
||||
width: this.bounds[i][BOUND_W] * keyboard.scale,
|
||||
height: this.bounds[i][BOUND_H] * keyboard.scale
|
||||
});
|
||||
}
|
||||
};
|
||||
this.remove = function() {
|
||||
for (var i = 0; i < this.overlays.length; i++) {
|
||||
Overlays.deleteOverlay(this.overlays[i]);
|
||||
}
|
||||
};
|
||||
this.isLoaded = function() {
|
||||
for (var i = 0; i < this.overlays.length; i++) {
|
||||
if (!Overlays.isLoaded(this.overlays[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
for (var i = 0; i < this.bounds.length; i++) {
|
||||
var newOverlay = Overlays.cloneOverlay(this.keyboard.background);
|
||||
Overlays.editOverlay(newOverlay, {
|
||||
x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale,
|
||||
y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale,
|
||||
width: this.bounds[i][BOUND_W] * keyboard.scale,
|
||||
height: this.bounds[i][BOUND_H] * keyboard.scale,
|
||||
subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]},
|
||||
alpha: 1
|
||||
});
|
||||
this.overlays.push(newOverlay);
|
||||
}
|
||||
}
|
||||
|
||||
function Keyboard() {
|
||||
var tthis = this;
|
||||
this.focussed_key = -1;
|
||||
this.scale = windowDimensions.x / KEYBOARD_WIDTH;
|
||||
this.shift = false;
|
||||
this.width = function() {
|
||||
return KEYBOARD_WIDTH * tthis.scale;
|
||||
};
|
||||
this.height = function() {
|
||||
return KEYBOARD_HEIGHT * tthis.scale;
|
||||
};
|
||||
this.getX = function() {
|
||||
return (windowDimensions.x / 2) - (this.width() / 2);
|
||||
};
|
||||
this.getY = function() {
|
||||
return windowDimensions.y - this.height();
|
||||
};
|
||||
this.background = Overlays.addOverlay("image", {
|
||||
x: this.getX(),
|
||||
y: this.getY(),
|
||||
width: this.width(),
|
||||
height: this.height(),
|
||||
subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND},
|
||||
imageURL: KEYBOARD_URL,
|
||||
alpha: 1
|
||||
});
|
||||
this.rescale = function() {
|
||||
this.scale = windowDimensions.x / KEYBOARD_WIDTH;
|
||||
Overlays.editOverlay(tthis.background, {
|
||||
x: this.getX(),
|
||||
y: this.getY(),
|
||||
width: this.width(),
|
||||
height: this.height()
|
||||
});
|
||||
for (var i = 0; i < tthis.keys.length; i++) {
|
||||
tthis.keys[i].rescale();
|
||||
}
|
||||
};
|
||||
|
||||
this.setFocusPosition = function(x, y) {
|
||||
// set to local unscaled position
|
||||
var localx = (x - tthis.getX()) / tthis.scale;
|
||||
var localy = (y - tthis.getY()) / tthis.scale;
|
||||
var new_focus_key = -1;
|
||||
if (localx >= 0 && localy >= 0 && localx <= KEYBOARD_WIDTH && localy <= KEYBOARD_HEIGHT) {
|
||||
for (var i = 0; i < tthis.keys.length; i++) {
|
||||
if (tthis.keys[i].containsCoord(localx, localy)) {
|
||||
new_focus_key = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (new_focus_key != tthis.focussed_key) {
|
||||
if (tthis.focussed_key != -1) {
|
||||
tthis.keys[tthis.focussed_key].blur();
|
||||
}
|
||||
tthis.focussed_key = new_focus_key;
|
||||
if (tthis.focussed_key != -1) {
|
||||
tthis.keys[tthis.focussed_key].focus();
|
||||
}
|
||||
}
|
||||
return tthis;
|
||||
};
|
||||
|
||||
this.pressFocussedKey = function() {
|
||||
if (tthis.focussed_key != -1) {
|
||||
if (tthis.keys[tthis.focussed_key].event == 'shift') {
|
||||
tthis.toggleShift();
|
||||
} else {
|
||||
tthis.keys[tthis.focussed_key].press();
|
||||
}
|
||||
if (this.onKeyPress != null) {
|
||||
this.onKeyPress(tthis.keys[tthis.focussed_key].getKeyEvent());
|
||||
}
|
||||
}
|
||||
|
||||
return tthis;
|
||||
};
|
||||
|
||||
this.releaseKeys = function() {
|
||||
for (var i = 0; i < tthis.keys.length; i++) {
|
||||
if (tthis.keys[i]._beingPressed) {
|
||||
if (tthis.keys[i].event != 'shift') {
|
||||
tthis.keys[i].release();
|
||||
}
|
||||
if (this.onKeyRelease != null) {
|
||||
this.onKeyRelease(tthis.keys[i].getKeyEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.toggleShift = function() {
|
||||
tthis.shift = !tthis.shift;
|
||||
for (var i = 0; i < tthis.keys.length; i++) {
|
||||
tthis.keys[i].updateState();
|
||||
if (tthis.keys[i].event == 'shift') {
|
||||
if (tthis.shift) {
|
||||
tthis.keys[i].press();
|
||||
continue;
|
||||
}
|
||||
tthis.keys[i].release();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.getFocussedKey = function() {
|
||||
if (tthis.focussed_key == -1) {
|
||||
return null;
|
||||
}
|
||||
return tthis.keys[tthis.focussed_key];
|
||||
};
|
||||
|
||||
this.remove = function() {
|
||||
Overlays.deleteOverlay(this.background);
|
||||
for (var i = 0; i < this.keys.length; i++) {
|
||||
this.keys[i].remove();
|
||||
}
|
||||
};
|
||||
|
||||
this.onKeyPress = null;
|
||||
this.onKeyRelease = null;
|
||||
this.onSubmit = null;
|
||||
this.onFullyLoaded = null;
|
||||
|
||||
this.keys = [];
|
||||
//
|
||||
// keyProperties contains the key data
|
||||
//
|
||||
// coords [[x,y,w,h],[x,y,w,h]]
|
||||
// states array of 1 or 2 objects [lowercase, uppercase] each object contains a charCode and a char
|
||||
var keyProperties = [
|
||||
{bounds: [[12, 12, 65, 52]], states: [{charCode: 126, char: '~'}]},
|
||||
{bounds: [[84, 12, 65, 52]], states: [{charCode: 33, char: '!'}]},
|
||||
{bounds: [[156, 12, 65, 52]], states: [{charCode: 64, char: '@'}]},
|
||||
{bounds: [[228, 12, 65, 52]], states: [{charCode: 35, char: '#'}]},
|
||||
{bounds: [[300, 12, 65, 52]], states: [{charCode: 36, char: '$'}]},
|
||||
{bounds: [[372, 12, 65, 52]], states: [{charCode: 37, char: '%'}]},
|
||||
{bounds: [[445, 12, 65, 52]], states: [{charCode: 94, char: '^'}]},
|
||||
{bounds: [[517, 12, 65, 52]], states: [{charCode: 38, char: '&'}]},
|
||||
{bounds: [[589, 12, 65, 52]], states: [{charCode: 42, char: '*'}]},
|
||||
{bounds: [[662, 12, 65, 52]], states: [{charCode: 40, char: '('}]},
|
||||
{bounds: [[734, 12, 65, 52]], states: [{charCode: 41, char: ')'}]},
|
||||
{bounds: [[806, 12, 65, 52]], states: [{charCode: 95, char: '_'}]},
|
||||
{bounds: [[881, 12, 65, 52]], states: [{charCode: 123, char: '{'}]},
|
||||
{bounds: [[953, 12, 65, 52]], states: [{charCode: 125, char: '}'}]},
|
||||
{bounds: [[1025, 12, 65, 52]], states: [{charCode: 60, char: '<'}]},
|
||||
{bounds: [[1097, 12, 65, 52]], states: [{charCode: 62, char: '>'}]},
|
||||
|
||||
{bounds: [[12, 71, 65, 63]], states: [{charCode: 96, char: '`'}]},
|
||||
{bounds: [[84, 71, 65, 63]], states: [{charCode: 49, char: '1'}]},
|
||||
{bounds: [[156, 71, 65, 63]], states: [{charCode: 50, char: '2'}]},
|
||||
{bounds: [[228, 71, 65, 63]], states: [{charCode: 51, char: '3'}]},
|
||||
{bounds: [[300, 71, 65, 63]], states: [{charCode: 52, char: '4'}]},
|
||||
{bounds: [[372, 71, 65, 63]], states: [{charCode: 53, char: '5'}]},
|
||||
{bounds: [[445, 71, 65, 63]], states: [{charCode: 54, char: '6'}]},
|
||||
{bounds: [[517, 71, 65, 63]], states: [{charCode: 55, char: '7'}]},
|
||||
{bounds: [[589, 71, 65, 63]], states: [{charCode: 56, char: '8'}]},
|
||||
{bounds: [[661, 71, 65, 63]], states: [{charCode: 57, char: '9'}]},
|
||||
{bounds: [[733, 71, 65, 63]], states: [{charCode: 48, char: '0'}]},
|
||||
{bounds: [[806, 71, 65, 63]], states: [{charCode: 45, char: '-'}]},
|
||||
{bounds: [[880, 71, 65, 63]], states: [{charCode: 61, char: '='}]},
|
||||
{bounds: [[953, 71, 65, 63]], states: [{charCode: 43, char: '+'}]},
|
||||
{bounds: [[1024, 71, 139, 63]], event: 'delete'},
|
||||
|
||||
// enter key has 2 bounds and one state
|
||||
{bounds: [[11, 143, 98, 71], [11, 213, 121, 62]], event: 'enter'},
|
||||
|
||||
{bounds: [[118, 142, 64, 63]], states: [{charCode: 113, char: 'q'}, {charCode: 81, char: 'Q'}]},
|
||||
{bounds: [[190, 142, 64, 63]], states: [{charCode: 119, char: 'w'}, {charCode: 87, char: 'W'}]},
|
||||
{bounds: [[262, 142, 64, 63]], states: [{charCode: 101, char: 'e'}, {charCode: 69, char: 'E'}]},
|
||||
{bounds: [[334, 142, 64, 63]], states: [{charCode: 114, char: 'r'}, {charCode: 82, char: 'R'}]},
|
||||
{bounds: [[407, 142, 64, 63]], states: [{charCode: 116, char: 't'}, {charCode: 84, char: 'T'}]},
|
||||
{bounds: [[479, 142, 64, 63]], states: [{charCode: 121, char: 'y'}, {charCode: 89, char: 'Y'}]},
|
||||
{bounds: [[551, 142, 65, 63]], states: [{charCode: 117, char: 'u'}, {charCode: 85, char: 'U'}]},
|
||||
{bounds: [[623, 142, 65, 63]], states: [{charCode: 105, char: 'i'}, {charCode: 73, char: 'I'}]},
|
||||
{bounds: [[695, 142, 65, 63]], states: [{charCode: 111, char: 'o'}, {charCode: 79, char: 'O'}]},
|
||||
{bounds: [[768, 142, 64, 63]], states: [{charCode: 112, char: 'p'}, {charCode: 80, char: 'P'}]},
|
||||
{bounds: [[840, 142, 64, 63]], states: [{charCode: 91, char: '['}]},
|
||||
{bounds: [[912, 142, 65, 63]], states: [{charCode: 93, char: ']'}]},
|
||||
{bounds: [[984, 142, 65, 63]], states: [{charCode: 92, char: '\\'}]},
|
||||
{bounds: [[1055, 142, 65, 63]], states: [{charCode: 124, char: '|'}]},
|
||||
|
||||
{bounds: [[1126, 143, 35, 72], [1008, 214, 153, 62]], event: 'enter'},
|
||||
|
||||
{bounds: [[140, 213, 65, 63]], states: [{charCode: 97, char: 'a'}, {charCode: 65, char: 'A'}]},
|
||||
{bounds: [[211, 213, 64, 63]], states: [{charCode: 115, char: 's'}, {charCode: 83, char: 'S'}]},
|
||||
{bounds: [[283, 213, 65, 63]], states: [{charCode: 100, char: 'd'}, {charCode: 68, char: 'D'}]},
|
||||
{bounds: [[355, 213, 65, 63]], states: [{charCode: 102, char: 'f'}, {charCode: 70, char: 'F'}]},
|
||||
{bounds: [[428, 213, 64, 63]], states: [{charCode: 103, char: 'g'}, {charCode: 71, char: 'G'}]},
|
||||
{bounds: [[500, 213, 64, 63]], states: [{charCode: 104, char: 'h'}, {charCode: 72, char: 'H'}]},
|
||||
{bounds: [[572, 213, 65, 63]], states: [{charCode: 106, char: 'j'}, {charCode: 74, char: 'J'}]},
|
||||
{bounds: [[644, 213, 65, 63]], states: [{charCode: 107, char: 'k'}, {charCode: 75, char: 'K'}]},
|
||||
{bounds: [[716, 213, 65, 63]], states: [{charCode: 108, char: 'l'}, {charCode: 76, char: 'L'}]},
|
||||
{bounds: [[789, 213, 64, 63]], states: [{charCode: 59, char: ';'}]},
|
||||
{bounds: [[861, 213, 64, 63]], states: [{charCode: 39, char: '\''}]},
|
||||
{bounds: [[934, 213, 65, 63]], states: [{charCode: 58, char: ':'}]},
|
||||
|
||||
{bounds: [[12, 283, 157, 63]], event: 'shift'},
|
||||
|
||||
{bounds: [[176, 283, 65, 63]], states: [{charCode: 122, char: 'z'}, {charCode: 90, char: 'Z'}]},
|
||||
{bounds: [[249, 283, 64, 63]], states: [{charCode: 120, char: 'x'}, {charCode: 88, char: 'X'}]},
|
||||
{bounds: [[321, 283, 64, 63]], states: [{charCode: 99, char: 'c'}, {charCode: 67, char: 'C'}]},
|
||||
{bounds: [[393, 283, 64, 63]], states: [{charCode: 118, char: 'v'}, {charCode: 86, char: 'V'}]},
|
||||
{bounds: [[465, 283, 65, 63]], states: [{charCode: 98, char: 'b'}, {charCode: 66, char: 'B'}]},
|
||||
{bounds: [[537, 283, 65, 63]], states: [{charCode: 110, char: 'n'}, {charCode: 78, char: 'N'}]},
|
||||
{bounds: [[610, 283, 64, 63]], states: [{charCode: 109, char: 'm'}, {charCode: 77, char: 'M'}]},
|
||||
{bounds: [[682, 283, 64, 63]], states: [{charCode: 44, char: ','}]},
|
||||
{bounds: [[754, 283, 65, 63]], states: [{charCode: 46, char: '.'}]},
|
||||
{bounds: [[826, 283, 65, 63]], states: [{charCode: 47, char: '/'}]},
|
||||
{bounds: [[899, 283, 64, 63]], states: [{charCode: 63, char: '?'}]},
|
||||
|
||||
{bounds: [[972, 283, 190, 63]], event: 'shift'},
|
||||
|
||||
{bounds: [[249, 355, 573, 67]], states: [{charCode: 32, char: ' '}]},
|
||||
|
||||
{bounds: [[899, 355, 263, 67]], event: 'submit'}
|
||||
];
|
||||
|
||||
this.keyboardTextureLoaded = function() {
|
||||
if (Overlays.isLoaded(tthis.background)) {
|
||||
Script.clearInterval(tthis.keyboardTextureLoaded_timer);
|
||||
for (var i = 0; i < keyProperties.length; i++) {
|
||||
tthis.keys.push(new KeyboardKey(tthis, keyProperties[i]));
|
||||
}
|
||||
if (keyboard.onFullyLoaded != null) {
|
||||
tthis.onFullyLoaded();
|
||||
}
|
||||
}
|
||||
};
|
||||
this.keyboardTextureLoaded_timer = Script.setInterval(this.keyboardTextureLoaded, 250);
|
||||
}
|
||||
|
||||
function Cursor() {
|
||||
var tthis = this;
|
||||
this.x = windowDimensions.x / 2;
|
||||
this.y = windowDimensions.y / 2;
|
||||
this.overlay = Overlays.addOverlay("image", {
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
width: CURSOR_WIDTH,
|
||||
height: CURSOR_HEIGHT,
|
||||
imageURL: CURSOR_URL,
|
||||
alpha: 1
|
||||
});
|
||||
this.remove = function() {
|
||||
Overlays.deleteOverlay(this.overlay);
|
||||
};
|
||||
this.getPosition = function() {
|
||||
return {x: tthis.getX(), y: tthis.getY()};
|
||||
};
|
||||
this.getX = function() {
|
||||
return tthis.x;
|
||||
};
|
||||
this.getY = function() {
|
||||
return tthis.y;
|
||||
};
|
||||
this.onUpdate = null;
|
||||
this.update = function() {
|
||||
var newWindowDimensions = Controller.getViewportDimensions();
|
||||
if (newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y) {
|
||||
windowDimensions = newWindowDimensions;
|
||||
keyboard.rescale();
|
||||
Overlays.editOverlay(text, {
|
||||
y: windowDimensions.y - keyboard.height() - 260,
|
||||
width: windowDimensions.x
|
||||
});
|
||||
}
|
||||
var editobject = {};
|
||||
if (MyAvatar.getHeadFinalYaw() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalYaw() >= -1 * VIEW_ANGLE_BY_TWO) {
|
||||
angle = ((-1 * MyAvatar.getHeadFinalYaw()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE;
|
||||
tthis.x = angle * windowDimensions.x;
|
||||
editobject.x = tthis.x - (CURSOR_WIDTH / 2);
|
||||
}
|
||||
if (MyAvatar.getHeadFinalPitch() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalPitch() >= -1 * VIEW_ANGLE_BY_TWO) {
|
||||
angle = ((-1 * MyAvatar.getHeadFinalPitch()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE;
|
||||
tthis.y = angle * windowDimensions.y;
|
||||
editobject.y = tthis.y - (CURSOR_HEIGHT / 2);
|
||||
}
|
||||
if (Object.keys(editobject).length > 0) {
|
||||
Overlays.editOverlay(tthis.overlay, editobject);
|
||||
if (tthis.onUpdate != null) {
|
||||
tthis.onUpdate(tthis.getPosition());
|
||||
}
|
||||
}
|
||||
};
|
||||
Script.update.connect(this.update);
|
||||
}
|
||||
|
||||
function keyPressEvent(event) {
|
||||
if (event.key === SPACEBAR_CHARCODE) {
|
||||
keyboard.pressFocussedKey();
|
||||
}
|
||||
}
|
||||
|
||||
function keyReleaseEvent(event) {
|
||||
if (event.key === SPACEBAR_CHARCODE) {
|
||||
keyboard.releaseKeys();
|
||||
}
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
keyboard.remove();
|
||||
cursor.remove();
|
||||
Overlays.deleteOverlay(text);
|
||||
Overlays.deleteOverlay(textSizeMeasureOverlay);
|
||||
Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE});
|
||||
}
|
||||
Controller.captureKeyEvents({key: SPACEBAR_CHARCODE});
|
||||
Controller.keyPressEvent.connect(keyPressEvent);
|
||||
Controller.keyReleaseEvent.connect(keyReleaseEvent);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
|
@ -107,7 +107,7 @@ endif()
|
|||
add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM})
|
||||
|
||||
# link required hifi libraries
|
||||
link_hifi_libraries(shared octree voxels fbx metavoxels networking entities avatars audio animation script-engine physics)
|
||||
link_hifi_libraries(shared octree voxels gpu fbx metavoxels networking entities avatars audio animation script-engine physics)
|
||||
|
||||
# find any optional and required libraries
|
||||
find_package(ZLIB REQUIRED)
|
||||
|
|
|
@ -165,8 +165,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
_scaleMirror(1.0f),
|
||||
_rotateMirror(0.0f),
|
||||
_raiseMirror(0.0f),
|
||||
_mouseX(0),
|
||||
_mouseY(0),
|
||||
_lastMouseMove(usecTimestampNow()),
|
||||
_lastMouseMoveWasSimulated(false),
|
||||
_mouseHidden(false),
|
||||
|
@ -1132,7 +1130,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||
if (!event->isAutoRepeat()) {
|
||||
// this starts an HFActionEvent
|
||||
HFActionEvent startActionEvent(HFActionEvent::startType(),
|
||||
_viewFrustum.computePickRay(0.5f, 0.5f));
|
||||
_myCamera.computeViewPickRay(0.5f, 0.5f));
|
||||
sendEvent(this, &startActionEvent);
|
||||
}
|
||||
|
||||
|
@ -1223,7 +1221,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
|
|||
case Qt::Key_Space: {
|
||||
if (!event->isAutoRepeat()) {
|
||||
// this ends the HFActionEvent
|
||||
HFActionEvent endActionEvent(HFActionEvent::endType(), _viewFrustum.computePickRay(0.5f, 0.5f));
|
||||
HFActionEvent endActionEvent(HFActionEvent::endType(), _myCamera.computeViewPickRay(0.5f, 0.5f));
|
||||
sendEvent(this, &endActionEvent);
|
||||
}
|
||||
|
||||
|
@ -1254,7 +1252,6 @@ void Application::focusOutEvent(QFocusEvent* event) {
|
|||
}
|
||||
|
||||
void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
|
||||
bool showMouse = true;
|
||||
|
||||
// Used by application overlay to determine how to draw cursor(s)
|
||||
|
@ -1283,13 +1280,9 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||
_mouseHidden = false;
|
||||
_seenMouseMove = true;
|
||||
}
|
||||
|
||||
_mouseX = event->x();
|
||||
_mouseY = event->y();
|
||||
}
|
||||
|
||||
void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
|
||||
if (!_aboutToQuit) {
|
||||
_entities.mousePressEvent(event, deviceID);
|
||||
}
|
||||
|
@ -1304,20 +1297,20 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||
|
||||
if (activeWindow() == _window) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
_mouseX = event->x();
|
||||
_mouseY = event->y();
|
||||
_mouseDragStartedX = _mouseX;
|
||||
_mouseDragStartedY = _mouseY;
|
||||
_mouseDragStartedX = getTrueMouseX();
|
||||
_mouseDragStartedY = getTrueMouseY();
|
||||
_mousePressed = true;
|
||||
|
||||
if (_audio.mousePressEvent(_mouseX, _mouseY)) {
|
||||
// stop propagation
|
||||
return;
|
||||
}
|
||||
|
||||
if (_rearMirrorTools->mousePressEvent(_mouseX, _mouseY)) {
|
||||
// stop propagation
|
||||
return;
|
||||
|
||||
if (mouseOnScreen()) {
|
||||
if (_audio.mousePressEvent(getMouseX(), getMouseY())) {
|
||||
// stop propagation
|
||||
return;
|
||||
}
|
||||
|
||||
if (_rearMirrorTools->mousePressEvent(getMouseX(), getMouseY())) {
|
||||
// stop propagation
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// nobody handled this - make it an action event on the _window object
|
||||
|
@ -1346,15 +1339,14 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
|
|||
|
||||
if (activeWindow() == _window) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
_mouseX = event->x();
|
||||
_mouseY = event->y();
|
||||
_mousePressed = false;
|
||||
|
||||
checkBandwidthMeterClick();
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && mouseOnScreen()) {
|
||||
// let's set horizontal offset to give stats some margin to mirror
|
||||
int horizontalOffset = MIRROR_VIEW_WIDTH;
|
||||
Stats::getInstance()->checkClick(_mouseX, _mouseY, _mouseDragStartedX, _mouseDragStartedY, horizontalOffset);
|
||||
Stats::getInstance()->checkClick(getMouseX(), getMouseY(),
|
||||
getMouseDragStartedX(), getMouseDragStartedY(), horizontalOffset);
|
||||
checkBandwidthMeterClick();
|
||||
}
|
||||
|
||||
// fire an action end event
|
||||
|
@ -1547,13 +1539,13 @@ void Application::idle() {
|
|||
|
||||
void Application::checkBandwidthMeterClick() {
|
||||
// ... to be called upon button release
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth) &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::Stats) &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::UserInterface) &&
|
||||
glm::compMax(glm::abs(glm::ivec2(_mouseX - _mouseDragStartedX, _mouseY - _mouseDragStartedY)))
|
||||
<= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH
|
||||
&& _bandwidthMeter.isWithinArea(_mouseX, _mouseY, _glWidget->width(), _glWidget->height())) {
|
||||
glm::compMax(glm::abs(glm::ivec2(getMouseX() - getMouseDragStartedX(),
|
||||
getMouseY() - getMouseDragStartedY())))
|
||||
<= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH
|
||||
&& _bandwidthMeter.isWithinArea(getMouseX(), getMouseY(), _glWidget->width(), _glWidget->height())) {
|
||||
|
||||
// The bandwidth meter is visible, the click didn't get dragged too far and
|
||||
// we actually hit the bandwidth meter
|
||||
|
@ -1667,6 +1659,48 @@ glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVox
|
|||
(mouseVoxel.z + mouseVoxel.s / 2.0f) * TREE_SCALE);
|
||||
}
|
||||
|
||||
bool Application::mouseOnScreen() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
return getMouseX() >= 0 && getMouseX() <= _glWidget->getDeviceWidth() &&
|
||||
getMouseY() >= 0 && getMouseY() <= _glWidget->getDeviceHeight();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int Application::getMouseX() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
|
||||
return pos.x;
|
||||
}
|
||||
return getTrueMouseX();
|
||||
}
|
||||
|
||||
int Application::getMouseY() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
|
||||
return pos.y;
|
||||
}
|
||||
return getTrueMouseY();
|
||||
}
|
||||
|
||||
int Application::getMouseDragStartedX() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseDragStartedX(),
|
||||
getTrueMouseDragStartedY()));
|
||||
return pos.x;
|
||||
}
|
||||
return getTrueMouseDragStartedX();
|
||||
}
|
||||
|
||||
int Application::getMouseDragStartedY() const {
|
||||
if (OculusManager::isConnected()) {
|
||||
glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseDragStartedX(),
|
||||
getTrueMouseDragStartedY()));
|
||||
return pos.y;
|
||||
}
|
||||
return getTrueMouseDragStartedY();
|
||||
}
|
||||
|
||||
FaceTracker* Application::getActiveFaceTracker() {
|
||||
return (_dde.isActive() ? static_cast<FaceTracker*>(&_dde) :
|
||||
(_faceshift.isActive() ? static_cast<FaceTracker*>(&_faceshift) :
|
||||
|
@ -1897,10 +1931,6 @@ void Application::init() {
|
|||
_voxelShader.init();
|
||||
_pointShader.init();
|
||||
|
||||
_mouseX = _glWidget->width() / 2;
|
||||
_mouseY = _glWidget->height() / 2;
|
||||
QCursor::setPos(_mouseX, _mouseY);
|
||||
|
||||
// TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager
|
||||
_avatarManager.init();
|
||||
_myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
|
||||
|
@ -1989,6 +2019,13 @@ void Application::init() {
|
|||
connect(&_entityCollisionSystem, &EntityCollisionSystem::entityCollisionWithEntity,
|
||||
ScriptEngine::getEntityScriptingInterface(), &EntityScriptingInterface::entityCollisionWithEntity);
|
||||
|
||||
// connect the _entityCollisionSystem to our EntityTreeRenderer since that's what handles running entity scripts
|
||||
connect(&_entityCollisionSystem, &EntityCollisionSystem::entityCollisionWithVoxel,
|
||||
&_entities, &EntityTreeRenderer::entityCollisionWithVoxel);
|
||||
|
||||
connect(&_entityCollisionSystem, &EntityCollisionSystem::entityCollisionWithEntity,
|
||||
&_entities, &EntityTreeRenderer::entityCollisionWithEntity);
|
||||
|
||||
// connect the _entities (EntityTreeRenderer) to our script engine's EntityScriptingInterface for firing
|
||||
// of events related clicking, hovering over, and entering entities
|
||||
_entities.connectSignalsToSlots(ScriptEngine::getEntityScriptingInterface());
|
||||
|
@ -2077,11 +2114,13 @@ void Application::updateMouseRay() {
|
|||
// if the mouse pointer isn't visible, act like it's at the center of the screen
|
||||
float x = 0.5f, y = 0.5f;
|
||||
if (!_mouseHidden) {
|
||||
x = _mouseX / (float)_glWidget->width();
|
||||
y = _mouseY / (float)_glWidget->height();
|
||||
x = getTrueMouseX() / (float)_glWidget->width();
|
||||
y = getTrueMouseY() / (float)_glWidget->height();
|
||||
}
|
||||
_viewFrustum.computePickRay(x, y, _mouseRayOrigin, _mouseRayDirection);
|
||||
|
||||
PickRay pickRay = _myCamera.computeViewPickRay(x, y);
|
||||
_mouseRayOrigin = pickRay.origin;
|
||||
_mouseRayDirection = pickRay.direction;
|
||||
|
||||
// adjust for mirroring
|
||||
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||
glm::vec3 mouseRayOffset = _mouseRayOrigin - _viewFrustum.getPosition();
|
||||
|
@ -2310,7 +2349,18 @@ void Application::update(float deltaTime) {
|
|||
_prioVR.update(deltaTime);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static QCursor cursor;
|
||||
if (OculusManager::isConnected() &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)){
|
||||
if (_window->cursor().shape() != Qt::BlankCursor) {
|
||||
cursor = _window->cursor();
|
||||
_window->setCursor(QCursor(Qt::BlankCursor));
|
||||
}
|
||||
} else if(_window->cursor().shape() == Qt::BlankCursor) {
|
||||
_window->setCursor(cursor);
|
||||
}
|
||||
|
||||
// Dispatch input events
|
||||
_controllerScriptingInterface.updateInputControllers();
|
||||
|
||||
|
@ -2910,7 +2960,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr
|
|||
// transform by eye offset
|
||||
|
||||
// load the view frustum
|
||||
loadViewFrustum(whichCamera, _viewFrustum);
|
||||
loadViewFrustum(whichCamera, _displayViewFrustum);
|
||||
|
||||
// flip x if in mirror mode (also requires reversing winding order for backface culling)
|
||||
if (whichCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||
|
@ -3184,7 +3234,7 @@ void Application::computeOffAxisFrustum(float& left, float& right, float& bottom
|
|||
float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
|
||||
|
||||
// allow 3DTV/Oculus to override parameters from camera
|
||||
_viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
||||
_displayViewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
||||
if (OculusManager::isConnected()) {
|
||||
OculusManager::overrideOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
||||
|
||||
|
@ -3513,9 +3563,6 @@ void Application::deleteVoxelAt(const VoxelDetail& voxel) {
|
|||
}
|
||||
|
||||
void Application::resetSensors() {
|
||||
_mouseX = _glWidget->width() / 2;
|
||||
_mouseY = _glWidget->height() / 2;
|
||||
|
||||
_faceshift.reset();
|
||||
_visage.reset();
|
||||
_dde.reset();
|
||||
|
@ -3528,7 +3575,7 @@ void Application::resetSensors() {
|
|||
QScreen* currentScreen = _window->windowHandle()->screen();
|
||||
QWindow* mainWindow = _window->windowHandle();
|
||||
QPoint windowCenter = mainWindow->geometry().center();
|
||||
QCursor::setPos(currentScreen, windowCenter);
|
||||
_glWidget->cursor().setPos(currentScreen, windowCenter);
|
||||
|
||||
_myAvatar->reset();
|
||||
|
||||
|
|
|
@ -196,6 +196,7 @@ public:
|
|||
const AudioReflector* getAudioReflector() const { return &_audioReflector; }
|
||||
Camera* getCamera() { return &_myCamera; }
|
||||
ViewFrustum* getViewFrustum() { return &_viewFrustum; }
|
||||
ViewFrustum* getDisplayViewFrustum() { return &_displayViewFrustum; }
|
||||
ViewFrustum* getShadowViewFrustum() { return &_shadowViewFrustum; }
|
||||
VoxelImporter* getVoxelImporter() { return &_voxelImporter; }
|
||||
VoxelSystem* getVoxels() { return &_voxels; }
|
||||
|
@ -213,8 +214,15 @@ public:
|
|||
bool isMouseHidden() const { return _mouseHidden; }
|
||||
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
|
||||
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
||||
int getMouseX() const { return _mouseX; }
|
||||
int getMouseY() const { return _mouseY; }
|
||||
bool mouseOnScreen() const;
|
||||
int getMouseX() const;
|
||||
int getMouseY() const;
|
||||
int getTrueMouseX() const { return _glWidget->mapFromGlobal(QCursor::pos()).x(); }
|
||||
int getTrueMouseY() const { return _glWidget->mapFromGlobal(QCursor::pos()).y(); }
|
||||
int getMouseDragStartedX() const;
|
||||
int getMouseDragStartedY() const;
|
||||
int getTrueMouseDragStartedX() const { return _mouseDragStartedX; }
|
||||
int getTrueMouseDragStartedY() const { return _mouseDragStartedY; }
|
||||
bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated;; }
|
||||
Faceshift* getFaceshift() { return &_faceshift; }
|
||||
Visage* getVisage() { return &_visage; }
|
||||
|
@ -517,6 +525,7 @@ private:
|
|||
|
||||
ViewFrustum _viewFrustum; // current state of view frustum, perspective, orientation, etc.
|
||||
ViewFrustum _lastQueriedViewFrustum; /// last view frustum used to query octree servers (voxels)
|
||||
ViewFrustum _displayViewFrustum;
|
||||
ViewFrustum _shadowViewFrustum;
|
||||
quint64 _lastQueriedTime;
|
||||
|
||||
|
@ -554,8 +563,6 @@ private:
|
|||
|
||||
Environment _environment;
|
||||
|
||||
int _mouseX;
|
||||
int _mouseY;
|
||||
int _mouseDragStartedX;
|
||||
int _mouseDragStartedY;
|
||||
quint64 _lastMouseMove;
|
||||
|
|
|
@ -97,20 +97,17 @@ void Camera::setFarClip(float f) {
|
|||
PickRay Camera::computePickRay(float x, float y) {
|
||||
float screenWidth = Application::getInstance()->getGLWidget()->width();
|
||||
float screenHeight = Application::getInstance()->getGLWidget()->height();
|
||||
PickRay result;
|
||||
if (OculusManager::isConnected()) {
|
||||
result.origin = getPosition();
|
||||
Application::getInstance()->getApplicationOverlay().computeOculusPickRay(x / screenWidth, y / screenHeight, result.direction);
|
||||
} else {
|
||||
Application::getInstance()->getViewFrustum()->computePickRay(x / screenWidth, y / screenHeight,
|
||||
result.origin, result.direction);
|
||||
}
|
||||
return result;
|
||||
|
||||
return computeViewPickRay(x / screenWidth, y / screenHeight);
|
||||
}
|
||||
|
||||
PickRay Camera::computeViewPickRay(float xRatio, float yRatio) {
|
||||
PickRay result;
|
||||
Application::getInstance()->getViewFrustum()->computePickRay(xRatio, yRatio, result.origin, result.direction);
|
||||
if (OculusManager::isConnected()) {
|
||||
Application::getInstance()->getApplicationOverlay().computeOculusPickRay(xRatio, yRatio, result.origin, result.direction);
|
||||
} else {
|
||||
Application::getInstance()->getViewFrustum()->computePickRay(xRatio, yRatio, result.origin, result.direction);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -367,6 +367,7 @@ namespace MenuOption {
|
|||
const QString DontCullTooSmallMeshParts = "Don't Cull Too Small Mesh Parts";
|
||||
const QString DontReduceMaterialSwitches = "Don't Attempt to Reduce Material Switches";
|
||||
const QString DontRenderEntitiesAsScene = "Don't Render Entities as Scene";
|
||||
const QString DontDoPrecisionPicking = "Don't Do Precision Picking";
|
||||
const QString DecreaseAvatarSize = "Decrease Avatar Size";
|
||||
const QString DecreaseVoxelSize = "Decrease Voxel Size";
|
||||
const QString DisableActivityLogger = "Disable Activity Logger";
|
||||
|
@ -378,6 +379,7 @@ namespace MenuOption {
|
|||
const QString DisplayHandTargets = "Show Hand Targets";
|
||||
const QString DisplayHermiteData = "Display Hermite Data";
|
||||
const QString DisplayModelBounds = "Display Model Bounds";
|
||||
const QString DisplayModelTriangles = "Display Model Triangles";
|
||||
const QString DisplayModelElementChildProxies = "Display Model Element Children";
|
||||
const QString DisplayModelElementProxy = "Display Model Element Bounds";
|
||||
const QString DisplayTimingDetails = "Display Timing Details";
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <glm/gtx/transform.hpp>
|
||||
|
||||
#include <GeometryUtil.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include <MetavoxelMessages.h>
|
||||
|
@ -192,7 +193,7 @@ static const float EIGHT_BIT_MAXIMUM_RECIPROCAL = 1.0f / EIGHT_BIT_MAXIMUM;
|
|||
|
||||
void MetavoxelSystem::render() {
|
||||
// update the frustum
|
||||
ViewFrustum* viewFrustum = Application::getInstance()->getViewFrustum();
|
||||
ViewFrustum* viewFrustum = Application::getInstance()->getDisplayViewFrustum();
|
||||
_frustum.set(viewFrustum->getFarTopLeft(), viewFrustum->getFarTopRight(), viewFrustum->getFarBottomLeft(),
|
||||
viewFrustum->getFarBottomRight(), viewFrustum->getNearTopLeft(), viewFrustum->getNearTopRight(),
|
||||
viewFrustum->getNearBottomLeft(), viewFrustum->getNearBottomRight());
|
||||
|
@ -1095,30 +1096,6 @@ VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>
|
|||
_materials(materials) {
|
||||
}
|
||||
|
||||
static bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance) {
|
||||
glm::vec3 firstSide = v0 - v1;
|
||||
glm::vec3 secondSide = v2 - v1;
|
||||
glm::vec3 normal = glm::cross(secondSide, firstSide);
|
||||
float dividend = glm::dot(normal, v1) - glm::dot(origin, normal);
|
||||
if (dividend > 0.0f) {
|
||||
return false; // origin below plane
|
||||
}
|
||||
float divisor = glm::dot(normal, direction);
|
||||
if (divisor > -EPSILON) {
|
||||
return false;
|
||||
}
|
||||
float t = dividend / divisor;
|
||||
glm::vec3 point = origin + direction * t;
|
||||
if (glm::dot(normal, glm::cross(point - v1, firstSide)) > 0.0f &&
|
||||
glm::dot(normal, glm::cross(secondSide, point - v1)) > 0.0f &&
|
||||
glm::dot(normal, glm::cross(point - v0, v2 - v0)) > 0.0f) {
|
||||
distance = t;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,
|
||||
const glm::vec3& direction, float& distance) const {
|
||||
float highest = _size - 1.0f;
|
||||
|
@ -1953,7 +1930,7 @@ private:
|
|||
|
||||
BufferRenderVisitor::BufferRenderVisitor(const AttributePointer& attribute) :
|
||||
MetavoxelVisitor(QVector<AttributePointer>() << attribute),
|
||||
_order(encodeOrder(Application::getInstance()->getViewFrustum()->getDirection())),
|
||||
_order(encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())),
|
||||
_containmentDepth(INT_MAX) {
|
||||
}
|
||||
|
||||
|
|
|
@ -540,8 +540,6 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) {
|
|||
//a magnification window was clicked on
|
||||
int clickX = pos.x();
|
||||
int clickY = pos.y();
|
||||
//Checks for magnification window click
|
||||
application->getApplicationOverlay().getClickLocation(clickX, clickY);
|
||||
//Set pos to the new click location, which may be the same if no magnification window is open
|
||||
pos.setX(clickX);
|
||||
pos.setY(clickY);
|
||||
|
|
|
@ -151,12 +151,19 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
|||
return QScriptValue(); // no entity...
|
||||
}
|
||||
|
||||
// NOTE: we keep local variables for the entityID and the script because
|
||||
// below in loadScriptContents() it's possible for us to execute the
|
||||
// application event loop, which may cause our entity to be deleted on
|
||||
// us. We don't really need access the entity after this point, can
|
||||
// can accomplish all we need to here with just the script "text" and the ID.
|
||||
EntityItemID entityID = entity->getEntityItemID();
|
||||
QString entityScript = entity->getScript();
|
||||
|
||||
if (_entityScripts.contains(entityID)) {
|
||||
EntityScriptDetails details = _entityScripts[entityID];
|
||||
|
||||
// check to make sure our script text hasn't changed on us since we last loaded it
|
||||
if (details.scriptText == entity->getScript()) {
|
||||
if (details.scriptText == entityScript) {
|
||||
return details.scriptObject; // previously loaded
|
||||
}
|
||||
|
||||
|
@ -164,18 +171,18 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
|||
// has changed and so we need to reload it.
|
||||
_entityScripts.remove(entityID);
|
||||
}
|
||||
if (entity->getScript().isEmpty()) {
|
||||
if (entityScript.isEmpty()) {
|
||||
return QScriptValue(); // no script
|
||||
}
|
||||
|
||||
QString scriptContents = loadScriptContents(entity->getScript());
|
||||
QString scriptContents = loadScriptContents(entityScript);
|
||||
|
||||
QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(scriptContents);
|
||||
if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
|
||||
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
|
||||
qDebug() << " " << syntaxCheck.errorMessage() << ":"
|
||||
<< syntaxCheck.errorLineNumber() << syntaxCheck.errorColumnNumber();
|
||||
qDebug() << " SCRIPT:" << entity->getScript();
|
||||
qDebug() << " SCRIPT:" << entityScript;
|
||||
return QScriptValue(); // invalid script
|
||||
}
|
||||
|
||||
|
@ -184,12 +191,12 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
|||
if (!entityScriptConstructor.isFunction()) {
|
||||
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
|
||||
qDebug() << " NOT CONSTRUCTOR";
|
||||
qDebug() << " SCRIPT:" << entity->getScript();
|
||||
qDebug() << " SCRIPT:" << entityScript;
|
||||
return QScriptValue(); // invalid script
|
||||
}
|
||||
|
||||
QScriptValue entityScriptObject = entityScriptConstructor.construct();
|
||||
EntityScriptDetails newDetails = { entity->getScript(), entityScriptObject };
|
||||
EntityScriptDetails newDetails = { entityScript, entityScriptObject };
|
||||
_entityScripts[entityID] = newDetails;
|
||||
|
||||
return entityScriptObject; // newly constructed
|
||||
|
@ -233,7 +240,7 @@ void EntityTreeRenderer::update() {
|
|||
|
||||
void EntityTreeRenderer::checkEnterLeaveEntities() {
|
||||
if (_tree) {
|
||||
_tree->lockForRead();
|
||||
_tree->lockForWrite(); // so that our scripts can do edits if they want
|
||||
glm::vec3 avatarPosition = Application::getInstance()->getAvatar()->getPosition() / (float) TREE_SCALE;
|
||||
|
||||
if (avatarPosition != _lastAvatarPosition) {
|
||||
|
@ -635,22 +642,12 @@ void EntityTreeRenderer::deleteReleasedModels() {
|
|||
}
|
||||
|
||||
PickRay EntityTreeRenderer::computePickRay(float x, float y) {
|
||||
float screenWidth = Application::getInstance()->getGLWidget()->width();
|
||||
float screenHeight = Application::getInstance()->getGLWidget()->height();
|
||||
PickRay result;
|
||||
if (OculusManager::isConnected()) {
|
||||
Camera* camera = Application::getInstance()->getCamera();
|
||||
result.origin = camera->getPosition();
|
||||
Application::getInstance()->getApplicationOverlay().computeOculusPickRay(x / screenWidth, y / screenHeight, result.direction);
|
||||
} else {
|
||||
ViewFrustum* viewFrustum = Application::getInstance()->getViewFrustum();
|
||||
viewFrustum->computePickRay(x / screenWidth, y / screenHeight, result.origin, result.direction);
|
||||
}
|
||||
return result;
|
||||
return Application::getInstance()->getCamera()->computePickRay(x, y);
|
||||
}
|
||||
|
||||
|
||||
RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType) {
|
||||
RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
||||
bool precisionPicking) {
|
||||
RayToEntityIntersectionResult result;
|
||||
if (_tree) {
|
||||
EntityTree* entityTree = static_cast<EntityTree*>(_tree);
|
||||
|
@ -658,7 +655,8 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons
|
|||
OctreeElement* element;
|
||||
EntityItem* intersectedEntity = NULL;
|
||||
result.intersects = entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
|
||||
(void**)&intersectedEntity, lockType, &result.accurate);
|
||||
(void**)&intersectedEntity, lockType, &result.accurate,
|
||||
precisionPicking);
|
||||
if (result.intersects && intersectedEntity) {
|
||||
result.entityID = intersectedEntity->getEntityItemID();
|
||||
result.properties = intersectedEntity->getProperties();
|
||||
|
@ -710,7 +708,9 @@ QScriptValueList EntityTreeRenderer::createEntityArgs(const EntityItemID& entity
|
|||
void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
PerformanceTimer perfTimer("EntityTreeRenderer::mousePressEvent");
|
||||
PickRay ray = computePickRay(event->x(), event->y());
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock);
|
||||
|
||||
bool precisionPicking = !Menu::getInstance()->isOptionChecked(MenuOption::DontDoPrecisionPicking);
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
|
||||
if (rayPickResult.intersects) {
|
||||
//qDebug() << "mousePressEvent over entity:" << rayPickResult.entityID;
|
||||
emit mousePressOnEntity(rayPickResult.entityID, MouseEvent(*event, deviceID));
|
||||
|
@ -734,7 +734,8 @@ void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int device
|
|||
void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
PerformanceTimer perfTimer("EntityTreeRenderer::mouseReleaseEvent");
|
||||
PickRay ray = computePickRay(event->x(), event->y());
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock);
|
||||
bool precisionPicking = !Menu::getInstance()->isOptionChecked(MenuOption::DontDoPrecisionPicking);
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
|
||||
if (rayPickResult.intersects) {
|
||||
//qDebug() << "mouseReleaseEvent over entity:" << rayPickResult.entityID;
|
||||
emit mouseReleaseOnEntity(rayPickResult.entityID, MouseEvent(*event, deviceID));
|
||||
|
@ -768,7 +769,9 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
|
|||
PerformanceTimer perfTimer("EntityTreeRenderer::mouseMoveEvent");
|
||||
|
||||
PickRay ray = computePickRay(event->x(), event->y());
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::TryLock);
|
||||
|
||||
bool precisionPicking = false; // for mouse moves we do not do precision picking
|
||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::TryLock, precisionPicking);
|
||||
if (rayPickResult.intersects) {
|
||||
QScriptValueList entityScriptArgs = createMouseEventArgs(rayPickResult.entityID, event, deviceID);
|
||||
|
||||
|
@ -888,3 +891,35 @@ void EntityTreeRenderer::changingEntityID(const EntityItemID& oldEntityID, const
|
|||
}
|
||||
}
|
||||
|
||||
void EntityTreeRenderer::entityCollisionWithVoxel(const EntityItemID& entityID, const VoxelDetail& voxel,
|
||||
const Collision& collision) {
|
||||
QScriptValue entityScript = getPreviouslyLoadedEntityScript(entityID);
|
||||
if (entityScript.property("collisionWithVoxel").isValid()) {
|
||||
QScriptValueList args;
|
||||
args << entityID.toScriptValue(_entitiesScriptEngine);
|
||||
args << collisionToScriptValue(_entitiesScriptEngine, collision);
|
||||
entityScript.property("collisionWithVoxel").call(entityScript, args);
|
||||
}
|
||||
}
|
||||
|
||||
void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB,
|
||||
const Collision& collision) {
|
||||
QScriptValue entityScriptA = loadEntityScript(idA);
|
||||
if (entityScriptA.property("collisionWithEntity").isValid()) {
|
||||
QScriptValueList args;
|
||||
args << idA.toScriptValue(_entitiesScriptEngine);
|
||||
args << idB.toScriptValue(_entitiesScriptEngine);
|
||||
args << collisionToScriptValue(_entitiesScriptEngine, collision);
|
||||
entityScriptA.property("collisionWithEntity").call(entityScriptA, args);
|
||||
}
|
||||
|
||||
QScriptValue entityScriptB = loadEntityScript(idB);
|
||||
if (entityScriptB.property("collisionWithEntity").isValid()) {
|
||||
QScriptValueList args;
|
||||
args << idB.toScriptValue(_entitiesScriptEngine);
|
||||
args << idA.toScriptValue(_entitiesScriptEngine);
|
||||
args << collisionToScriptValue(_entitiesScriptEngine, collision);
|
||||
entityScriptB.property("collisionWithEntity").call(entityScriptA, args);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,6 +106,9 @@ public slots:
|
|||
void deletingEntity(const EntityItemID& entityID);
|
||||
void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID);
|
||||
void entitySciptChanging(const EntityItemID& entityID);
|
||||
void entityCollisionWithVoxel(const EntityItemID& entityID, const VoxelDetail& voxel, const Collision& collision);
|
||||
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
||||
|
||||
|
||||
protected:
|
||||
virtual Octree* createTree() { return new EntityTree(true); }
|
||||
|
@ -117,7 +120,8 @@ private:
|
|||
QList<Model*> _releasedModels;
|
||||
void renderProxies(const EntityItem* entity, RenderArgs* args);
|
||||
PickRay computePickRay(float x, float y);
|
||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType);
|
||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
||||
bool precisionPicking);
|
||||
|
||||
EntityItemID _currentHoverOverEntityID;
|
||||
EntityItemID _currentClickingOnEntityID;
|
||||
|
|
|
@ -93,7 +93,7 @@ void RenderableLightEntityItem::render(RenderArgs* args) {
|
|||
|
||||
bool RenderableLightEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const {
|
||||
void** intersectedObject, bool precisionPicking) const {
|
||||
|
||||
// TODO: this isn't really correct because we don't know if we actually live in the main tree of the applications's
|
||||
// EntityTreeRenderer. But we probably do. Technically we could be on the clipboard and someone might be trying to
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const;
|
||||
void** intersectedObject, bool precisionPicking) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
|||
}
|
||||
|
||||
glm::quat rotation = getRotation();
|
||||
if (needsSimulation() && _model->isActive()) {
|
||||
if (needsToCallUpdate() && _model->isActive()) {
|
||||
_model->setScaleToFit(true, dimensions);
|
||||
_model->setSnapModelToRegistrationPoint(true, getRegistrationPoint());
|
||||
_model->setRotation(rotation);
|
||||
|
@ -173,10 +173,18 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
|||
// is significantly more expensive. Is there a way to call this that doesn't cost us as much?
|
||||
PerformanceTimer perfTimer("model->render");
|
||||
bool dontRenderAsScene = Menu::getInstance()->isOptionChecked(MenuOption::DontRenderEntitiesAsScene);
|
||||
if (dontRenderAsScene) {
|
||||
_model->render(alpha, modelRenderMode, args);
|
||||
} else {
|
||||
_model->renderInScene(alpha, args);
|
||||
bool displayModelTriangles = Menu::getInstance()->isOptionChecked(MenuOption::DisplayModelTriangles);
|
||||
bool rendered = false;
|
||||
if (displayModelTriangles) {
|
||||
rendered = _model->renderTriangleProxies();
|
||||
}
|
||||
|
||||
if (!rendered) {
|
||||
if (dontRenderAsScene) {
|
||||
_model->render(alpha, modelRenderMode, args);
|
||||
} else {
|
||||
_model->renderInScene(alpha, args);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if we couldn't get a model, then just draw a cube
|
||||
|
@ -245,8 +253,8 @@ Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) {
|
|||
return result;
|
||||
}
|
||||
|
||||
bool RenderableModelEntityItem::needsSimulation() const {
|
||||
return _needsInitialSimulation || getSimulationState() == EntityItem::Moving;
|
||||
bool RenderableModelEntityItem::needsToCallUpdate() const {
|
||||
return _needsInitialSimulation || ModelEntityItem::needsToCallUpdate();
|
||||
}
|
||||
|
||||
EntityItemProperties RenderableModelEntityItem::getProperties() const {
|
||||
|
@ -257,7 +265,29 @@ EntityItemProperties RenderableModelEntityItem::getProperties() const {
|
|||
return properties;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RenderableModelEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject, bool precisionPicking) const {
|
||||
if (!_model) {
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::vec3 originInMeters = origin * (float)TREE_SCALE;
|
||||
QString extraInfo;
|
||||
float localDistance;
|
||||
|
||||
//qDebug() << "RenderableModelEntityItem::findDetailedRayIntersection() precisionPicking:" << precisionPicking;
|
||||
|
||||
bool intersectsModel = _model->findRayIntersectionAgainstSubMeshes(originInMeters, direction,
|
||||
localDistance, face, extraInfo, precisionPicking);
|
||||
|
||||
if (intersectsModel) {
|
||||
// NOTE: findRayIntersectionAgainstSubMeshes() does work in meters, but we're expected to return
|
||||
// results in tree scale.
|
||||
distance = localDistance / (float)TREE_SCALE;
|
||||
}
|
||||
|
||||
return intersectsModel; // we only got here if we intersected our non-aabox
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,10 +51,17 @@ public:
|
|||
virtual void somethingChangedNotification() { _needsInitialSimulation = true; }
|
||||
|
||||
virtual void render(RenderArgs* args);
|
||||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject, bool precisionPicking) const;
|
||||
|
||||
Model* getModel(EntityTreeRenderer* renderer);
|
||||
|
||||
bool needsToCallUpdate() const;
|
||||
|
||||
private:
|
||||
void remapTextures();
|
||||
bool needsSimulation() const;
|
||||
|
||||
Model* _model;
|
||||
bool _needsInitialSimulation;
|
||||
|
|
|
@ -232,8 +232,8 @@ void DeferredLightingEffect::render() {
|
|||
// enlarge the scales slightly to account for tesselation
|
||||
const float SCALE_EXPANSION = 0.05f;
|
||||
|
||||
const glm::vec3& eyePoint = Application::getInstance()->getViewFrustum()->getPosition();
|
||||
float nearRadius = glm::distance(eyePoint, Application::getInstance()->getViewFrustum()->getNearTopLeft());
|
||||
const glm::vec3& eyePoint = Application::getInstance()->getDisplayViewFrustum()->getPosition();
|
||||
float nearRadius = glm::distance(eyePoint, Application::getInstance()->getDisplayViewFrustum()->getNearTopLeft());
|
||||
|
||||
if (!_pointLights.isEmpty()) {
|
||||
_pointLight.bind();
|
||||
|
|
|
@ -54,6 +54,7 @@ Model::Model(QObject* parent) :
|
|||
_blendNumber(0),
|
||||
_appliedBlendNumber(0),
|
||||
_calculatedMeshBoxesValid(false),
|
||||
_calculatedMeshTrianglesValid(false),
|
||||
_meshGroupsKnown(false) {
|
||||
|
||||
// we may have been created in the network thread, but we live in the main thread
|
||||
|
@ -269,7 +270,7 @@ void Model::init() {
|
|||
_program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/model.vert");
|
||||
_program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/model.frag");
|
||||
_program.link();
|
||||
|
||||
|
||||
initProgram(_program, _locations);
|
||||
|
||||
_normalMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||
|
@ -515,8 +516,61 @@ void Model::setJointStates(QVector<JointState> states) {
|
|||
_boundingRadius = radius;
|
||||
}
|
||||
|
||||
bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const {
|
||||
bool Model::renderTriangleProxies() {
|
||||
if (!isActive()) {
|
||||
return false;
|
||||
}
|
||||
if (_calculatedMeshTrianglesValid) {
|
||||
int color = 0;
|
||||
foreach (const QVector<Triangle>& meshTriangles, _calculatedMeshTriangles) {
|
||||
switch(color) {
|
||||
case 0: glColor3ub( 0, 0, 255); break;
|
||||
case 1: glColor3ub( 0, 255, 0); break;
|
||||
case 2: glColor3ub( 0, 255, 255); break;
|
||||
case 3: glColor3ub(255, 0, 0); break;
|
||||
case 4: glColor3ub(255, 0, 255); break;
|
||||
case 5: glColor3ub(255, 255, 0); break;
|
||||
case 6: glColor3ub( 0, 0, 128); break;
|
||||
case 7: glColor3ub( 0, 128, 0); break;
|
||||
case 8: glColor3ub( 0, 128, 128); break;
|
||||
case 9: glColor3ub(128, 0, 0); break;
|
||||
case 10: glColor3ub(128, 0, 128); break;
|
||||
case 11: glColor3ub(128, 128, 0); break;
|
||||
case 12: glColor3ub(128, 128, 255); break;
|
||||
case 13: glColor3ub(128, 255, 128); break;
|
||||
case 14: glColor3ub(128, 255, 255); break;
|
||||
case 15: glColor3ub(255, 128, 128); break;
|
||||
case 16: glColor3ub(255, 128, 255); break;
|
||||
case 17: glColor3ub(255, 255, 128); break;
|
||||
default: glColor3ub(255,255, 255); break;
|
||||
}
|
||||
|
||||
if (_calculatedMeshBoxes.size() > color) {
|
||||
const AABox& box = _calculatedMeshBoxes[color];
|
||||
glm::vec3 center = box.calcCenter();
|
||||
glm::vec3 dimensions = box.getDimensions();
|
||||
glPushMatrix();
|
||||
glTranslatef(center.x, center.y, center.z);
|
||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||
Application::getInstance()->getDeferredLightingEffect()->renderWireCube(1.0f);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
foreach (const Triangle& triangle, meshTriangles) {
|
||||
glVertex3f( triangle.v0.x, triangle.v0.y, triangle.v0.z);
|
||||
glVertex3f( triangle.v1.x, triangle.v1.y, triangle.v1.z);
|
||||
glVertex3f( triangle.v2.x, triangle.v2.y, triangle.v2.z);
|
||||
}
|
||||
glEnd();
|
||||
color++;
|
||||
}
|
||||
}
|
||||
return _calculatedMeshTrianglesValid;
|
||||
}
|
||||
|
||||
bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance,
|
||||
BoxFace& face, QString& extraInfo, bool pickAgainstTriangles) {
|
||||
|
||||
bool intersectedSomething = false;
|
||||
|
||||
|
@ -524,7 +578,7 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
|||
if (!isActive()) {
|
||||
return intersectedSomething;
|
||||
}
|
||||
|
||||
|
||||
// extents is the entity relative, scaled, centered extents of the entity
|
||||
glm::vec3 position = _translation;
|
||||
glm::mat4 rotation = glm::mat4_cast(_rotation);
|
||||
|
@ -535,35 +589,70 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
|||
Extents modelExtents = getMeshExtents(); // NOTE: unrotated
|
||||
|
||||
glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum;
|
||||
glm::vec3 corner = dimensions * -0.5f; // since we're going to do the ray picking in the model frame of reference
|
||||
AABox overlayFrameBox(corner, dimensions);
|
||||
glm::vec3 corner = -(dimensions * _registrationPoint); // since we're going to do the ray picking in the model frame of reference
|
||||
AABox modelFrameBox(corner, dimensions);
|
||||
|
||||
glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));
|
||||
glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f));
|
||||
|
||||
// we can use the AABox's ray intersection by mapping our origin and direction into the model frame
|
||||
// and testing intersection there.
|
||||
if (overlayFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) {
|
||||
if (modelFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) {
|
||||
|
||||
float bestDistance = std::numeric_limits<float>::max();
|
||||
float bestTriangleDistance = std::numeric_limits<float>::max();
|
||||
bool someTriangleHit = false;
|
||||
|
||||
float distanceToSubMesh;
|
||||
BoxFace subMeshFace;
|
||||
int subMeshIndex = 0;
|
||||
|
||||
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
|
||||
// If we hit the models box, then consider the submeshes...
|
||||
foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
|
||||
if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {
|
||||
if (distanceToSubMesh < bestDistance) {
|
||||
bestDistance = distanceToSubMesh;
|
||||
intersectedSomething = true;
|
||||
face = subMeshFace;
|
||||
extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
|
||||
if (pickAgainstTriangles) {
|
||||
someTriangleHit = false;
|
||||
if (!_calculatedMeshTrianglesValid) {
|
||||
recalculateMeshBoxes(pickAgainstTriangles);
|
||||
}
|
||||
// check our triangles here....
|
||||
const QVector<Triangle>& meshTriangles = _calculatedMeshTriangles[subMeshIndex];
|
||||
int t = 0;
|
||||
foreach (const Triangle& triangle, meshTriangles) {
|
||||
t++;
|
||||
|
||||
float thisTriangleDistance;
|
||||
if (findRayTriangleIntersection(origin, direction, triangle, thisTriangleDistance)) {
|
||||
if (thisTriangleDistance < bestDistance) {
|
||||
bestTriangleDistance = thisTriangleDistance;
|
||||
someTriangleHit = true;
|
||||
|
||||
bestDistance = thisTriangleDistance;
|
||||
intersectedSomething = true;
|
||||
face = subMeshFace;
|
||||
extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// this is the non-triangle picking case...
|
||||
bestDistance = distanceToSubMesh;
|
||||
intersectedSomething = true;
|
||||
face = subMeshFace;
|
||||
extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
subMeshIndex++;
|
||||
}
|
||||
|
||||
if (intersectedSomething) {
|
||||
distance = bestDistance;
|
||||
}
|
||||
|
||||
return intersectedSomething;
|
||||
}
|
||||
|
@ -571,18 +660,81 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
|||
return intersectedSomething;
|
||||
}
|
||||
|
||||
void Model::recalcuateMeshBoxes() {
|
||||
if (!_calculatedMeshBoxesValid) {
|
||||
// TODO: we seem to call this too often when things haven't actually changed... look into optimizing this
|
||||
void Model::recalculateMeshBoxes(bool pickAgainstTriangles) {
|
||||
bool calculatedMeshTrianglesNeeded = pickAgainstTriangles && !_calculatedMeshTrianglesValid;
|
||||
|
||||
if (!_calculatedMeshBoxesValid || calculatedMeshTrianglesNeeded) {
|
||||
PerformanceTimer perfTimer("calculatedMeshBoxes");
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
int numberOfMeshes = geometry.meshes.size();
|
||||
_calculatedMeshBoxes.resize(numberOfMeshes);
|
||||
_calculatedMeshTriangles.clear();
|
||||
_calculatedMeshTriangles.resize(numberOfMeshes);
|
||||
for (int i = 0; i < numberOfMeshes; i++) {
|
||||
const FBXMesh& mesh = geometry.meshes.at(i);
|
||||
Extents scaledMeshExtents = calculateScaledOffsetExtents(mesh.meshExtents);
|
||||
|
||||
_calculatedMeshBoxes[i] = AABox(scaledMeshExtents);
|
||||
|
||||
if (pickAgainstTriangles) {
|
||||
QVector<Triangle> thisMeshTriangles;
|
||||
for (int j = 0; j < mesh.parts.size(); j++) {
|
||||
const FBXMeshPart& part = mesh.parts.at(j);
|
||||
|
||||
const int INDICES_PER_TRIANGLE = 3;
|
||||
const int INDICES_PER_QUAD = 4;
|
||||
|
||||
if (part.quadIndices.size() > 0) {
|
||||
int numberOfQuads = part.quadIndices.size() / INDICES_PER_QUAD;
|
||||
int vIndex = 0;
|
||||
for (int q = 0; q < numberOfQuads; q++) {
|
||||
int i0 = part.quadIndices[vIndex++];
|
||||
int i1 = part.quadIndices[vIndex++];
|
||||
int i2 = part.quadIndices[vIndex++];
|
||||
int i3 = part.quadIndices[vIndex++];
|
||||
|
||||
glm::vec3 v0 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i0], 1.0f)));
|
||||
glm::vec3 v1 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i1], 1.0f)));
|
||||
glm::vec3 v2 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i2], 1.0f)));
|
||||
glm::vec3 v3 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i3], 1.0f)));
|
||||
|
||||
// Sam's recommended triangle slices
|
||||
Triangle tri1 = { v0, v1, v3 };
|
||||
Triangle tri2 = { v1, v2, v3 };
|
||||
|
||||
// NOTE: Random guy on the internet's recommended triangle slices
|
||||
//Triangle tri1 = { v0, v1, v2 };
|
||||
//Triangle tri2 = { v2, v3, v0 };
|
||||
|
||||
thisMeshTriangles.push_back(tri1);
|
||||
thisMeshTriangles.push_back(tri2);
|
||||
}
|
||||
}
|
||||
|
||||
if (part.triangleIndices.size() > 0) {
|
||||
int numberOfTris = part.triangleIndices.size() / INDICES_PER_TRIANGLE;
|
||||
int vIndex = 0;
|
||||
for (int t = 0; t < numberOfTris; t++) {
|
||||
int i0 = part.triangleIndices[vIndex++];
|
||||
int i1 = part.triangleIndices[vIndex++];
|
||||
int i2 = part.triangleIndices[vIndex++];
|
||||
|
||||
glm::vec3 v0 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i0], 1.0f)));
|
||||
glm::vec3 v1 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i1], 1.0f)));
|
||||
glm::vec3 v2 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i2], 1.0f)));
|
||||
|
||||
Triangle tri = { v0, v1, v2 };
|
||||
|
||||
thisMeshTriangles.push_back(tri);
|
||||
}
|
||||
}
|
||||
}
|
||||
_calculatedMeshTriangles[i] = thisMeshTriangles;
|
||||
}
|
||||
}
|
||||
_calculatedMeshBoxesValid = true;
|
||||
_calculatedMeshTrianglesValid = pickAgainstTriangles;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -592,7 +744,7 @@ void Model::renderSetup(RenderArgs* args) {
|
|||
// against. We cache the results of these calculations so long as the model hasn't been
|
||||
// simulated and the mesh hasn't changed.
|
||||
if (args && !_calculatedMeshBoxesValid) {
|
||||
recalcuateMeshBoxes();
|
||||
recalculateMeshBoxes();
|
||||
}
|
||||
|
||||
// set up dilated textures on first render after load/simulate
|
||||
|
@ -844,6 +996,15 @@ Extents Model::calculateScaledOffsetExtents(const Extents& extents) const {
|
|||
return translatedExtents;
|
||||
}
|
||||
|
||||
glm::vec3 Model::calculateScaledOffsetPoint(const glm::vec3& point) const {
|
||||
// we need to include any fst scaling, translation, and rotation, which is captured in the offset matrix
|
||||
glm::vec3 offsetPoint = glm::vec3(_geometry->getFBXGeometry().offset * glm::vec4(point, 1.0f));
|
||||
glm::vec3 scaledPoint = ((offsetPoint + _offset) * _scale);
|
||||
glm::vec3 rotatedPoint = _rotation * scaledPoint;
|
||||
glm::vec3 translatedPoint = rotatedPoint + _translation;
|
||||
return translatedPoint;
|
||||
}
|
||||
|
||||
|
||||
bool Model::getJointState(int index, glm::quat& rotation) const {
|
||||
if (index == -1 || index >= _jointStates.size()) {
|
||||
|
@ -1142,6 +1303,7 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
|
|||
|
||||
if (isActive() && fullUpdate) {
|
||||
_calculatedMeshBoxesValid = false; // if we have to simulate, we need to assume our mesh boxes are all invalid
|
||||
_calculatedMeshTrianglesValid = false;
|
||||
|
||||
// check for scale to fit
|
||||
if (_scaleToFit && !_scaledToFit) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "Transform.h"
|
||||
#include <AABox.h>
|
||||
#include <AnimationCache.h>
|
||||
#include <GeometryUtil.h>
|
||||
#include <PhysicsEntity.h>
|
||||
|
||||
#include "AnimationHandle.h"
|
||||
|
@ -34,7 +35,6 @@ class Shape;
|
|||
#include "RenderArgs.h"
|
||||
class ViewFrustum;
|
||||
|
||||
|
||||
#include "gpu/Stream.h"
|
||||
#include "gpu/Batch.h"
|
||||
|
||||
|
@ -89,6 +89,7 @@ public:
|
|||
enum RenderMode { DEFAULT_RENDER_MODE, SHADOW_RENDER_MODE, DIFFUSE_RENDER_MODE, NORMAL_RENDER_MODE };
|
||||
|
||||
bool render(float alpha = 1.0f, RenderMode mode = DEFAULT_RENDER_MODE, RenderArgs* args = NULL);
|
||||
bool renderTriangleProxies();
|
||||
|
||||
// Scene rendering support
|
||||
static void startScene(RenderArgs::RenderSide renderSide);
|
||||
|
@ -119,6 +120,9 @@ public:
|
|||
/// Returns the scaled equivalent of some extents in model space.
|
||||
Extents calculateScaledOffsetExtents(const Extents& extents) const;
|
||||
|
||||
/// Returns the scaled equivalent of a point in model space.
|
||||
glm::vec3 calculateScaledOffsetPoint(const glm::vec3& point) const;
|
||||
|
||||
/// Returns a reference to the shared geometry.
|
||||
const QSharedPointer<NetworkGeometry>& getGeometry() const { return _geometry; }
|
||||
|
||||
|
@ -193,8 +197,8 @@ public:
|
|||
Q_INVOKABLE void setTextureWithNameToURL(const QString& name, const QUrl& url)
|
||||
{ _geometry->setTextureWithNameToURL(name, url); }
|
||||
|
||||
bool findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const;
|
||||
bool findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance,
|
||||
BoxFace& face, QString& extraInfo, bool pickAgainstTriangles = false);
|
||||
|
||||
protected:
|
||||
QSharedPointer<NetworkGeometry> _geometry;
|
||||
|
@ -318,7 +322,7 @@ private:
|
|||
static ProgramObject _skinTranslucentProgram;
|
||||
|
||||
static ProgramObject _skinShadowProgram;
|
||||
|
||||
|
||||
static int _normalMapTangentLocation;
|
||||
static int _normalSpecularMapTangentLocation;
|
||||
|
||||
|
@ -361,10 +365,13 @@ private:
|
|||
|
||||
static void initSkinProgram(ProgramObject& program, SkinLocations& locations, int specularTextureUnit = 1);
|
||||
|
||||
QVector<AABox> _calculatedMeshBoxes;
|
||||
QVector<AABox> _calculatedMeshBoxes; // world coordinate AABoxes for all sub mesh boxes
|
||||
bool _calculatedMeshBoxesValid;
|
||||
|
||||
QVector< QVector<Triangle> > _calculatedMeshTriangles; // world coordinate triangles for all sub meshes
|
||||
bool _calculatedMeshTrianglesValid;
|
||||
|
||||
void recalcuateMeshBoxes();
|
||||
void recalculateMeshBoxes(bool pickAgainstTriangles = false);
|
||||
|
||||
void segregateMeshGroups(); // used to calculate our list of translucent vs opaque meshes
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ void JoystickScriptingInterface::update() {
|
|||
|
||||
// global action events fire in the center of the screen
|
||||
HFActionEvent actionEvent(actionType,
|
||||
Application::getInstance()->getViewFrustum()->computePickRay(0.5f, 0.5f));
|
||||
Application::getInstance()->getCamera()->computeViewPickRay(0.5f, 0.5f));
|
||||
qApp->sendEvent(qApp, &actionEvent);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -15,14 +15,13 @@
|
|||
class Overlays;
|
||||
class QOpenGLFramebufferObject;
|
||||
|
||||
const float MAGNIFY_WIDTH = 160.0f;
|
||||
const float MAGNIFY_HEIGHT = 80.0f;
|
||||
const float MAGNIFY_MULT = 4.0f;
|
||||
const float MAGNIFY_WIDTH = 220.0f;
|
||||
const float MAGNIFY_HEIGHT = 100.0f;
|
||||
const float MAGNIFY_MULT = 2.0f;
|
||||
|
||||
// Handles the drawing of the overlays to the screen
|
||||
class ApplicationOverlay {
|
||||
public:
|
||||
|
||||
ApplicationOverlay();
|
||||
~ApplicationOverlay();
|
||||
|
||||
|
@ -30,16 +29,25 @@ public:
|
|||
void displayOverlayTexture();
|
||||
void displayOverlayTextureOculus(Camera& whichCamera);
|
||||
void displayOverlayTexture3DTV(Camera& whichCamera, float aspectRatio, float fov);
|
||||
void computeOculusPickRay(float x, float y, glm::vec3& direction) const;
|
||||
void getClickLocation(int &x, int &y) const;
|
||||
|
||||
void computeOculusPickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const;
|
||||
QPoint getPalmClickLocation(const PalmData *palm) const;
|
||||
bool calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const;
|
||||
|
||||
|
||||
// Getters
|
||||
QOpenGLFramebufferObject* getFramebufferObject();
|
||||
float getAlpha() const { return _alpha; }
|
||||
|
||||
|
||||
// Converter from one frame of reference to another.
|
||||
// Frame of reference:
|
||||
// Screen: Position on the screen (x,y)
|
||||
// Spherical: Pitch and yaw that gives the position on the sphere we project on (yaw,pitch)
|
||||
// Overlay: Position on the overlay (x,y)
|
||||
// (x,y) in Overlay are similar than (x,y) in Screen except they can be outside of the bound of te screen.
|
||||
// This allows for picking outside of the screen projection in 3D.
|
||||
glm::vec2 screenToSpherical(glm::vec2 screenPos) const;
|
||||
glm::vec2 sphericalToScreen(glm::vec2 sphericalPos) const;
|
||||
glm::vec2 sphericalToOverlay(glm::vec2 sphericalPos) const;
|
||||
glm::vec2 overlayToSpherical(glm::vec2 overlayPos) const;
|
||||
glm::vec2 screenToOverlay(glm::vec2 screenPos) const;
|
||||
glm::vec2 overlayToScreen(glm::vec2 overlayPos) const;
|
||||
|
||||
private:
|
||||
// Interleaved vertex data
|
||||
struct TextureVertex {
|
||||
|
@ -48,31 +56,54 @@ private:
|
|||
};
|
||||
|
||||
typedef QPair<GLuint, GLuint> VerticesIndices;
|
||||
|
||||
void renderPointers();
|
||||
class TexturedHemisphere {
|
||||
public:
|
||||
TexturedHemisphere();
|
||||
~TexturedHemisphere();
|
||||
|
||||
void bind();
|
||||
void release();
|
||||
void bindTexture();
|
||||
void releaseTexture();
|
||||
|
||||
void buildFramebufferObject();
|
||||
void buildVBO(const float fov, const float aspectRatio, const int slices, const int stacks);
|
||||
void render();
|
||||
|
||||
private:
|
||||
void cleanupVBO();
|
||||
|
||||
GLuint _vertices;
|
||||
GLuint _indices;
|
||||
QOpenGLFramebufferObject* _framebufferObject;
|
||||
VerticesIndices _vbo;
|
||||
};
|
||||
|
||||
void renderPointers();;
|
||||
void renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) const;
|
||||
|
||||
void renderControllerPointers();
|
||||
void renderPointersOculus(const glm::vec3& eyePos);
|
||||
void renderMagnifier(int mouseX, int mouseY, float sizeMult, bool showBorder) const;
|
||||
|
||||
void renderAudioMeter();
|
||||
void renderStatsAndLogs();
|
||||
void renderTexturedHemisphere();
|
||||
void renderDomainConnectionStatusBorder();
|
||||
|
||||
QOpenGLFramebufferObject* _framebufferObject;
|
||||
float _trailingAudioLoudness;
|
||||
float _textureFov;
|
||||
TexturedHemisphere _overlays;
|
||||
|
||||
enum MagnifyDevices { MOUSE, LEFT_CONTROLLER, RIGHT_CONTROLLER, NUMBER_OF_MAGNIFIERS = RIGHT_CONTROLLER + 1 };
|
||||
bool _reticleActive[NUMBER_OF_MAGNIFIERS];
|
||||
int _mouseX[NUMBER_OF_MAGNIFIERS];
|
||||
int _mouseY[NUMBER_OF_MAGNIFIERS];
|
||||
bool _magActive[NUMBER_OF_MAGNIFIERS];
|
||||
int _magX[NUMBER_OF_MAGNIFIERS];
|
||||
int _magY[NUMBER_OF_MAGNIFIERS];
|
||||
float _magSizeMult[NUMBER_OF_MAGNIFIERS];
|
||||
float _textureFov;
|
||||
float _textureAspectRatio;
|
||||
|
||||
enum Reticles { MOUSE, LEFT_CONTROLLER, RIGHT_CONTROLLER, NUMBER_OF_RETICLES };
|
||||
bool _reticleActive[NUMBER_OF_RETICLES];
|
||||
QPoint _reticlePosition[NUMBER_OF_RETICLES];
|
||||
bool _magActive[NUMBER_OF_RETICLES];
|
||||
float _magSizeMult[NUMBER_OF_RETICLES];
|
||||
quint64 _lastMouseMove;
|
||||
|
||||
float _alpha;
|
||||
float _oculusuiRadius;
|
||||
float _oculusUIRadius;
|
||||
float _trailingAudioLoudness;
|
||||
|
||||
GLuint _crosshairTexture;
|
||||
};
|
||||
|
|
|
@ -38,12 +38,8 @@ void NodeBounds::draw() {
|
|||
// Compute ray to find selected nodes later on. We can't use the pre-computed ray in Application because it centers
|
||||
// itself after the cursor disappears.
|
||||
Application* application = Application::getInstance();
|
||||
GLCanvas* glWidget = application->getGLWidget();
|
||||
float mouseX = application->getMouseX() / (float)glWidget->width();
|
||||
float mouseY = application->getMouseY() / (float)glWidget->height();
|
||||
glm::vec3 mouseRayOrigin;
|
||||
glm::vec3 mouseRayDirection;
|
||||
application->getViewFrustum()->computePickRay(mouseX, mouseY, mouseRayOrigin, mouseRayDirection);
|
||||
PickRay pickRay = application->getCamera()->computePickRay(application->getTrueMouseX(),
|
||||
application->getTrueMouseY());
|
||||
|
||||
// Variables to keep track of the selected node and properties to draw the cube later if needed
|
||||
Node* selectedNode = NULL;
|
||||
|
@ -106,8 +102,8 @@ void NodeBounds::draw() {
|
|||
|
||||
float distance;
|
||||
BoxFace face;
|
||||
bool inside = serverBounds.contains(mouseRayOrigin);
|
||||
bool colliding = serverBounds.findRayIntersection(mouseRayOrigin, mouseRayDirection, distance, face);
|
||||
bool inside = serverBounds.contains(pickRay.origin);
|
||||
bool colliding = serverBounds.findRayIntersection(pickRay.origin, pickRay.direction, distance, face);
|
||||
|
||||
// If the camera is inside a node it will be "selected" if you don't have your cursor over another node
|
||||
// that you aren't inside.
|
||||
|
@ -225,8 +221,8 @@ void NodeBounds::drawOverlay() {
|
|||
const int MOUSE_OFFSET = 10;
|
||||
const int BACKGROUND_BEVEL = 3;
|
||||
|
||||
int mouseX = application->getMouseX(),
|
||||
mouseY = application->getMouseY(),
|
||||
int mouseX = application->getTrueMouseX(),
|
||||
mouseY = application->getTrueMouseY(),
|
||||
textWidth = widthText(TEXT_SCALE, 0, _overlayText);
|
||||
glColor4f(0.4f, 0.4f, 0.4f, 0.6f);
|
||||
renderBevelCornersRect(mouseX + MOUSE_OFFSET, mouseY - TEXT_HEIGHT - PADDING,
|
||||
|
|
|
@ -167,7 +167,7 @@ QScriptValue Base3DOverlay::getProperty(const QString& property) {
|
|||
}
|
||||
|
||||
bool Base3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
float& distance, BoxFace& face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,10 +50,10 @@ public:
|
|||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
|
||||
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const {
|
||||
float& distance, BoxFace& face, QString& extraInfo) {
|
||||
return findRayIntersection(origin, direction, distance, face);
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ void BillboardOverlay::replyFinished() {
|
|||
}
|
||||
|
||||
bool BillboardOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
float& distance, BoxFace& face) {
|
||||
|
||||
if (_billboardTexture) {
|
||||
float maxSize = glm::max(_fromImage.width(), _fromImage.height());
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
void setClipFromSource(const QRect& bounds) { _fromImage = bounds; }
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
|
||||
virtual BillboardOverlay* createClone() const;
|
||||
|
||||
|
|
|
@ -355,7 +355,7 @@ QScriptValue Circle3DOverlay::getProperty(const QString& property) {
|
|||
|
||||
|
||||
bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin,
|
||||
const glm::vec3& direction, float& distance, BoxFace& face) const {
|
||||
const glm::vec3& direction, float& distance, BoxFace& face) {
|
||||
|
||||
bool intersects = Planar3DOverlay::findRayIntersection(origin, direction, distance, face);
|
||||
if (intersects) {
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
void setMajorTickMarksColor(const xColor& value) { _majorTickMarksColor = value; }
|
||||
void setMinorTickMarksColor(const xColor& value) { _minorTickMarksColor = value; }
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
|
||||
virtual Circle3DOverlay* createClone() const;
|
||||
|
||||
|
|
|
@ -170,14 +170,14 @@ QScriptValue ModelOverlay::getProperty(const QString& property) {
|
|||
}
|
||||
|
||||
bool ModelOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
float& distance, BoxFace& face) {
|
||||
|
||||
QString subMeshNameTemp;
|
||||
return _model.findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, subMeshNameTemp);
|
||||
}
|
||||
|
||||
bool ModelOverlay::findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const {
|
||||
float& distance, BoxFace& face, QString& extraInfo) {
|
||||
|
||||
return _model.findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, extraInfo);
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@ public:
|
|||
virtual void render(RenderArgs* args);
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const;
|
||||
float& distance, BoxFace& face, QString& extraInfo);
|
||||
|
||||
virtual ModelOverlay* createClone() const;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <limits>
|
||||
#include <typeinfo>
|
||||
#include <Application.h>
|
||||
#include <devices/OculusManager.h>
|
||||
#include <Menu.h>
|
||||
#include <QScriptValueIterator>
|
||||
|
||||
|
@ -244,6 +245,11 @@ void Overlays::deleteOverlay(unsigned int id) {
|
|||
}
|
||||
|
||||
unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) {
|
||||
glm::vec2 pointCopy = point;
|
||||
if (OculusManager::isConnected()) {
|
||||
pointCopy = Application::getInstance()->getApplicationOverlay().screenToOverlay(point);
|
||||
}
|
||||
|
||||
QReadLocker lock(&_lock);
|
||||
QMapIterator<unsigned int, Overlay*> i(_overlays2D);
|
||||
i.toBack();
|
||||
|
@ -251,7 +257,8 @@ unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) {
|
|||
i.previous();
|
||||
unsigned int thisID = i.key();
|
||||
Overlay2D* thisOverlay = static_cast<Overlay2D*>(i.value());
|
||||
if (thisOverlay->getVisible() && thisOverlay->isLoaded() && thisOverlay->getBounds().contains(point.x, point.y, false)) {
|
||||
if (thisOverlay->getVisible() && thisOverlay->isLoaded() &&
|
||||
thisOverlay->getBounds().contains(pointCopy.x, pointCopy.y, false)) {
|
||||
return thisID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ QScriptValue Planar3DOverlay::getProperty(const QString& property) {
|
|||
}
|
||||
|
||||
bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
float& distance, BoxFace& face) {
|
||||
|
||||
RayIntersectionInfo rayInfo;
|
||||
rayInfo._rayStart = origin;
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
|
||||
protected:
|
||||
glm::vec2 _dimensions;
|
||||
|
|
|
@ -16,12 +16,14 @@
|
|||
#include "ui/TextRenderer.h"
|
||||
|
||||
const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 };
|
||||
const float DEFAULT_BACKGROUND_ALPHA = 0.7f;
|
||||
const float DEFAULT_MARGIN = 0.1f;
|
||||
const int FIXED_FONT_POINT_SIZE = 40;
|
||||
const float LINE_SCALE_RATIO = 1.2f;
|
||||
|
||||
Text3DOverlay::Text3DOverlay() :
|
||||
_backgroundColor(DEFAULT_BACKGROUND_COLOR),
|
||||
_backgroundAlpha(DEFAULT_BACKGROUND_ALPHA),
|
||||
_lineHeight(0.1f),
|
||||
_leftMargin(DEFAULT_MARGIN),
|
||||
_topMargin(DEFAULT_MARGIN),
|
||||
|
@ -35,6 +37,7 @@ Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
|
|||
Planar3DOverlay(text3DOverlay),
|
||||
_text(text3DOverlay->_text),
|
||||
_backgroundColor(text3DOverlay->_backgroundColor),
|
||||
_backgroundAlpha(text3DOverlay->_backgroundAlpha),
|
||||
_lineHeight(text3DOverlay->_lineHeight),
|
||||
_leftMargin(text3DOverlay->_leftMargin),
|
||||
_topMargin(text3DOverlay->_topMargin),
|
||||
|
@ -88,8 +91,8 @@ void Text3DOverlay::render(RenderArgs* args) {
|
|||
|
||||
const float MAX_COLOR = 255.0f;
|
||||
xColor backgroundColor = getBackgroundColor();
|
||||
float alpha = getAlpha();
|
||||
glColor4f(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, alpha);
|
||||
glColor4f(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR,
|
||||
getBackgroundAlpha());
|
||||
|
||||
glm::vec2 dimensions = getDimensions();
|
||||
glm::vec2 halfDimensions = dimensions * 0.5f;
|
||||
|
@ -124,6 +127,7 @@ void Text3DOverlay::render(RenderArgs* args) {
|
|||
enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y);
|
||||
|
||||
glColor3f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR);
|
||||
float alpha = getAlpha();
|
||||
QStringList lines = _text.split("\n");
|
||||
int lineOffset = maxHeight;
|
||||
foreach(QString thisLine, lines) {
|
||||
|
@ -166,6 +170,10 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
}
|
||||
|
||||
if (properties.property("backgroundAlpha").isValid()) {
|
||||
_backgroundAlpha = properties.property("backgroundAlpha").toVariant().toFloat();
|
||||
}
|
||||
|
||||
if (properties.property("lineHeight").isValid()) {
|
||||
setLineHeight(properties.property("lineHeight").toVariant().toFloat());
|
||||
}
|
||||
|
@ -200,6 +208,9 @@ QScriptValue Text3DOverlay::getProperty(const QString& property) {
|
|||
if (property == "backgroundColor") {
|
||||
return xColorToScriptValue(_scriptEngine, _backgroundColor);
|
||||
}
|
||||
if (property == "backgroundAlpha") {
|
||||
return _backgroundAlpha;
|
||||
}
|
||||
if (property == "lineHeight") {
|
||||
return _lineHeight;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
float getBottomMargin() const { return _bottomMargin; }
|
||||
bool getIsFacingAvatar() const { return _isFacingAvatar; }
|
||||
xColor getBackgroundColor();
|
||||
float getBackgroundAlpha() const { return _backgroundAlpha; }
|
||||
|
||||
// setters
|
||||
void setText(const QString& text) { _text = text; }
|
||||
|
@ -59,6 +60,7 @@ private:
|
|||
|
||||
QString _text;
|
||||
xColor _backgroundColor;
|
||||
float _backgroundAlpha;
|
||||
float _lineHeight;
|
||||
float _leftMargin;
|
||||
float _topMargin;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
TextOverlay::TextOverlay() :
|
||||
_backgroundColor(DEFAULT_BACKGROUND_COLOR),
|
||||
_backgroundAlpha(DEFAULT_BACKGROUND_ALPHA),
|
||||
_leftMargin(DEFAULT_MARGIN),
|
||||
_topMargin(DEFAULT_MARGIN),
|
||||
_fontSize(DEFAULT_FONTSIZE)
|
||||
|
@ -29,6 +30,7 @@ TextOverlay::TextOverlay(const TextOverlay* textOverlay) :
|
|||
Overlay2D(textOverlay),
|
||||
_text(textOverlay->_text),
|
||||
_backgroundColor(textOverlay->_backgroundColor),
|
||||
_backgroundAlpha(textOverlay->_backgroundAlpha),
|
||||
_leftMargin(textOverlay->_leftMargin),
|
||||
_topMargin(textOverlay->_topMargin),
|
||||
_fontSize(textOverlay->_fontSize)
|
||||
|
@ -63,11 +65,10 @@ void TextOverlay::render(RenderArgs* args) {
|
|||
return; // do nothing if we're not visible
|
||||
}
|
||||
|
||||
|
||||
const float MAX_COLOR = 255.0f;
|
||||
xColor backgroundColor = getBackgroundColor();
|
||||
float alpha = getAlpha();
|
||||
glColor4f(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, alpha);
|
||||
glColor4f(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR,
|
||||
getBackgroundAlpha());
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2f(_bounds.left(), _bounds.top());
|
||||
|
@ -85,6 +86,7 @@ void TextOverlay::render(RenderArgs* args) {
|
|||
int y = _bounds.top() + _topMargin + topAdjust;
|
||||
|
||||
glColor3f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR);
|
||||
float alpha = getAlpha();
|
||||
QStringList lines = _text.split("\n");
|
||||
int lineOffset = 0;
|
||||
foreach(QString thisLine, lines) {
|
||||
|
@ -125,6 +127,10 @@ void TextOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
}
|
||||
|
||||
if (properties.property("backgroundAlpha").isValid()) {
|
||||
_backgroundAlpha = properties.property("backgroundAlpha").toVariant().toFloat();
|
||||
}
|
||||
|
||||
if (properties.property("leftMargin").isValid()) {
|
||||
setLeftMargin(properties.property("leftMargin").toVariant().toInt());
|
||||
}
|
||||
|
@ -150,6 +156,9 @@ QScriptValue TextOverlay::getProperty(const QString& property) {
|
|||
if (property == "backgroundColor") {
|
||||
return xColorToScriptValue(_scriptEngine, _backgroundColor);
|
||||
}
|
||||
if (property == "backgroundAlpha") {
|
||||
return _backgroundAlpha;
|
||||
}
|
||||
if (property == "leftMargin") {
|
||||
return _leftMargin;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "Overlay2D.h"
|
||||
|
||||
const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 };
|
||||
const float DEFAULT_BACKGROUND_ALPHA = 0.7f;
|
||||
const int DEFAULT_MARGIN = 10;
|
||||
const int DEFAULT_FONTSIZE = 11;
|
||||
const int DEFAULT_FONT_WEIGHT = 50;
|
||||
|
@ -46,6 +47,7 @@ public:
|
|||
int getLeftMargin() const { return _leftMargin; }
|
||||
int getTopMargin() const { return _topMargin; }
|
||||
xColor getBackgroundColor();
|
||||
float getBackgroundAlpha() const { return _backgroundAlpha; }
|
||||
|
||||
// setters
|
||||
void setText(const QString& text) { _text = text; }
|
||||
|
@ -62,6 +64,7 @@ public:
|
|||
private:
|
||||
QString _text;
|
||||
xColor _backgroundColor;
|
||||
float _backgroundAlpha;
|
||||
int _leftMargin;
|
||||
int _topMargin;
|
||||
int _fontSize;
|
||||
|
|
|
@ -100,7 +100,7 @@ QScriptValue Volume3DOverlay::getProperty(const QString& property) {
|
|||
}
|
||||
|
||||
bool Volume3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
float& distance, BoxFace& face) {
|
||||
|
||||
// extents is the entity relative, scaled, centered extents of the entity
|
||||
glm::vec3 position = getPosition();
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||
|
||||
protected:
|
||||
glm::vec3 _dimensions;
|
||||
|
|
|
@ -85,6 +85,13 @@ bool AudioScriptingInterface::isInjectorPlaying(AudioInjector* injector) {
|
|||
return (injector != NULL);
|
||||
}
|
||||
|
||||
void AudioScriptingInterface::setInjectorOptions(AudioInjector* injector, const AudioInjectorOptions& injectorOptions) {
|
||||
AudioInjectorOptions optionsCopy = injectorOptions;
|
||||
if (injector) {
|
||||
injector->setOptions(optionsCopy);
|
||||
}
|
||||
}
|
||||
|
||||
float AudioScriptingInterface::getLoudness(AudioInjector* injector) {
|
||||
if (injector) {
|
||||
return injector->getLoudness();
|
||||
|
|
|
@ -35,6 +35,8 @@ public slots:
|
|||
void stopInjector(AudioInjector* injector);
|
||||
bool isInjectorPlaying(AudioInjector* injector);
|
||||
|
||||
void setInjectorOptions(AudioInjector* injector, const AudioInjectorOptions& injectorOptions);
|
||||
|
||||
void injectorStopped();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -54,7 +54,7 @@ void EntityCollisionSystem::updateCollisions() {
|
|||
PerformanceTimer perfTimer("collisions");
|
||||
assert(_entityTree);
|
||||
// update all Entities
|
||||
if (_entityTree->tryLockForRead()) {
|
||||
if (_entityTree->tryLockForWrite()) {
|
||||
foreach (EntityItem* entity, _movingEntities) {
|
||||
checkEntity(entity);
|
||||
}
|
||||
|
@ -70,13 +70,13 @@ void EntityCollisionSystem::checkEntity(EntityItem* entity) {
|
|||
}
|
||||
|
||||
void EntityCollisionSystem::emitGlobalEntityCollisionWithVoxel(EntityItem* entity,
|
||||
VoxelDetail* voxelDetails, const CollisionInfo& collision) {
|
||||
VoxelDetail* voxelDetails, const Collision& collision) {
|
||||
EntityItemID entityItemID = entity->getEntityItemID();
|
||||
emit entityCollisionWithVoxel(entityItemID, *voxelDetails, collision);
|
||||
}
|
||||
|
||||
void EntityCollisionSystem::emitGlobalEntityCollisionWithEntity(EntityItem* entityA,
|
||||
EntityItem* entityB, const CollisionInfo& collision) {
|
||||
EntityItem* entityB, const Collision& collision) {
|
||||
|
||||
EntityItemID idA = entityA->getEntityItemID();
|
||||
EntityItemID idB = entityB->getEntityItemID();
|
||||
|
@ -104,7 +104,8 @@ void EntityCollisionSystem::updateCollisionWithVoxels(EntityItem* entity) {
|
|||
// the results to systems outside of this octree reference frame.
|
||||
collisionInfo._contactPoint = (float)TREE_SCALE * (entity->getPosition() + entity->getRadius() * glm::normalize(collisionInfo._penetration));
|
||||
// let the global script run their collision scripts for Entities if they have them
|
||||
emitGlobalEntityCollisionWithVoxel(entity, voxelDetails, collisionInfo);
|
||||
Collision collision(collisionInfo._contactPoint, collisionInfo._penetration);
|
||||
emitGlobalEntityCollisionWithVoxel(entity, voxelDetails, collision);
|
||||
|
||||
// we must scale back down to the octree reference frame before updating the Entity properties
|
||||
collisionInfo._penetration /= (float)(TREE_SCALE);
|
||||
|
@ -169,10 +170,10 @@ void EntityCollisionSystem::updateCollisionWithEntities(EntityItem* entityA) {
|
|||
|
||||
quint64 now = usecTimestampNow();
|
||||
|
||||
CollisionInfo collision;
|
||||
collision._penetration = penetration;
|
||||
Collision collision;
|
||||
collision.penetration = penetration;
|
||||
// for now the contactPoint is the average between the the two paricle centers
|
||||
collision._contactPoint = (0.5f * (float)TREE_SCALE) * (entityA->getPosition() + entityB->getPosition());
|
||||
collision.contactPoint = (0.5f * (float)TREE_SCALE) * (entityA->getPosition() + entityB->getPosition());
|
||||
emitGlobalEntityCollisionWithEntity(entityA, entityB, collision);
|
||||
|
||||
glm::vec3 axis = glm::normalize(penetration);
|
||||
|
@ -208,7 +209,9 @@ void EntityCollisionSystem::updateCollisionWithEntities(EntityItem* entityA) {
|
|||
propertiesA.setPosition(newPositionA * (float)TREE_SCALE);
|
||||
propertiesA.setLastEdited(now);
|
||||
|
||||
_entityTree->updateEntity(idA, propertiesA);
|
||||
// NOTE: EntityTree::updateEntity() will cause the entity to get sorted correctly in the EntitySimulation,
|
||||
// thereby waking up static non-moving entities.
|
||||
_entityTree->updateEntity(entityA, propertiesA);
|
||||
_packetSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, idA, propertiesA);
|
||||
}
|
||||
|
||||
|
@ -225,7 +228,9 @@ void EntityCollisionSystem::updateCollisionWithEntities(EntityItem* entityA) {
|
|||
propertiesB.setPosition(newPositionB * (float)TREE_SCALE);
|
||||
propertiesB.setLastEdited(now);
|
||||
|
||||
_entityTree->updateEntity(idB, propertiesB);
|
||||
// NOTE: EntityTree::updateEntity() will cause the entity to get sorted correctly in the EntitySimulation,
|
||||
// thereby waking up static non-moving entities.
|
||||
_entityTree->updateEntity(entityB, propertiesB);
|
||||
_packetSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, idB, propertiesB);
|
||||
}
|
||||
}
|
||||
|
@ -331,6 +336,6 @@ void EntityCollisionSystem::applyHardCollision(EntityItem* entity, const Collisi
|
|||
properties.setVelocity(velocity * (float)TREE_SCALE);
|
||||
properties.setLastEdited(usecTimestampNow());
|
||||
|
||||
_entityTree->updateEntity(entityItemID, properties);
|
||||
_entityTree->updateEntity(entity, properties);
|
||||
_packetSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, entityItemID, properties);
|
||||
}
|
||||
|
|
|
@ -53,15 +53,15 @@ public:
|
|||
void updateCollisionSound(EntityItem* Entity, const glm::vec3 &penetration, float frequency);
|
||||
|
||||
signals:
|
||||
void entityCollisionWithVoxel(const EntityItemID& entityItemID, const VoxelDetail& voxel, const CollisionInfo& penetration);
|
||||
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const CollisionInfo& penetration);
|
||||
void entityCollisionWithVoxel(const EntityItemID& entityItemID, const VoxelDetail& voxel, const Collision& collision);
|
||||
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
||||
|
||||
private:
|
||||
void applyHardCollision(EntityItem* entity, const CollisionInfo& collisionInfo);
|
||||
|
||||
static bool updateOperation(OctreeElement* element, void* extraData);
|
||||
void emitGlobalEntityCollisionWithVoxel(EntityItem* Entity, VoxelDetail* voxelDetails, const CollisionInfo& penetration);
|
||||
void emitGlobalEntityCollisionWithEntity(EntityItem* entityA, EntityItem* entityB, const CollisionInfo& penetration);
|
||||
void emitGlobalEntityCollisionWithVoxel(EntityItem* Entity, VoxelDetail* voxelDetails, const Collision& penetration);
|
||||
void emitGlobalEntityCollisionWithEntity(EntityItem* entityA, EntityItem* entityB, const Collision& penetration);
|
||||
|
||||
EntityEditPacketSender* _packetSender;
|
||||
VoxelTree* _voxels;
|
||||
|
|
|
@ -29,7 +29,7 @@ const float EntityItem::DEFAULT_LOCAL_RENDER_ALPHA = 1.0f;
|
|||
const float EntityItem::DEFAULT_MASS = 1.0f;
|
||||
const float EntityItem::DEFAULT_LIFETIME = EntityItem::IMMORTAL;
|
||||
const QString EntityItem::DEFAULT_USER_DATA = QString("");
|
||||
const float EntityItem::DEFAULT_DAMPING = 0.5f;
|
||||
const float EntityItem::DEFAULT_DAMPING = 2.0f;
|
||||
const glm::vec3 EntityItem::NO_VELOCITY = glm::vec3(0, 0, 0);
|
||||
const float EntityItem::EPSILON_VELOCITY_LENGTH = (1.0f / 1000.0f) / (float)TREE_SCALE; // really small: 1mm/second
|
||||
const glm::vec3 EntityItem::DEFAULT_VELOCITY = EntityItem::NO_VELOCITY;
|
||||
|
@ -42,7 +42,7 @@ const glm::vec3 EntityItem::DEFAULT_DIMENSIONS = glm::vec3(0.1f, 0.1f, 0.1f);
|
|||
const glm::vec3 EntityItem::DEFAULT_REGISTRATION_POINT = glm::vec3(0.5f, 0.5f, 0.5f); // center
|
||||
const glm::vec3 EntityItem::NO_ANGULAR_VELOCITY = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
const glm::vec3 EntityItem::DEFAULT_ANGULAR_VELOCITY = NO_ANGULAR_VELOCITY;
|
||||
const float EntityItem::DEFAULT_ANGULAR_DAMPING = 0.5f;
|
||||
const float EntityItem::DEFAULT_ANGULAR_DAMPING = 2.0f;
|
||||
const bool EntityItem::DEFAULT_VISIBLE = true;
|
||||
const bool EntityItem::DEFAULT_IGNORE_FOR_COLLISIONS = false;
|
||||
const bool EntityItem::DEFAULT_COLLISIONS_WILL_MOVE = false;
|
||||
|
@ -58,6 +58,7 @@ void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) {
|
|||
_lastEditedFromRemote = 0;
|
||||
_lastEditedFromRemoteInRemoteTime = 0;
|
||||
|
||||
_lastSimulated = 0;
|
||||
_lastUpdated = 0;
|
||||
_created = 0; // TODO: when do we actually want to make this "now"
|
||||
_changedOnServer = 0;
|
||||
|
@ -88,12 +89,12 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) {
|
|||
_lastEdited = 0;
|
||||
_lastEditedFromRemote = 0;
|
||||
_lastEditedFromRemoteInRemoteTime = 0;
|
||||
_lastSimulated = 0;
|
||||
_lastUpdated = 0;
|
||||
_created = 0;
|
||||
_updateFlags = 0;
|
||||
_dirtyFlags = 0;
|
||||
_changedOnServer = 0;
|
||||
initFromEntityItemID(entityItemID);
|
||||
_simulationState = EntityItem::Static;
|
||||
}
|
||||
|
||||
EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) {
|
||||
|
@ -101,13 +102,13 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert
|
|||
_lastEdited = 0;
|
||||
_lastEditedFromRemote = 0;
|
||||
_lastEditedFromRemoteInRemoteTime = 0;
|
||||
_lastSimulated = 0;
|
||||
_lastUpdated = 0;
|
||||
_created = properties.getCreated();
|
||||
_updateFlags = 0;
|
||||
_dirtyFlags = 0;
|
||||
_changedOnServer = 0;
|
||||
initFromEntityItemID(entityItemID);
|
||||
setProperties(properties, true); // force copy
|
||||
_simulationState = EntityItem::Static;
|
||||
}
|
||||
|
||||
EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& params) const {
|
||||
|
@ -154,7 +155,7 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
|
|||
ByteCountCoded<quint32> typeCoder = getType();
|
||||
QByteArray encodedType = typeCoder;
|
||||
|
||||
quint64 updateDelta = getLastUpdated() <= getLastEdited() ? 0 : getLastUpdated() - getLastEdited();
|
||||
quint64 updateDelta = getLastSimulated() <= getLastEdited() ? 0 : getLastSimulated() - getLastEdited();
|
||||
ByteCountCoded<quint64> updateDeltaCoder = updateDelta;
|
||||
QByteArray encodedUpdateDelta = updateDeltaCoder;
|
||||
EntityPropertyFlags propertyFlags(PROP_LAST_ITEM);
|
||||
|
@ -450,9 +451,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
|||
ByteCountCoded<quint64> updateDeltaCoder = encodedUpdateDelta;
|
||||
quint64 updateDelta = updateDeltaCoder;
|
||||
if (overwriteLocalData) {
|
||||
_lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that for _lastEdited
|
||||
_lastSimulated = _lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that for _lastEdited
|
||||
if (wantDebug) {
|
||||
qDebug() << "_lastUpdated=" << _lastUpdated;
|
||||
qDebug() << "_lastUpdated =" << _lastUpdated;
|
||||
qDebug() << "_lastEdited=" << _lastEdited;
|
||||
qDebug() << "lastEditedFromBufferAdjusted=" << lastEditedFromBufferAdjusted;
|
||||
}
|
||||
|
@ -565,20 +566,20 @@ bool EntityItem::isRestingOnSurface() const {
|
|||
&& _gravity.y < 0.0f;
|
||||
}
|
||||
|
||||
void EntityItem::update(const quint64& updateTime) {
|
||||
void EntityItem::simulate(const quint64& now) {
|
||||
bool wantDebug = false;
|
||||
|
||||
if (_lastUpdated == 0) {
|
||||
_lastUpdated = updateTime;
|
||||
if (_lastSimulated == 0) {
|
||||
_lastSimulated = now;
|
||||
}
|
||||
|
||||
float timeElapsed = (float)(updateTime - _lastUpdated) / (float)(USECS_PER_SECOND);
|
||||
float timeElapsed = (float)(now - _lastSimulated) / (float)(USECS_PER_SECOND);
|
||||
|
||||
if (wantDebug) {
|
||||
qDebug() << "********** EntityItem::update()";
|
||||
qDebug() << " entity ID=" << getEntityItemID();
|
||||
qDebug() << " updateTime=" << updateTime;
|
||||
qDebug() << " _lastUpdated=" << _lastUpdated;
|
||||
qDebug() << " now=" << now;
|
||||
qDebug() << " _lastSimulated=" << _lastSimulated;
|
||||
qDebug() << " timeElapsed=" << timeElapsed;
|
||||
qDebug() << " hasVelocity=" << hasVelocity();
|
||||
qDebug() << " hasGravity=" << hasGravity();
|
||||
|
@ -611,10 +612,10 @@ void EntityItem::update(const quint64& updateTime) {
|
|||
}
|
||||
}
|
||||
|
||||
_lastUpdated = updateTime;
|
||||
_lastSimulated = now;
|
||||
|
||||
if (wantDebug) {
|
||||
qDebug() << " ********** EntityItem::update() .... SETTING _lastUpdated=" << _lastUpdated;
|
||||
qDebug() << " ********** EntityItem::update() .... SETTING _lastSimulated=" << _lastSimulated;
|
||||
}
|
||||
|
||||
if (hasAngularVelocity()) {
|
||||
|
@ -631,13 +632,13 @@ void EntityItem::update(const quint64& updateTime) {
|
|||
setRotation(rotation);
|
||||
|
||||
// handle damping for angular velocity
|
||||
if (getAngularDamping() > 0.0f) {
|
||||
glm::vec3 dampingResistance = getAngularVelocity() * getAngularDamping();
|
||||
glm::vec3 newAngularVelocity = getAngularVelocity() - (dampingResistance * timeElapsed);
|
||||
float dampingTimescale = getAngularDamping();
|
||||
if (dampingTimescale > 0.0f) {
|
||||
float dampingFactor = glm::clamp(timeElapsed / dampingTimescale, 0.0f, 1.0f);
|
||||
glm::vec3 newAngularVelocity = (1.0f - dampingFactor) * getAngularVelocity();
|
||||
setAngularVelocity(newAngularVelocity);
|
||||
if (wantDebug) {
|
||||
qDebug() << " getDamping():" << getDamping();
|
||||
qDebug() << " dampingResistance:" << dampingResistance;
|
||||
qDebug() << " dampingTimescale :" << dampingTimescale;
|
||||
qDebug() << " newAngularVelocity:" << newAngularVelocity;
|
||||
}
|
||||
}
|
||||
|
@ -688,13 +689,15 @@ void EntityItem::update(const quint64& updateTime) {
|
|||
}
|
||||
|
||||
// handle damping for velocity
|
||||
glm::vec3 dampingResistance = velocity * getDamping();
|
||||
if (wantDebug) {
|
||||
qDebug() << " getDamping():" << getDamping();
|
||||
qDebug() << " dampingResistance:" << dampingResistance;
|
||||
qDebug() << " dampingResistance * timeElapsed:" << dampingResistance * timeElapsed;
|
||||
float dampingTimescale = getDamping();
|
||||
if (dampingTimescale > 0.0f) {
|
||||
float dampingFactor = glm::clamp(timeElapsed / dampingTimescale, 0.0f, 1.0f);
|
||||
velocity *= (1.0f - dampingFactor);
|
||||
if (wantDebug) {
|
||||
qDebug() << " dampingTimescale:" << dampingTimescale;
|
||||
qDebug() << " newVelocity:" << velocity;
|
||||
}
|
||||
}
|
||||
velocity -= dampingResistance * timeElapsed;
|
||||
|
||||
if (wantDebug) {
|
||||
qDebug() << " velocity AFTER dampingResistance:" << velocity;
|
||||
|
@ -707,6 +710,7 @@ void EntityItem::update(const quint64& updateTime) {
|
|||
velocity = NO_VELOCITY;
|
||||
}
|
||||
|
||||
// NOTE: the simulation should NOT set any DirtyFlags on this entity
|
||||
setPosition(position); // this will automatically recalculate our collision shape
|
||||
setVelocity(velocity);
|
||||
|
||||
|
@ -719,20 +723,18 @@ void EntityItem::update(const quint64& updateTime) {
|
|||
}
|
||||
}
|
||||
|
||||
EntityItem::SimulationState EntityItem::computeSimulationState() const {
|
||||
if (hasVelocity() || (hasGravity() && !isRestingOnSurface()) || hasAngularVelocity()) {
|
||||
return EntityItem::Moving;
|
||||
}
|
||||
if (isMortal()) {
|
||||
return EntityItem::Mortal;
|
||||
}
|
||||
return EntityItem::Static;
|
||||
bool EntityItem::isMoving() const {
|
||||
return hasVelocity() || (hasGravity() && !isRestingOnSurface()) || hasAngularVelocity();
|
||||
}
|
||||
|
||||
bool EntityItem::lifetimeHasExpired() const {
|
||||
return isMortal() && (getAge() > getLifetime());
|
||||
}
|
||||
|
||||
quint64 EntityItem::getExpiry() const {
|
||||
return _created + (quint64)(_lifetime * (float)USECS_PER_SECOND);
|
||||
}
|
||||
|
||||
EntityItemProperties EntityItem::getProperties() const {
|
||||
EntityItemProperties properties;
|
||||
properties._id = getID();
|
||||
|
@ -778,23 +780,23 @@ bool EntityItem::setProperties(const EntityItemProperties& properties, bool forc
|
|||
}
|
||||
}
|
||||
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(position, setPositionInMeters); // this will call recalculate collision shape if needed
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(dimensions, setDimensionsInMeters); // NOTE: radius is obsolete
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(rotation, setRotation);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(mass, setMass);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(velocity, setVelocityInMeters);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(gravity, setGravityInMeters);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(position, updatePositionInMeters); // this will call recalculate collision shape if needed
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(dimensions, updateDimensionsInMeters); // NOTE: radius is obsolete
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(rotation, updateRotation);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(mass, updateMass);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(velocity, updateVelocityInMeters);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(gravity, updateGravityInMeters);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(damping, setDamping);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(lifetime, setLifetime);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(script, setScript);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(lifetime, updateLifetime);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(script, updateScript);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(registrationPoint, setRegistrationPoint);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(angularVelocity, setAngularVelocity);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(angularVelocity, updateAngularVelocity);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(angularDamping, setAngularDamping);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(glowLevel, setGlowLevel);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(localRenderAlpha, setLocalRenderAlpha);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(visible, setVisible);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(ignoreForCollisions, setIgnoreForCollisions);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(collisionsWillMove, setCollisionsWillMove);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(ignoreForCollisions, updateIgnoreForCollisions);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(collisionsWillMove, updateCollisionsWillMove);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(locked, setLocked);
|
||||
SET_ENTITY_PROPERTY_FROM_PROPERTIES(userData, setUserData);
|
||||
|
||||
|
@ -948,7 +950,7 @@ void EntityItem::updatePosition(const glm::vec3& value) {
|
|||
if (_position != value) {
|
||||
_position = value;
|
||||
recalculateCollisionShape();
|
||||
_updateFlags |= EntityItem::UPDATE_POSITION;
|
||||
_dirtyFlags |= EntityItem::DIRTY_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -957,7 +959,7 @@ void EntityItem::updatePositionInMeters(const glm::vec3& value) {
|
|||
if (_position != position) {
|
||||
_position = position;
|
||||
recalculateCollisionShape();
|
||||
_updateFlags |= EntityItem::UPDATE_POSITION;
|
||||
_dirtyFlags |= EntityItem::DIRTY_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -965,7 +967,7 @@ void EntityItem::updateDimensions(const glm::vec3& value) {
|
|||
if (_dimensions != value) {
|
||||
_dimensions = value;
|
||||
recalculateCollisionShape();
|
||||
_updateFlags |= EntityItem::UPDATE_SHAPE;
|
||||
_dirtyFlags |= EntityItem::DIRTY_SHAPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -974,7 +976,7 @@ void EntityItem::updateDimensionsInMeters(const glm::vec3& value) {
|
|||
if (_dimensions != dimensions) {
|
||||
_dimensions = dimensions;
|
||||
recalculateCollisionShape();
|
||||
_updateFlags |= EntityItem::UPDATE_SHAPE;
|
||||
_dirtyFlags |= EntityItem::DIRTY_SHAPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -982,21 +984,21 @@ void EntityItem::updateRotation(const glm::quat& rotation) {
|
|||
if (_rotation != rotation) {
|
||||
_rotation = rotation;
|
||||
recalculateCollisionShape();
|
||||
_updateFlags |= EntityItem::UPDATE_POSITION;
|
||||
_dirtyFlags |= EntityItem::DIRTY_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::updateMass(float value) {
|
||||
if (_mass != value) {
|
||||
_mass = value;
|
||||
_updateFlags |= EntityItem::UPDATE_MASS;
|
||||
_dirtyFlags |= EntityItem::DIRTY_MASS;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::updateVelocity(const glm::vec3& value) {
|
||||
if (_velocity != value) {
|
||||
_velocity = value;
|
||||
_updateFlags |= EntityItem::UPDATE_VELOCITY;
|
||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1004,14 +1006,14 @@ void EntityItem::updateVelocityInMeters(const glm::vec3& value) {
|
|||
glm::vec3 velocity = value / (float) TREE_SCALE;
|
||||
if (_velocity != velocity) {
|
||||
_velocity = velocity;
|
||||
_updateFlags |= EntityItem::UPDATE_VELOCITY;
|
||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::updateGravity(const glm::vec3& value) {
|
||||
if (_gravity != value) {
|
||||
_gravity = value;
|
||||
_updateFlags |= EntityItem::UPDATE_VELOCITY;
|
||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1019,36 +1021,42 @@ void EntityItem::updateGravityInMeters(const glm::vec3& value) {
|
|||
glm::vec3 gravity = value / (float) TREE_SCALE;
|
||||
if (_gravity != gravity) {
|
||||
_gravity = gravity;
|
||||
_updateFlags |= EntityItem::UPDATE_VELOCITY;
|
||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::updateAngularVelocity(const glm::vec3& value) {
|
||||
if (_angularVelocity != value) {
|
||||
_angularVelocity = value;
|
||||
_updateFlags |= EntityItem::UPDATE_VELOCITY;
|
||||
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::updateIgnoreForCollisions(bool value) {
|
||||
if (_ignoreForCollisions != value) {
|
||||
_ignoreForCollisions = value;
|
||||
_updateFlags |= EntityItem::UPDATE_COLLISION_GROUP;
|
||||
_dirtyFlags |= EntityItem::DIRTY_COLLISION_GROUP;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::updateCollisionsWillMove(bool value) {
|
||||
if (_collisionsWillMove != value) {
|
||||
_collisionsWillMove = value;
|
||||
_updateFlags |= EntityItem::UPDATE_MOTION_TYPE;
|
||||
_dirtyFlags |= EntityItem::DIRTY_MOTION_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::updateLifetime(float value) {
|
||||
if (_lifetime != value) {
|
||||
_lifetime = value;
|
||||
_updateFlags |= EntityItem::UPDATE_LIFETIME;
|
||||
_dirtyFlags |= EntityItem::DIRTY_LIFETIME;
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::updateScript(const QString& value) {
|
||||
if (_script != value) {
|
||||
_script = value;
|
||||
_dirtyFlags |= EntityItem::DIRTY_SCRIPT;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,15 +41,18 @@ class EntityTreeElementExtraEncodeData;
|
|||
class EntityItem {
|
||||
|
||||
public:
|
||||
enum EntityUpdateFlags {
|
||||
UPDATE_POSITION = 0x0001,
|
||||
UPDATE_VELOCITY = 0x0002,
|
||||
UPDATE_MASS = 0x0004,
|
||||
UPDATE_COLLISION_GROUP = 0x0008,
|
||||
UPDATE_MOTION_TYPE = 0x0010,
|
||||
UPDATE_SHAPE = 0x0020,
|
||||
UPDATE_LIFETIME = 0x0040
|
||||
//UPDATE_APPEARANCE = 0x8000,
|
||||
enum EntityDirtyFlags {
|
||||
DIRTY_POSITION = 0x0001,
|
||||
DIRTY_VELOCITY = 0x0002,
|
||||
DIRTY_MASS = 0x0004,
|
||||
DIRTY_COLLISION_GROUP = 0x0008,
|
||||
DIRTY_MOTION_TYPE = 0x0010,
|
||||
DIRTY_SHAPE = 0x0020,
|
||||
DIRTY_LIFETIME = 0x0040,
|
||||
DIRTY_UPDATEABLE = 0x0080,
|
||||
// add new simulation-relevant flags above
|
||||
// all other flags below
|
||||
DIRTY_SCRIPT = 0x8000
|
||||
};
|
||||
|
||||
DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly
|
||||
|
@ -77,12 +80,12 @@ public:
|
|||
/// has changed. This will be called with properties change or when new data is loaded from a stream
|
||||
virtual void somethingChangedNotification() { }
|
||||
|
||||
quint64 getLastUpdated() const { return _lastUpdated; } /// Last simulated time of this entity universal usecs
|
||||
quint64 getLastSimulated() const { return _lastSimulated; } /// Last simulated time of this entity universal usecs
|
||||
|
||||
/// Last edited time of this entity universal usecs
|
||||
quint64 getLastEdited() const { return _lastEdited; }
|
||||
void setLastEdited(quint64 lastEdited)
|
||||
{ _lastEdited = _lastUpdated = lastEdited; _changedOnServer = glm::max(lastEdited, _changedOnServer); }
|
||||
{ _lastEdited = _lastSimulated = _lastUpdated = lastEdited; _changedOnServer = glm::max(lastEdited, _changedOnServer); }
|
||||
float getEditedAgo() const /// Elapsed seconds since this entity was last edited
|
||||
{ return (float)(usecTimestampNow() - getLastEdited()) / (float)USECS_PER_SECOND; }
|
||||
|
||||
|
@ -121,24 +124,21 @@ public:
|
|||
unsigned char* bufferOut, int sizeIn, int& sizeOut);
|
||||
|
||||
static void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, size_t length, int clockSkew);
|
||||
virtual void update(const quint64& now);
|
||||
|
||||
// perform update
|
||||
virtual void update(const quint64& now) { _lastUpdated = now; }
|
||||
|
||||
typedef enum SimulationState_t {
|
||||
Static,
|
||||
Mortal,
|
||||
Moving
|
||||
} SimulationState;
|
||||
// perform linear extrapolation for SimpleEntitySimulation
|
||||
void simulate(const quint64& now);
|
||||
|
||||
// computes the SimulationState that the entity SHOULD be in.
|
||||
// Use getSimulationState() to find the state under which it is currently categorized.
|
||||
virtual SimulationState computeSimulationState() const;
|
||||
virtual bool needsToCallUpdate() const { return false; }
|
||||
|
||||
virtual void debugDump() const;
|
||||
|
||||
virtual bool supportsDetailedRayIntersection() const { return false; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const { return true; }
|
||||
void** intersectedObject, bool precisionPicking) const { return true; }
|
||||
|
||||
// attributes applicable to all entity types
|
||||
EntityTypes::EntityType getType() const { return _type; }
|
||||
|
@ -160,7 +160,7 @@ public:
|
|||
float getLargestDimension() const { return glm::length(_dimensions); } /// get the largest possible dimension
|
||||
|
||||
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
|
||||
void setDimensions(const glm::vec3& value) { _dimensions = value; recalculateCollisionShape(); }
|
||||
virtual void setDimensions(const glm::vec3& value) { _dimensions = value; recalculateCollisionShape(); }
|
||||
|
||||
/// set dimensions in meter units (0.0 - TREE_SCALE) this will also reset radius appropriately
|
||||
void setDimensionsInMeters(const glm::vec3& value) { setDimensions(value / (float) TREE_SCALE); }
|
||||
|
@ -221,11 +221,14 @@ public:
|
|||
/// age of this entity in seconds
|
||||
float getAge() const { return (float)(usecTimestampNow() - _created) / (float)USECS_PER_SECOND; }
|
||||
bool lifetimeHasExpired() const;
|
||||
quint64 getExpiry() const;
|
||||
|
||||
// position, size, and bounds related helpers
|
||||
float getSize() const; /// get maximum dimension in domain scale units (0.0 - 1.0)
|
||||
AACube getMaximumAACube() const;
|
||||
AACube getMinimumAACube() const;
|
||||
AACube getOldMaximumAACube() const { return _oldMaximumAACube; }
|
||||
void setOldMaximumAACube(const AACube& cube) { _oldMaximumAACube = cube; }
|
||||
AABox getAABox() const; /// axis aligned bounding box in domain scale units (0.0 - 1.0)
|
||||
|
||||
static const QString DEFAULT_SCRIPT;
|
||||
|
@ -278,7 +281,7 @@ public:
|
|||
virtual const Shape& getCollisionShapeInMeters() const { return _collisionShape; }
|
||||
virtual bool contains(const glm::vec3& point) const { return getAABox().contains(point); }
|
||||
|
||||
// updateFoo() methods to be used when changes need to be accumulated in the _updateFlags
|
||||
// updateFoo() methods to be used when changes need to be accumulated in the _dirtyFlags
|
||||
void updatePosition(const glm::vec3& value);
|
||||
void updatePositionInMeters(const glm::vec3& value);
|
||||
void updateDimensions(const glm::vec3& value);
|
||||
|
@ -293,13 +296,13 @@ public:
|
|||
void updateIgnoreForCollisions(bool value);
|
||||
void updateCollisionsWillMove(bool value);
|
||||
void updateLifetime(float value);
|
||||
void updateScript(const QString& value);
|
||||
|
||||
uint32_t getUpdateFlags() const { return _updateFlags; }
|
||||
void clearUpdateFlags() { _updateFlags = 0; }
|
||||
|
||||
SimulationState getSimulationState() const { return _simulationState; }
|
||||
uint32_t getDirtyFlags() const { return _dirtyFlags; }
|
||||
void clearDirtyFlags(uint32_t mask = 0xffff) { _dirtyFlags &= ~mask; }
|
||||
|
||||
void setSimulationState(SimulationState state) { _simulationState = state; }
|
||||
bool isMoving() const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void initFromEntityItemID(const EntityItemID& entityItemID); // maybe useful to allow subclasses to init
|
||||
|
@ -309,7 +312,8 @@ protected:
|
|||
QUuid _id;
|
||||
uint32_t _creatorTokenID;
|
||||
bool _newlyCreated;
|
||||
quint64 _lastUpdated;
|
||||
quint64 _lastSimulated; // last time this entity called simulate()
|
||||
quint64 _lastUpdated; // last time this entity called update()
|
||||
quint64 _lastEdited; // this is the last official local or remote edit time
|
||||
quint64 _lastEditedFromRemote; // this is the last time we received and edit from the server
|
||||
quint64 _lastEditedFromRemoteInRemoteTime; // time in server time space the last time we received and edit from the server
|
||||
|
@ -324,12 +328,12 @@ protected:
|
|||
float _mass;
|
||||
glm::vec3 _velocity;
|
||||
glm::vec3 _gravity;
|
||||
float _damping;
|
||||
float _damping; // timescale
|
||||
float _lifetime;
|
||||
QString _script;
|
||||
glm::vec3 _registrationPoint;
|
||||
glm::vec3 _angularVelocity;
|
||||
float _angularDamping;
|
||||
float _angularDamping; // timescale
|
||||
bool _visible;
|
||||
bool _ignoreForCollisions;
|
||||
bool _collisionsWillMove;
|
||||
|
@ -343,11 +347,10 @@ protected:
|
|||
void setRadius(float value);
|
||||
|
||||
AACubeShape _collisionShape;
|
||||
SimulationState _simulationState; // only set by EntityTree
|
||||
AACube _oldMaximumAACube; // remember this so we know where the entity used to live in the tree
|
||||
|
||||
// UpdateFlags are set whenever a property changes that requires the change to be communicated to other
|
||||
// data structures. It is the responsibility of the EntityTree to relay changes entity and clear flags.
|
||||
uint32_t _updateFlags;
|
||||
// DirtyFlags are set whenever a property changes that the EntitySimulation needs to know about.
|
||||
uint32_t _dirtyFlags; // things that have changed from EXTERNAL changes (via script or packet) but NOT from simulation
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -196,22 +196,26 @@ QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& ce
|
|||
return result;
|
||||
}
|
||||
|
||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray) {
|
||||
return findRayIntersectionWorker(ray, Octree::TryLock);
|
||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking) {
|
||||
return findRayIntersectionWorker(ray, Octree::TryLock, precisionPicking);
|
||||
}
|
||||
|
||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray) {
|
||||
return findRayIntersectionWorker(ray, Octree::Lock);
|
||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray, bool precisionPicking) {
|
||||
return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
|
||||
}
|
||||
|
||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray,
|
||||
Octree::lockType lockType) {
|
||||
Octree::lockType lockType,
|
||||
bool precisionPicking) {
|
||||
|
||||
|
||||
RayToEntityIntersectionResult result;
|
||||
if (_entityTree) {
|
||||
OctreeElement* element;
|
||||
EntityItem* intersectedEntity = NULL;
|
||||
result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
|
||||
(void**)&intersectedEntity, lockType, &result.accurate);
|
||||
(void**)&intersectedEntity, lockType, &result.accurate,
|
||||
precisionPicking);
|
||||
if (result.intersects && intersectedEntity) {
|
||||
result.entityID = intersectedEntity->getEntityItemID();
|
||||
result.properties = intersectedEntity->getProperties();
|
||||
|
|
|
@ -90,11 +90,11 @@ public slots:
|
|||
/// If the scripting context has visible voxels, this will determine a ray intersection, the results
|
||||
/// may be inaccurate if the engine is unable to access the visible voxels, in which case result.accurate
|
||||
/// will be false.
|
||||
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray);
|
||||
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray, bool precisionPicking = false);
|
||||
|
||||
/// If the scripting context has visible voxels, this will determine a ray intersection, and will block in
|
||||
/// order to return an accurate result
|
||||
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersectionBlocking(const PickRay& ray);
|
||||
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersectionBlocking(const PickRay& ray, bool precisionPicking = false);
|
||||
|
||||
Q_INVOKABLE void setLightsArePickable(bool value);
|
||||
Q_INVOKABLE bool getLightsArePickable() const;
|
||||
|
@ -102,8 +102,8 @@ public slots:
|
|||
Q_INVOKABLE void dumpTree() const;
|
||||
|
||||
signals:
|
||||
void entityCollisionWithVoxel(const EntityItemID& entityID, const VoxelDetail& voxel, const CollisionInfo& collision);
|
||||
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const CollisionInfo& collision);
|
||||
void entityCollisionWithVoxel(const EntityItemID& entityID, const VoxelDetail& voxel, const Collision& collision);
|
||||
void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision);
|
||||
|
||||
void mousePressOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
|
||||
void mouseMoveOnEntity(const EntityItemID& entityItemID, const MouseEvent& event);
|
||||
|
@ -124,7 +124,8 @@ private:
|
|||
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
|
||||
|
||||
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
|
||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType);
|
||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
||||
bool precisionPicking);
|
||||
|
||||
uint32_t _nextCreatorTokenID;
|
||||
EntityTree* _entityTree;
|
||||
|
|
|
@ -9,12 +9,178 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <AACube.h>
|
||||
|
||||
#include "EntitySimulation.h"
|
||||
#include "MovingEntitiesOperator.h"
|
||||
|
||||
void EntitySimulation::setEntityTree(EntityTree* tree) {
|
||||
if (_entityTree && _entityTree != tree) {
|
||||
clearEntities();
|
||||
_mortalEntities.clear();
|
||||
_nextExpiry = quint64(-1);
|
||||
_updateableEntities.clear();
|
||||
_entitiesToBeSorted.clear();
|
||||
}
|
||||
_entityTree = tree;
|
||||
}
|
||||
|
||||
void EntitySimulation::updateEntities(QSet<EntityItem*>& entitiesToDelete) {
|
||||
quint64 now = usecTimestampNow();
|
||||
|
||||
// these methods may accumulate entries in _entitiesToBeDeleted
|
||||
expireMortalEntities(now);
|
||||
callUpdateOnEntitiesThatNeedIt(now);
|
||||
updateEntitiesInternal(now);
|
||||
sortEntitiesThatMoved();
|
||||
|
||||
// at this point we harvest _entitiesToBeDeleted
|
||||
entitiesToDelete.unite(_entitiesToDelete);
|
||||
_entitiesToDelete.clear();
|
||||
}
|
||||
|
||||
void EntitySimulation::expireMortalEntities(const quint64& now) {
|
||||
if (now > _nextExpiry) {
|
||||
// only search for expired entities if we expect to find one
|
||||
_nextExpiry = quint64(-1);
|
||||
QSet<EntityItem*>::iterator itemItr = _mortalEntities.begin();
|
||||
while (itemItr != _mortalEntities.end()) {
|
||||
EntityItem* entity = *itemItr;
|
||||
quint64 expiry = entity->getExpiry();
|
||||
if (expiry < now) {
|
||||
_entitiesToDelete.insert(entity);
|
||||
itemItr = _mortalEntities.erase(itemItr);
|
||||
_updateableEntities.remove(entity);
|
||||
_entitiesToBeSorted.remove(entity);
|
||||
removeEntityInternal(entity);
|
||||
} else {
|
||||
if (expiry < _nextExpiry) {
|
||||
// remeber the smallest _nextExpiry so we know when to start the next search
|
||||
_nextExpiry = expiry;
|
||||
}
|
||||
++itemItr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EntitySimulation::callUpdateOnEntitiesThatNeedIt(const quint64& now) {
|
||||
PerformanceTimer perfTimer("updatingEntities");
|
||||
QSet<EntityItem*>::iterator itemItr = _updateableEntities.begin();
|
||||
while (itemItr != _updateableEntities.end()) {
|
||||
EntityItem* entity = *itemItr;
|
||||
// TODO: catch transition from needing update to not as a "change"
|
||||
// so we don't have to scan for it here.
|
||||
if (!entity->needsToCallUpdate()) {
|
||||
itemItr = _updateableEntities.erase(itemItr);
|
||||
} else {
|
||||
entity->update(now);
|
||||
++itemItr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EntitySimulation::sortEntitiesThatMoved() {
|
||||
// NOTE: this is only for entities that have been moved by THIS EntitySimulation.
|
||||
// External changes to entity position/shape are expected to be sorted outside of the EntitySimulation.
|
||||
PerformanceTimer perfTimer("sortingEntities");
|
||||
MovingEntitiesOperator moveOperator(_entityTree);
|
||||
AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), 1.0f);
|
||||
QSet<EntityItem*>::iterator itemItr = _entitiesToBeSorted.begin();
|
||||
while (itemItr != _entitiesToBeSorted.end()) {
|
||||
EntityItem* entity = *itemItr;
|
||||
// check to see if this movement has sent the entity outside of the domain.
|
||||
AACube newCube = entity->getMaximumAACube();
|
||||
if (!domainBounds.touches(newCube)) {
|
||||
qDebug() << "Entity " << entity->getEntityItemID() << " moved out of domain bounds.";
|
||||
_entitiesToDelete.insert(entity);
|
||||
_mortalEntities.remove(entity);
|
||||
_updateableEntities.remove(entity);
|
||||
removeEntityInternal(entity);
|
||||
} else {
|
||||
moveOperator.addEntityToMoveList(entity, newCube);
|
||||
}
|
||||
++itemItr;
|
||||
}
|
||||
_entitiesToBeSorted.clear();
|
||||
|
||||
if (moveOperator.hasMovingEntities()) {
|
||||
PerformanceTimer perfTimer("recurseTreeWithOperator");
|
||||
_entityTree->recurseTreeWithOperator(&moveOperator);
|
||||
moveOperator.finish();
|
||||
}
|
||||
}
|
||||
|
||||
void EntitySimulation::addEntity(EntityItem* entity) {
|
||||
assert(entity);
|
||||
if (entity->isMortal()) {
|
||||
_mortalEntities.insert(entity);
|
||||
quint64 expiry = entity->getExpiry();
|
||||
if (expiry < _nextExpiry) {
|
||||
_nextExpiry = expiry;
|
||||
}
|
||||
}
|
||||
if (entity->needsToCallUpdate()) {
|
||||
_updateableEntities.insert(entity);
|
||||
}
|
||||
addEntityInternal(entity);
|
||||
}
|
||||
|
||||
void EntitySimulation::removeEntity(EntityItem* entity) {
|
||||
assert(entity);
|
||||
_updateableEntities.remove(entity);
|
||||
_mortalEntities.remove(entity);
|
||||
_entitiesToBeSorted.remove(entity);
|
||||
_entitiesToDelete.remove(entity);
|
||||
removeEntityInternal(entity);
|
||||
}
|
||||
|
||||
void EntitySimulation::entityChanged(EntityItem* entity) {
|
||||
assert(entity);
|
||||
|
||||
// Although it is not the responsibility of the EntitySimulation to sort the tree for EXTERNAL changes
|
||||
// it IS responsibile for triggering deletes for entities that leave the bounds of the domain, hence
|
||||
// we must check for that case here, however we rely on the change event to have set DIRTY_POSITION flag.
|
||||
bool wasRemoved = false;
|
||||
uint32_t dirtyFlags = entity->getDirtyFlags();
|
||||
if (dirtyFlags & EntityItem::DIRTY_POSITION) {
|
||||
AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), 1.0f);
|
||||
AACube newCube = entity->getMaximumAACube();
|
||||
if (!domainBounds.touches(newCube)) {
|
||||
qDebug() << "Entity " << entity->getEntityItemID() << " moved out of domain bounds.";
|
||||
_entitiesToDelete.insert(entity);
|
||||
_mortalEntities.remove(entity);
|
||||
_updateableEntities.remove(entity);
|
||||
removeEntityInternal(entity);
|
||||
wasRemoved = true;
|
||||
}
|
||||
}
|
||||
if (!wasRemoved) {
|
||||
if (dirtyFlags & EntityItem::DIRTY_LIFETIME) {
|
||||
if (entity->isMortal()) {
|
||||
_mortalEntities.insert(entity);
|
||||
quint64 expiry = entity->getExpiry();
|
||||
if (expiry < _nextExpiry) {
|
||||
_nextExpiry = expiry;
|
||||
}
|
||||
} else {
|
||||
_mortalEntities.remove(entity);
|
||||
}
|
||||
entity->clearDirtyFlags(EntityItem::DIRTY_LIFETIME);
|
||||
}
|
||||
if (entity->needsToCallUpdate()) {
|
||||
_updateableEntities.insert(entity);
|
||||
} else {
|
||||
_updateableEntities.remove(entity);
|
||||
}
|
||||
entityChangedInternal(entity);
|
||||
}
|
||||
entity->clearDirtyFlags();
|
||||
}
|
||||
|
||||
void EntitySimulation::clearEntities() {
|
||||
_mortalEntities.clear();
|
||||
_nextExpiry = quint64(-1);
|
||||
_updateableEntities.clear();
|
||||
_entitiesToBeSorted.clear();
|
||||
clearEntitiesInternal();
|
||||
}
|
||||
|
|
|
@ -14,36 +14,61 @@
|
|||
|
||||
#include <QSet>
|
||||
|
||||
#include <PerfStat.h>
|
||||
|
||||
#include "EntityTree.h"
|
||||
|
||||
class EntitySimulation {
|
||||
public:
|
||||
EntitySimulation() : _entityTree(NULL) { }
|
||||
virtual ~EntitySimulation() {}
|
||||
virtual ~EntitySimulation() { setEntityTree(NULL); }
|
||||
|
||||
/// \param tree pointer to EntityTree which is stored internally
|
||||
virtual void setEntityTree(EntityTree* tree);
|
||||
void setEntityTree(EntityTree* tree);
|
||||
|
||||
/// \param[out] entitiesToDelete list of entities removed from simulation and should be deleted.
|
||||
virtual void update(QSet<EntityItem*>& entitiesToDelete) = 0;
|
||||
void updateEntities(QSet<EntityItem*>& entitiesToDelete);
|
||||
|
||||
/// \param entity pointer to EntityItem to add to the simulation
|
||||
/// \sideeffect the EntityItem::_simulationState member may be updated to indicate membership to internal list
|
||||
virtual void addEntity(EntityItem* entity) = 0;
|
||||
void addEntity(EntityItem* entity);
|
||||
|
||||
/// \param entity pointer to EntityItem to removed from the simulation
|
||||
/// \sideeffect the EntityItem::_simulationState member may be updated to indicate non-membership to internal list
|
||||
virtual void removeEntity(EntityItem* entity) = 0;
|
||||
void removeEntity(EntityItem* entity);
|
||||
|
||||
/// \param entity pointer to EntityItem to that may have changed in a way that would affect its simulation
|
||||
virtual void entityChanged(EntityItem* entity) = 0;
|
||||
/// call this whenever an entity was changed from some EXTERNAL event (NOT by the EntitySimulation itself)
|
||||
void entityChanged(EntityItem* entity);
|
||||
|
||||
virtual void clearEntities() = 0;
|
||||
void clearEntities();
|
||||
|
||||
EntityTree* getEntityTree() { return _entityTree; }
|
||||
|
||||
protected:
|
||||
|
||||
// These pure virtual methods are protected because they are not to be called will-nilly. The base class
|
||||
// calls them in the right places.
|
||||
virtual void updateEntitiesInternal(const quint64& now) = 0;
|
||||
virtual void addEntityInternal(EntityItem* entity) = 0;
|
||||
virtual void removeEntityInternal(EntityItem* entity) = 0;
|
||||
virtual void entityChangedInternal(EntityItem* entity) = 0;
|
||||
virtual void clearEntitiesInternal() = 0;
|
||||
|
||||
void expireMortalEntities(const quint64& now);
|
||||
void callUpdateOnEntitiesThatNeedIt(const quint64& now);
|
||||
void sortEntitiesThatMoved();
|
||||
|
||||
// back pointer to EntityTree structure
|
||||
EntityTree* _entityTree;
|
||||
|
||||
// We maintain multiple lists, each for its distinct purpose.
|
||||
// An entity may be in more than one list.
|
||||
QSet<EntityItem*> _mortalEntities; // entities that have an expiry
|
||||
quint64 _nextExpiry;
|
||||
QSet<EntityItem*> _updateableEntities; // entities that need update() called
|
||||
QSet<EntityItem*> _entitiesToBeSorted; // entities that were moved by THIS simulation and might need to be resorted in the tree
|
||||
QSet<EntityItem*> _entitiesToDelete;
|
||||
};
|
||||
|
||||
#endif // hifi_EntitySimulation_h
|
||||
|
|
|
@ -19,9 +19,13 @@
|
|||
#include "MovingEntitiesOperator.h"
|
||||
#include "UpdateEntityOperator.h"
|
||||
|
||||
EntityTree::EntityTree(bool shouldReaverage) : Octree(shouldReaverage), _simulation(NULL) {
|
||||
EntityTree::EntityTree(bool shouldReaverage) :
|
||||
Octree(shouldReaverage),
|
||||
_fbxService(NULL),
|
||||
_lightsArePickable(true),
|
||||
_simulation(NULL)
|
||||
{
|
||||
_rootElement = createNewElement();
|
||||
_lightsArePickable = true; // assume they are by default
|
||||
}
|
||||
|
||||
EntityTree::~EntityTree() {
|
||||
|
@ -79,6 +83,7 @@ EntityItem* EntityTree::getOrCreateEntityItem(const EntityItemID& entityID, cons
|
|||
/// Adds a new entity item to the tree
|
||||
void EntityTree::postAddEntity(EntityItem* entity) {
|
||||
assert(entity);
|
||||
entity->setOldMaximumAACube(entity->getMaximumAACube());
|
||||
// check to see if we need to simulate this entity..
|
||||
if (_simulation) {
|
||||
_simulation->addEntity(entity);
|
||||
|
@ -99,51 +104,64 @@ bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProp
|
|||
qDebug() << "UNEXPECTED!!!! don't call updateEntity() on entity items that don't exist. entityID=" << entityID;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return updateEntityWithElement(existingEntity, properties, containingElement);
|
||||
}
|
||||
|
||||
bool EntityTree::updateEntity(EntityItem* entity, const EntityItemProperties& properties) {
|
||||
EntityTreeElement* containingElement = getContainingElement(entity->getEntityItemID());
|
||||
if (!containingElement) {
|
||||
qDebug() << "UNEXPECTED!!!! EntityTree::updateEntity() entity-->element lookup failed!!! entityID="
|
||||
<< entity->getEntityItemID();
|
||||
return false;
|
||||
}
|
||||
return updateEntityWithElement(entity, properties, containingElement);
|
||||
}
|
||||
|
||||
bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemProperties& properties,
|
||||
EntityTreeElement* containingElement) {
|
||||
// enforce support for locked entities. If an entity is currently locked, then the only
|
||||
// property we allow you to change is the locked property.
|
||||
if (existingEntity->getLocked()) {
|
||||
if (entity->getLocked()) {
|
||||
if (properties.lockedChanged()) {
|
||||
bool wantsLocked = properties.getLocked();
|
||||
if (!wantsLocked) {
|
||||
EntityItemProperties tempProperties;
|
||||
tempProperties.setLocked(wantsLocked);
|
||||
UpdateEntityOperator theOperator(this, containingElement, existingEntity, tempProperties);
|
||||
UpdateEntityOperator theOperator(this, containingElement, entity, tempProperties);
|
||||
recurseTreeWithOperator(&theOperator);
|
||||
_isDirty = true;
|
||||
if (_simulation && existingEntity->getUpdateFlags() != 0) {
|
||||
_simulation->entityChanged(existingEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// check to see if we need to simulate this entity...
|
||||
QString entityScriptBefore = existingEntity->getScript();
|
||||
QString entityScriptBefore = entity->getScript();
|
||||
|
||||
UpdateEntityOperator theOperator(this, containingElement, existingEntity, properties);
|
||||
UpdateEntityOperator theOperator(this, containingElement, entity, properties);
|
||||
recurseTreeWithOperator(&theOperator);
|
||||
entity->setOldMaximumAACube(entity->getMaximumAACube());
|
||||
_isDirty = true;
|
||||
|
||||
if (_simulation && existingEntity->getUpdateFlags() != 0) {
|
||||
_simulation->entityChanged(existingEntity);
|
||||
if (_simulation && entity->getDirtyFlags() != 0) {
|
||||
_simulation->entityChanged(entity);
|
||||
}
|
||||
|
||||
QString entityScriptAfter = existingEntity->getScript();
|
||||
QString entityScriptAfter = entity->getScript();
|
||||
if (entityScriptBefore != entityScriptAfter) {
|
||||
emitEntityScriptChanging(entityID); // the entity script has changed
|
||||
emit entityScriptChanging(entity->getEntityItemID()); // the entity script has changed
|
||||
}
|
||||
}
|
||||
|
||||
containingElement = getContainingElement(entityID);
|
||||
// TODO: this final containingElement check should eventually be removed (or wrapped in an #ifdef DEBUG).
|
||||
containingElement = getContainingElement(entity->getEntityItemID());
|
||||
if (!containingElement) {
|
||||
qDebug() << "UNEXPECTED!!!! after updateEntity() we no longer have a containing element??? entityID=" << entityID;
|
||||
qDebug() << "UNEXPECTED!!!! after updateEntity() we no longer have a containing element??? entityID="
|
||||
<< entity->getEntityItemID();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItemProperties& properties) {
|
||||
EntityItem* result = NULL;
|
||||
|
||||
|
@ -572,7 +590,7 @@ void EntityTree::update() {
|
|||
if (_simulation) {
|
||||
lockForWrite();
|
||||
QSet<EntityItem*> entitiesToDelete;
|
||||
_simulation->update(entitiesToDelete);
|
||||
_simulation->updateEntities(entitiesToDelete);
|
||||
if (entitiesToDelete.size() > 0) {
|
||||
// translate into list of ID's
|
||||
QSet<EntityItemID> idsToDelete;
|
||||
|
|
|
@ -82,7 +82,13 @@ public:
|
|||
void postAddEntity(EntityItem* entityItem);
|
||||
|
||||
EntityItem* addEntity(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||
|
||||
// use this method if you only know the entityID
|
||||
bool updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties);
|
||||
|
||||
// use this method if you have a pointer to the entity (avoid an extra entity lookup)
|
||||
bool updateEntity(EntityItem* entity, const EntityItemProperties& properties);
|
||||
|
||||
void deleteEntity(const EntityItemID& entityID);
|
||||
void deleteEntities(QSet<EntityItemID> entityIDs);
|
||||
void removeEntityFromSimulation(EntityItem* entity);
|
||||
|
@ -156,6 +162,8 @@ signals:
|
|||
|
||||
private:
|
||||
|
||||
bool updateEntityWithElement(EntityItem* entity, const EntityItemProperties& properties,
|
||||
EntityTreeElement* containingElement);
|
||||
static bool findNearPointOperation(OctreeElement* element, void* extraData);
|
||||
static bool findInSphereOperation(OctreeElement* element, void* extraData);
|
||||
static bool findInCubeOperation(OctreeElement* element, void* extraData);
|
||||
|
|
|
@ -475,13 +475,17 @@ bool EntityTreeElement::bestFitBounds(const glm::vec3& minPoint, const glm::vec3
|
|||
|
||||
bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) {
|
||||
void** intersectedObject, bool precisionPicking, float distanceToElementCube) {
|
||||
|
||||
// only called if we do intersect our bounding cube, but find if we actually intersect with entities...
|
||||
int entityNumber = 0;
|
||||
|
||||
QList<EntityItem*>::iterator entityItr = _entityItems->begin();
|
||||
QList<EntityItem*>::const_iterator entityEnd = _entityItems->end();
|
||||
bool somethingIntersected = false;
|
||||
|
||||
//float bestEntityDistance = distance;
|
||||
|
||||
while(entityItr != entityEnd) {
|
||||
EntityItem* entity = (*entityItr);
|
||||
|
||||
|
@ -513,10 +517,9 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
|||
if (localDistance < distance) {
|
||||
// now ask the entity if we actually intersect
|
||||
if (entity->supportsDetailedRayIntersection()) {
|
||||
|
||||
if (entity->findDetailedRayIntersection(origin, direction, keepSearching, element, localDistance,
|
||||
localFace, intersectedObject)) {
|
||||
|
||||
localFace, intersectedObject, precisionPicking)) {
|
||||
|
||||
if (localDistance < distance) {
|
||||
distance = localDistance;
|
||||
face = localFace;
|
||||
|
@ -538,6 +541,7 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
|||
}
|
||||
|
||||
++entityItr;
|
||||
entityNumber++;
|
||||
}
|
||||
return somethingIntersected;
|
||||
}
|
||||
|
@ -757,7 +761,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
|||
EntityTreeElement* currentContainingElement = _myTree->getContainingElement(entityItemID);
|
||||
|
||||
bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args);
|
||||
if (entityItem->getUpdateFlags()) {
|
||||
if (entityItem->getDirtyFlags()) {
|
||||
_myTree->entityChanged(entityItem);
|
||||
}
|
||||
bool bestFitAfter = bestFitEntityBounds(entityItem);
|
||||
|
|
|
@ -137,7 +137,7 @@ public:
|
|||
virtual bool canRayIntersect() const { return hasEntities(); }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject);
|
||||
void** intersectedObject, bool precisionPicking, float distanceToElementCube);
|
||||
|
||||
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
||||
glm::vec3& penetration, void** penetratedObject) const;
|
||||
|
|
|
@ -47,6 +47,13 @@ LightEntityItem::LightEntityItem(const EntityItemID& entityItemID, const EntityI
|
|||
_emptyShape.setRadius(0.0f);
|
||||
}
|
||||
|
||||
void LightEntityItem::setDimensions(const glm::vec3& value) {
|
||||
float maxDimension = glm::max(value.x, value.y, value.z);
|
||||
_dimensions = glm::vec3(maxDimension, maxDimension, maxDimension);
|
||||
recalculateCollisionShape();
|
||||
}
|
||||
|
||||
|
||||
EntityItemProperties LightEntityItem::getProperties() const {
|
||||
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ public:
|
|||
LightEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
|
||||
|
||||
ALLOW_INSTANTIATION // This class can be instantiated
|
||||
|
||||
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
|
||||
virtual void setDimensions(const glm::vec3& value);
|
||||
|
||||
// methods for getting/setting all properties of an entity
|
||||
virtual EntityItemProperties getProperties() const;
|
||||
|
|
|
@ -373,17 +373,11 @@ bool ModelEntityItem::isAnimatingSomething() const {
|
|||
!getAnimationURL().isEmpty();
|
||||
}
|
||||
|
||||
EntityItem::SimulationState ModelEntityItem::computeSimulationState() const {
|
||||
// if we're animating then we need to have update() periodically called on this entity
|
||||
// which means we need to categorized as Moving
|
||||
return isAnimatingSomething() ? EntityItem::Moving : EntityItem::computeSimulationState();
|
||||
bool ModelEntityItem::needsToCallUpdate() const {
|
||||
return isAnimatingSomething() ? true : EntityItem::needsToCallUpdate();
|
||||
}
|
||||
|
||||
void ModelEntityItem::update(const quint64& updateTime) {
|
||||
EntityItem::update(updateTime); // let our base class handle it's updates...
|
||||
|
||||
quint64 now = updateTime;
|
||||
|
||||
void ModelEntityItem::update(const quint64& now) {
|
||||
// only advance the frame index if we're playing
|
||||
if (getAnimationIsPlaying()) {
|
||||
float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND;
|
||||
|
@ -392,6 +386,7 @@ void ModelEntityItem::update(const quint64& updateTime) {
|
|||
} else {
|
||||
_lastAnimated = now;
|
||||
}
|
||||
EntityItem::update(now); // let our base class handle it's updates...
|
||||
}
|
||||
|
||||
void ModelEntityItem::debugDump() const {
|
||||
|
@ -402,6 +397,11 @@ void ModelEntityItem::debugDump() const {
|
|||
qDebug() << " model URL:" << getModelURL();
|
||||
}
|
||||
|
||||
void ModelEntityItem::setAnimationURL(const QString& url) {
|
||||
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE;
|
||||
_animationURL = url;
|
||||
}
|
||||
|
||||
void ModelEntityItem::setAnimationSettings(const QString& value) {
|
||||
// the animations setting is a JSON string that may contain various animation settings.
|
||||
// if it includes fps, frameIndex, or running, those values will be parsed out and
|
||||
|
@ -453,6 +453,17 @@ void ModelEntityItem::setAnimationSettings(const QString& value) {
|
|||
}
|
||||
|
||||
_animationSettings = value;
|
||||
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE;
|
||||
}
|
||||
|
||||
void ModelEntityItem::setAnimationIsPlaying(bool value) {
|
||||
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE;
|
||||
_animationLoop.setRunning(value);
|
||||
}
|
||||
|
||||
void ModelEntityItem::setAnimationFPS(float value) {
|
||||
_dirtyFlags |= EntityItem::DIRTY_UPDATEABLE;
|
||||
_animationLoop.setFPS(value);
|
||||
}
|
||||
|
||||
QString ModelEntityItem::getAnimationSettings() const {
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
EntityPropertyFlags& propertyFlags, bool overwriteLocalData);
|
||||
|
||||
virtual void update(const quint64& now);
|
||||
virtual SimulationState computeSimulationState() const;
|
||||
virtual bool needsToCallUpdate() const;
|
||||
virtual void debugDump() const;
|
||||
|
||||
|
||||
|
@ -73,16 +73,16 @@ public:
|
|||
|
||||
// model related properties
|
||||
void setModelURL(const QString& url) { _modelURL = url; }
|
||||
void setAnimationURL(const QString& url) { _animationURL = url; }
|
||||
void setAnimationURL(const QString& url);
|
||||
static const float DEFAULT_ANIMATION_FRAME_INDEX;
|
||||
void setAnimationFrameIndex(float value) { _animationLoop.setFrameIndex(value); }
|
||||
void setAnimationSettings(const QString& value);
|
||||
|
||||
static const bool DEFAULT_ANIMATION_IS_PLAYING;
|
||||
void setAnimationIsPlaying(bool value) { _animationLoop.setRunning(value); }
|
||||
void setAnimationIsPlaying(bool value);
|
||||
|
||||
static const float DEFAULT_ANIMATION_FPS;
|
||||
void setAnimationFPS(float value) { _animationLoop.setFPS(value); }
|
||||
void setAnimationFPS(float value);
|
||||
|
||||
void setAnimationLoop(bool loop) { _animationLoop.setLoop(loop); }
|
||||
bool getAnimationLoop() const { return _animationLoop.getLoop(); }
|
||||
|
|
|
@ -49,9 +49,10 @@ MovingEntitiesOperator::~MovingEntitiesOperator() {
|
|||
}
|
||||
|
||||
|
||||
void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACube& oldCube, const AACube& newCube) {
|
||||
void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACube& newCube) {
|
||||
EntityTreeElement* oldContainingElement = _tree->getContainingElement(entity->getEntityItemID());
|
||||
AABox newCubeClamped = newCube.clamp(0.0f, 1.0f);
|
||||
AACube oldCube = entity->getOldMaximumAACube();
|
||||
AABox oldCubeClamped = oldCube.clamp(0.0f, 1.0f);
|
||||
|
||||
if (_wantDebug) {
|
||||
|
@ -290,3 +291,9 @@ OctreeElement* MovingEntitiesOperator::possiblyCreateChildAt(OctreeElement* elem
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void MovingEntitiesOperator::finish() {
|
||||
foreach(const EntityToMoveDetails& details, _entitiesToMove) {
|
||||
details.entity->setOldMaximumAACube(details.newCube);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,11 +38,12 @@ public:
|
|||
MovingEntitiesOperator(EntityTree* tree);
|
||||
~MovingEntitiesOperator();
|
||||
|
||||
void addEntityToMoveList(EntityItem* entity, const AACube& oldCube, const AACube& newCube);
|
||||
void addEntityToMoveList(EntityItem* entity, const AACube& newCube);
|
||||
virtual bool preRecursion(OctreeElement* element);
|
||||
virtual bool postRecursion(OctreeElement* element);
|
||||
virtual OctreeElement* possiblyCreateChildAt(OctreeElement* element, int childIndex);
|
||||
bool hasMovingEntities() const { return _entitiesToMove.size() > 0; }
|
||||
void finish();
|
||||
private:
|
||||
EntityTree* _tree;
|
||||
QSet<EntityToMoveDetails> _entitiesToMove;
|
||||
|
|
|
@ -9,216 +9,58 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <AACube.h>
|
||||
#include <PerfStat.h>
|
||||
//#include <PerfStat.h>
|
||||
|
||||
#include "EntityItem.h"
|
||||
#include "MovingEntitiesOperator.h"
|
||||
#include "SimpleEntitySimulation.h"
|
||||
|
||||
void SimpleEntitySimulation::update(QSet<EntityItem*>& entitiesToDelete) {
|
||||
quint64 now = usecTimestampNow();
|
||||
updateChangedEntities(now, entitiesToDelete);
|
||||
updateMovingEntities(now, entitiesToDelete);
|
||||
updateMortalEntities(now, entitiesToDelete);
|
||||
}
|
||||
|
||||
void SimpleEntitySimulation::addEntity(EntityItem* entity) {
|
||||
assert(entity && entity->getSimulationState() == EntityItem::Static);
|
||||
EntityItem::SimulationState state = entity->computeSimulationState();
|
||||
switch(state) {
|
||||
case EntityItem::Moving:
|
||||
_movingEntities.push_back(entity);
|
||||
entity->setSimulationState(state);
|
||||
break;
|
||||
case EntityItem::Mortal:
|
||||
_mortalEntities.push_back(entity);
|
||||
entity->setSimulationState(state);
|
||||
break;
|
||||
case EntityItem::Static:
|
||||
default:
|
||||
break;
|
||||
void SimpleEntitySimulation::updateEntitiesInternal(const quint64& now) {
|
||||
QSet<EntityItem*>::iterator itemItr = _movingEntities.begin();
|
||||
while (itemItr != _movingEntities.end()) {
|
||||
EntityItem* entity = *itemItr;
|
||||
if (!entity->isMoving()) {
|
||||
itemItr = _movingEntities.erase(itemItr);
|
||||
_movableButStoppedEntities.insert(entity);
|
||||
} else {
|
||||
entity->simulate(now);
|
||||
_entitiesToBeSorted.insert(entity);
|
||||
++itemItr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleEntitySimulation::removeEntity(EntityItem* entity) {
|
||||
assert(entity);
|
||||
// make sure to remove it from any of our simulation lists
|
||||
EntityItem::SimulationState state = entity->getSimulationState();
|
||||
switch (state) {
|
||||
case EntityItem::Moving:
|
||||
_movingEntities.removeAll(entity);
|
||||
break;
|
||||
case EntityItem::Mortal:
|
||||
_mortalEntities.removeAll(entity);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
void SimpleEntitySimulation::addEntityInternal(EntityItem* entity) {
|
||||
if (entity->isMoving()) {
|
||||
_movingEntities.insert(entity);
|
||||
} else if (entity->getCollisionsWillMove()) {
|
||||
_movableButStoppedEntities.insert(entity);
|
||||
}
|
||||
entity->setSimulationState(EntityItem::Static);
|
||||
_changedEntities.remove(entity);
|
||||
}
|
||||
|
||||
void SimpleEntitySimulation::entityChanged(EntityItem* entity) {
|
||||
assert(entity);
|
||||
// we batch all changes and deal with them in updateChangedEntities()
|
||||
_changedEntities.insert(entity);
|
||||
void SimpleEntitySimulation::removeEntityInternal(EntityItem* entity) {
|
||||
_movingEntities.remove(entity);
|
||||
_movableButStoppedEntities.remove(entity);
|
||||
}
|
||||
|
||||
void SimpleEntitySimulation::clearEntities() {
|
||||
foreach (EntityItem* entity, _changedEntities) {
|
||||
entity->clearUpdateFlags();
|
||||
entity->setSimulationState(EntityItem::Static);
|
||||
const int SIMPLE_SIMULATION_DIRTY_FLAGS = EntityItem::DIRTY_VELOCITY | EntityItem::DIRTY_MOTION_TYPE;
|
||||
|
||||
void SimpleEntitySimulation::entityChangedInternal(EntityItem* entity) {
|
||||
int dirtyFlags = entity->getDirtyFlags();
|
||||
if (dirtyFlags & SIMPLE_SIMULATION_DIRTY_FLAGS) {
|
||||
if (entity->isMoving()) {
|
||||
_movingEntities.insert(entity);
|
||||
} else if (entity->getCollisionsWillMove()) {
|
||||
_movableButStoppedEntities.remove(entity);
|
||||
} else {
|
||||
_movingEntities.remove(entity);
|
||||
_movableButStoppedEntities.remove(entity);
|
||||
}
|
||||
}
|
||||
_changedEntities.clear();
|
||||
}
|
||||
|
||||
void SimpleEntitySimulation::clearEntitiesInternal() {
|
||||
_movingEntities.clear();
|
||||
_mortalEntities.clear();
|
||||
}
|
||||
|
||||
void SimpleEntitySimulation::updateChangedEntities(quint64 now, QSet<EntityItem*>& entitiesToDelete) {
|
||||
foreach (EntityItem* entity, _changedEntities) {
|
||||
// check to see if the lifetime has expired, for immortal entities this is always false
|
||||
if (entity->lifetimeHasExpired()) {
|
||||
qDebug() << "Lifetime has expired for entity:" << entity->getEntityItemID();
|
||||
entitiesToDelete.insert(entity);
|
||||
clearEntityState(entity);
|
||||
} else {
|
||||
updateEntityState(entity);
|
||||
}
|
||||
entity->clearUpdateFlags();
|
||||
}
|
||||
_changedEntities.clear();
|
||||
_movableButStoppedEntities.clear();
|
||||
}
|
||||
|
||||
void SimpleEntitySimulation::updateMovingEntities(quint64 now, QSet<EntityItem*>& entitiesToDelete) {
|
||||
if (_entityTree && _movingEntities.size() > 0) {
|
||||
PerformanceTimer perfTimer("_movingEntities");
|
||||
MovingEntitiesOperator moveOperator(_entityTree);
|
||||
QList<EntityItem*>::iterator item_itr = _movingEntities.begin();
|
||||
while (item_itr != _movingEntities.end()) {
|
||||
EntityItem* entity = *item_itr;
|
||||
|
||||
// always check to see if the lifetime has expired, for immortal entities this is always false
|
||||
if (entity->lifetimeHasExpired()) {
|
||||
qDebug() << "Lifetime has expired for entity:" << entity->getEntityItemID();
|
||||
entitiesToDelete.insert(entity);
|
||||
// remove entity from the list
|
||||
item_itr = _movingEntities.erase(item_itr);
|
||||
entity->setSimulationState(EntityItem::Static);
|
||||
} else {
|
||||
AACube oldCube = entity->getMaximumAACube();
|
||||
entity->update(now);
|
||||
AACube newCube = entity->getMaximumAACube();
|
||||
|
||||
// check to see if this movement has sent the entity outside of the domain.
|
||||
AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), 1.0f);
|
||||
if (!domainBounds.touches(newCube)) {
|
||||
qDebug() << "Entity " << entity->getEntityItemID() << " moved out of domain bounds.";
|
||||
entitiesToDelete.insert(entity);
|
||||
// remove entity from the list
|
||||
item_itr = _movingEntities.erase(item_itr);
|
||||
entity->setSimulationState(EntityItem::Static);
|
||||
} else {
|
||||
moveOperator.addEntityToMoveList(entity, oldCube, newCube);
|
||||
EntityItem::SimulationState newState = entity->computeSimulationState();
|
||||
if (newState != EntityItem::Moving) {
|
||||
if (newState == EntityItem::Mortal) {
|
||||
_mortalEntities.push_back(entity);
|
||||
}
|
||||
// remove entity from the list
|
||||
item_itr = _movingEntities.erase(item_itr);
|
||||
entity->setSimulationState(newState);
|
||||
} else {
|
||||
++item_itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (moveOperator.hasMovingEntities()) {
|
||||
PerformanceTimer perfTimer("recurseTreeWithOperator");
|
||||
_entityTree->recurseTreeWithOperator(&moveOperator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleEntitySimulation::updateMortalEntities(quint64 now, QSet<EntityItem*>& entitiesToDelete) {
|
||||
QList<EntityItem*>::iterator item_itr = _mortalEntities.begin();
|
||||
while (item_itr != _mortalEntities.end()) {
|
||||
EntityItem* entity = *item_itr;
|
||||
// always check to see if the lifetime has expired, for immortal entities this is always false
|
||||
if (entity->lifetimeHasExpired()) {
|
||||
qDebug() << "Lifetime has expired for entity:" << entity->getEntityItemID();
|
||||
entitiesToDelete.insert(entity);
|
||||
// remove entity from the list
|
||||
item_itr = _mortalEntities.erase(item_itr);
|
||||
entity->setSimulationState(EntityItem::Static);
|
||||
} else {
|
||||
// check to see if this entity is no longer moving
|
||||
EntityItem::SimulationState newState = entity->computeSimulationState();
|
||||
if (newState != EntityItem::Mortal) {
|
||||
if (newState == EntityItem::Moving) {
|
||||
entity->update(now);
|
||||
_movingEntities.push_back(entity);
|
||||
}
|
||||
// remove entity from the list
|
||||
item_itr = _mortalEntities.erase(item_itr);
|
||||
entity->setSimulationState(newState);
|
||||
} else {
|
||||
++item_itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleEntitySimulation::updateEntityState(EntityItem* entity) {
|
||||
EntityItem::SimulationState oldState = entity->getSimulationState();
|
||||
EntityItem::SimulationState newState = entity->computeSimulationState();
|
||||
if (newState != oldState) {
|
||||
switch (oldState) {
|
||||
case EntityItem::Moving:
|
||||
_movingEntities.removeAll(entity);
|
||||
break;
|
||||
|
||||
case EntityItem::Mortal:
|
||||
_mortalEntities.removeAll(entity);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (newState) {
|
||||
case EntityItem::Moving:
|
||||
_movingEntities.push_back(entity);
|
||||
break;
|
||||
|
||||
case EntityItem::Mortal:
|
||||
_mortalEntities.push_back(entity);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
entity->setSimulationState(newState);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleEntitySimulation::clearEntityState(EntityItem* entity) {
|
||||
EntityItem::SimulationState oldState = entity->getSimulationState();
|
||||
switch (oldState) {
|
||||
case EntityItem::Moving:
|
||||
_movingEntities.removeAll(entity);
|
||||
break;
|
||||
|
||||
case EntityItem::Mortal:
|
||||
_mortalEntities.removeAll(entity);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
entity->setSimulationState(EntityItem::Static);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,29 +19,17 @@
|
|||
class SimpleEntitySimulation : public EntitySimulation {
|
||||
public:
|
||||
SimpleEntitySimulation() : EntitySimulation() { }
|
||||
virtual ~SimpleEntitySimulation() { setEntityTree(NULL); }
|
||||
|
||||
virtual void update(QSet<EntityItem*>& entitiesToDelete);
|
||||
|
||||
virtual void addEntity(EntityItem* entity);
|
||||
virtual void removeEntity(EntityItem* entity);
|
||||
virtual void entityChanged(EntityItem* entity);
|
||||
|
||||
virtual void clearEntities();
|
||||
virtual ~SimpleEntitySimulation() { clearEntitiesInternal(); }
|
||||
|
||||
protected:
|
||||
void updateEntityState(EntityItem* entity);
|
||||
void clearEntityState(EntityItem* entity);
|
||||
virtual void updateEntitiesInternal(const quint64& now);
|
||||
virtual void addEntityInternal(EntityItem* entity);
|
||||
virtual void removeEntityInternal(EntityItem* entity);
|
||||
virtual void entityChangedInternal(EntityItem* entity);
|
||||
virtual void clearEntitiesInternal();
|
||||
|
||||
QList<EntityItem*>& getMovingEntities() { return _movingEntities; }
|
||||
|
||||
void updateChangedEntities(quint64 now, QSet<EntityItem*>& entitiesToDelete);
|
||||
void updateMovingEntities(quint64 now, QSet<EntityItem*>& entitiesToDelete);
|
||||
void updateMortalEntities(quint64 now, QSet<EntityItem*>& entitiesToDelete);
|
||||
|
||||
QSet<EntityItem*> _changedEntities; // entities that have changed in the last frame
|
||||
QList<EntityItem*> _movingEntities; // entities that need to be updated
|
||||
QList<EntityItem*> _mortalEntities; // non-moving entities that need to be checked for expiry
|
||||
QSet<EntityItem*> _movingEntities;
|
||||
QSet<EntityItem*> _movableButStoppedEntities;
|
||||
};
|
||||
|
||||
#endif // hifi_SimpleEntitySimulation_h
|
||||
|
|
|
@ -10,9 +10,12 @@
|
|||
//
|
||||
|
||||
|
||||
#include <glm/gtx/transform.hpp>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <ByteCountCoding.h>
|
||||
#include <GeometryUtil.h>
|
||||
|
||||
#include "EntityTree.h"
|
||||
#include "EntityTreeElement.h"
|
||||
|
@ -96,19 +99,25 @@ void SphereEntityItem::recalculateCollisionShape() {
|
|||
|
||||
bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const {
|
||||
|
||||
// NOTE: origin and direction are in tree units. But our _sphereShape is in meters, so we need to
|
||||
// do a little math to make these match each other.
|
||||
RayIntersectionInfo rayInfo;
|
||||
rayInfo._rayStart = origin * (float)TREE_SCALE;
|
||||
rayInfo._rayDirection = direction;
|
||||
void** intersectedObject, bool precisionPicking) const {
|
||||
// determine the ray in the frame of the entity transformed from a unit sphere
|
||||
glm::mat4 translation = glm::translate(getPosition());
|
||||
glm::mat4 rotation = glm::mat4_cast(getRotation());
|
||||
glm::mat4 scale = glm::scale(getDimensions());
|
||||
glm::mat4 registration = glm::translate(glm::vec3(0.5f, 0.5f, 0.5f) - getRegistrationPoint());
|
||||
glm::mat4 entityToWorldMatrix = translation * rotation * scale * registration;
|
||||
glm::mat4 worldToEntityMatrix = glm::inverse(entityToWorldMatrix);
|
||||
glm::vec3 entityFrameOrigin = glm::vec3(worldToEntityMatrix * glm::vec4(origin, 1.0f));
|
||||
glm::vec3 entityFrameDirection = glm::normalize(glm::vec3(worldToEntityMatrix * glm::vec4(direction, 1.0f)));
|
||||
|
||||
// TODO: Note this is really doing ray intersections against a sphere, which is fine except in cases
|
||||
// where our dimensions actually make us an ellipsoid. But we'll live with this for now until we
|
||||
// get a more full fledged physics library
|
||||
if (_sphereShape.findRayIntersection(rayInfo)) {
|
||||
distance = rayInfo._hitDistance / (float)TREE_SCALE;
|
||||
float localDistance;
|
||||
// NOTE: unit sphere has center of 0,0,0 and radius of 0.5
|
||||
if (findRaySphereIntersection(entityFrameOrigin, entityFrameDirection, glm::vec3(0.0f), 0.5f, localDistance)) {
|
||||
// determine where on the unit sphere the hit point occured
|
||||
glm::vec3 entityFrameHitAt = entityFrameOrigin + (entityFrameDirection * localDistance);
|
||||
// then translate back to work coordinates
|
||||
glm::vec3 hitAt = glm::vec3(entityToWorldMatrix * glm::vec4(entityFrameHitAt, 1.0f));
|
||||
distance = glm::distance(origin,hitAt);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -59,8 +59,8 @@ public:
|
|||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const;
|
||||
|
||||
void** intersectedObject, bool precisionPicking) const;
|
||||
|
||||
protected:
|
||||
virtual void recalculateCollisionShape();
|
||||
|
||||
|
|
|
@ -40,6 +40,13 @@ TextEntityItem::TextEntityItem(const EntityItemID& entityItemID, const EntityIte
|
|||
setProperties(properties, true);
|
||||
}
|
||||
|
||||
void TextEntityItem::setDimensions(const glm::vec3& value) {
|
||||
// NOTE: Text Entities always have a "depth" of 1cm.
|
||||
float fixedDepth = 0.01f / (float)TREE_SCALE;
|
||||
_dimensions = glm::vec3(value.x, value.y, fixedDepth);
|
||||
recalculateCollisionShape();
|
||||
}
|
||||
|
||||
EntityItemProperties TextEntityItem::getProperties() const {
|
||||
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
|
||||
|
||||
|
@ -118,7 +125,7 @@ void TextEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits
|
|||
|
||||
bool TextEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const {
|
||||
void** intersectedObject, bool precisionPicking) const {
|
||||
|
||||
RayIntersectionInfo rayInfo;
|
||||
rayInfo._rayStart = origin;
|
||||
|
|
|
@ -21,6 +21,9 @@ public:
|
|||
TextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
|
||||
|
||||
ALLOW_INSTANTIATION // This class can be instantiated
|
||||
|
||||
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
|
||||
virtual void setDimensions(const glm::vec3& value);
|
||||
|
||||
// methods for getting/setting all properties of an entity
|
||||
virtual EntityItemProperties getProperties() const;
|
||||
|
@ -44,7 +47,7 @@ public:
|
|||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const;
|
||||
void** intersectedObject, bool precisionPicking) const;
|
||||
|
||||
static const QString DEFAULT_TEXT;
|
||||
void setText(const QString& value) { _text = value; }
|
||||
|
|
|
@ -2044,6 +2044,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
|||
|
||||
extracted.mesh.meshExtents.minimum = glm::min(extracted.mesh.meshExtents.minimum, transformedVertex);
|
||||
extracted.mesh.meshExtents.maximum = glm::max(extracted.mesh.meshExtents.maximum, transformedVertex);
|
||||
extracted.mesh.modelTransform = modelTransform;
|
||||
}
|
||||
|
||||
// look for textures, material properties
|
||||
|
|
|
@ -149,6 +149,7 @@ public:
|
|||
QVector<FBXCluster> clusters;
|
||||
|
||||
Extents meshExtents;
|
||||
glm::mat4 modelTransform;
|
||||
|
||||
bool isEye;
|
||||
|
||||
|
|
46
libraries/gpu/CMakeLists.txt
Normal file
46
libraries/gpu/CMakeLists.txt
Normal file
|
@ -0,0 +1,46 @@
|
|||
set(TARGET_NAME gpu)
|
||||
|
||||
# use setup_hifi_library macro to setup our project and link appropriate Qt modules
|
||||
setup_hifi_library()
|
||||
|
||||
include_glm()
|
||||
|
||||
link_hifi_libraries(shared)
|
||||
if (APPLE)
|
||||
# link in required OS X frameworks and include the right GL headers
|
||||
find_library(OpenGL OpenGL)
|
||||
|
||||
target_link_libraries(${TARGET_NAME} ${OpenGL})
|
||||
|
||||
else (APPLE)
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
if (${OPENGL_INCLUDE_DIR})
|
||||
include_directories(SYSTEM "${OPENGL_INCLUDE_DIR}")
|
||||
endif ()
|
||||
|
||||
target_link_libraries(${TARGET_NAME} "${OPENGL_LIBRARY}")
|
||||
|
||||
# link target to external libraries
|
||||
if (WIN32)
|
||||
find_package(GLEW REQUIRED)
|
||||
include_directories(${GLEW_INCLUDE_DIRS})
|
||||
|
||||
# we're using static GLEW, so define GLEW_STATIC
|
||||
add_definitions(-DGLEW_STATIC)
|
||||
|
||||
target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" opengl32.lib)
|
||||
|
||||
# try to find the Nsight package and add it to the build if we find it
|
||||
find_package(NSIGHT)
|
||||
if (NSIGHT_FOUND)
|
||||
include_directories(${NSIGHT_INCLUDE_DIRS})
|
||||
add_definitions(-DNSIGHT_FOUND)
|
||||
target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}")
|
||||
endif ()
|
||||
|
||||
endif()
|
||||
endif (APPLE)
|
||||
|
||||
# call macro to link our dependencies and bubble them up via a property on our target
|
||||
link_shared_dependencies()
|
|
@ -12,13 +12,13 @@
|
|||
#define hifi_gpu_Batch_h
|
||||
|
||||
#include <assert.h>
|
||||
#include "InterfaceConfig.h"
|
||||
#include "GPUConfig.h"
|
||||
|
||||
#include "Transform.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "gpu/Stream.h"
|
||||
#include "Stream.h"
|
||||
|
||||
#if defined(NSIGHT_FOUND)
|
||||
#include "nvToolsExt.h"
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue