mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 20:56:25 +02:00
64 lines
2.6 KiB
JavaScript
64 lines
2.6 KiB
JavaScript
//
|
|
// addVoxelOnMouseClickExample.js
|
|
// examples
|
|
//
|
|
// Created by Brad Hefta-Gaub on 2/6/14.
|
|
// Copyright 2014 High Fidelity, Inc.
|
|
//
|
|
// This is an example script that demonstrates use of the Camera and Voxels class to implement
|
|
// clicking on a voxel and adding a new voxel on the clicked on face
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
|
|
function mousePressEvent(event) {
|
|
print("mousePressEvent event.x,y=" + event.x + ", " + event.y);
|
|
var pickRay = Camera.computePickRay(event.x, event.y);
|
|
var intersection = Voxels.findRayIntersection(pickRay);
|
|
if (intersection.intersects) {
|
|
|
|
// Note: due to the current C++ "click on voxel" behavior, these values may be the animated color for the voxel
|
|
print("clicked on voxel.red/green/blue=" + intersection.voxel.red + ", "
|
|
+ intersection.voxel.green + ", " + intersection.voxel.blue);
|
|
print("clicked on voxel.x/y/z/s=" + intersection.voxel.x + ", "
|
|
+ intersection.voxel.y + ", " + intersection.voxel.z+ ": " + intersection.voxel.s);
|
|
print("clicked on face=" + intersection.face);
|
|
print("clicked on distance=" + intersection.distance);
|
|
|
|
var newVoxel = {
|
|
x: intersection.voxel.x,
|
|
y: intersection.voxel.y,
|
|
z: intersection.voxel.z,
|
|
s: intersection.voxel.s,
|
|
red: 255,
|
|
green: 0,
|
|
blue: 255 };
|
|
|
|
if (intersection.face == "MIN_X_FACE") {
|
|
newVoxel.x -= newVoxel.s;
|
|
} else if (intersection.face == "MAX_X_FACE") {
|
|
newVoxel.x += newVoxel.s;
|
|
} else if (intersection.face == "MIN_Y_FACE") {
|
|
newVoxel.y -= newVoxel.s;
|
|
} else if (intersection.face == "MAX_Y_FACE") {
|
|
newVoxel.y += newVoxel.s;
|
|
} else if (intersection.face == "MIN_Z_FACE") {
|
|
newVoxel.z -= newVoxel.s;
|
|
} else if (intersection.face == "MAX_Z_FACE") {
|
|
newVoxel.z += newVoxel.s;
|
|
}
|
|
|
|
print("Voxels.setVoxel("+newVoxel.x + ", "
|
|
+ newVoxel.y + ", " + newVoxel.z + ", " + newVoxel.s + ", "
|
|
+ newVoxel.red + ", " + newVoxel.green + ", " + newVoxel.blue + ")" );
|
|
|
|
Voxels.setVoxel(newVoxel.x, newVoxel.y, newVoxel.z, newVoxel.s, newVoxel.red, newVoxel.green, newVoxel.blue);
|
|
}
|
|
}
|
|
|
|
Controller.mousePressEvent.connect(mousePressEvent);
|
|
|
|
function scriptEnding() {
|
|
}
|
|
Script.scriptEnding.connect(scriptEnding);
|