Skip to content

Instantly share code, notes, and snippets.

@SamGondelman
Created May 1, 2019 18:49
Show Gist options
  • Save SamGondelman/f18015d6dcf95c3cdf4eb02f5bc515fa to your computer and use it in GitHub Desktop.
Save SamGondelman/f18015d6dcf95c3cdf4eb02f5bc515fa to your computer and use it in GitHub Desktop.
(function() { // BEGIN LOCAL_SCOPE
var entities = [];
function getPos(x, y) {
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(6, Quat.getFront(MyAvatar.orientation)));
return Vec3.sum(Vec3.sum(center, Vec3.multiply(Quat.getRight(MyAvatar.orientation), x)), Vec3.multiply(Quat.getUp(MyAvatar.orientation), y));
}
entities.push(Entities.addEntity({
type: "Box",
position: getPos(-5, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
color: "red"
}));
entities.push(Entities.addEntity({
type: "Model",
modelURL: "http://mpassets.highfidelity.com/ad348528-de38-420c-82bb-054cb22163f5-v1/mannequin.fst",
position: getPos(-4, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
groupCulled: false
}));
entities.push(Entities.addEntity({
type: "Model",
modelURL: "http://mpassets.highfidelity.com/ad348528-de38-420c-82bb-054cb22163f5-v1/mannequin.fst",
position: getPos(-4, 2),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
groupCulled: true
}));
entities.push(Entities.addEntity({
type: "Text",
text: "text",
position: getPos(-3, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
textColor: "blue",
backgroundColor: "red"
}));
entities.push(Entities.addEntity({
type: "Image",
position: getPos(-2, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
imageURL: "https://hifi-content.s3.amazonaws.com/DomainContent/production/no-image.jpg",
keepAspectRatio: false,
color: "red"
}));
entities.push(Entities.addEntity({
type: "Web",
position: getPos(-1, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
color: "red"
}));
entities.push(Entities.addEntity({
type: "ParticleEffect",
position: getPos(0, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
textures: "https://content.highfidelity.com/DomainContent/production/Particles/wispy-smoke.png",
particleRadius: 0.5,
emitSpeed: 0.0,
speedSpread: 0.0,
emitRate: 10,
emitAcceleration: 0.0
}));
entities.push(Entities.addEntity({
type: "PolyLine",
position: getPos(1, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
linePoints: [
{x: -0.5, y: 0.5, z: 0.0},
{x: 0.0, y: -0.5, z: 0.0},
{x: 0.5, y: 0.5, z: 0.0}
],
normals: [
{ x: 0, y: 0, z: 1 },
{ x: 0, y: 0, z: 1 },
{ x: 0, y: 0, z: 1 }
],
strokeWidths: [ 0.25, 0.25, 0.25 ],
color: "red"
}));
entities.push(Entities.addEntity({
type: "PolyVox",
position: getPos(2, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
voxelVolumeSize: { x: 16, y: 16, z: 16 },
voxelSurfaceStyle: 0,
xTextureURL: "http://headache.hungry.com/~seth/hifi/dirt.jpeg",
yTextureURL: "http://headache.hungry.com/~seth/hifi/grass.png",
zTextureURL: "http://headache.hungry.com/~seth/hifi/dirt.jpeg"
}));
Entities.setAllVoxels(entities[entities.length - 1], 255);
entities.push(Entities.addEntity({
type: "Grid",
position: getPos(3, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
followCamera: false,
minorGridEvery: 0.1,
majorGridEvery: 5
}));
entities.push(Entities.addEntity({
type: "Gizmo",
position: getPos(4, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
gizmoType: "ring",
ring: {
innerRadius: 0.5,
innerStartColor: "red",
innerEndColor: "red",
outerStartColor: "red",
outerEndColor: "red",
}
}));
entities.push(Entities.addEntity({
type: "Material",
position: getPos(5, 1),
rotation: MyAvatar.orientation,
grab: { grabbable: false },
dimensions: 1.0,
materialURL: "https://hifi-content.s3.amazonaws.com/samuel/TestMaterial.json"
}));
var layers = [ "world", "front", "hud" ];
var layer = 0;
var billboardModes = [ "none", "yaw", "full" ];
var billboardMode = 0;
var primitiveModes = [ "solid", "lines" ];
var primitiveMode = 0;
var alpha = 1;
var parentID = undefined;
function keyPressEvent(event) {
if (event.text === 'o') {
layer = (layer + 1) % layers.length;
for (var i = 0; i < entities.length; i++) {
Entities.editEntity(entities[i], {
renderLayer: layers[layer]
});
}
} else if (event.text === 'i') {
billboardMode = (billboardMode + 1) % billboardModes.length;
for (var i = 0; i < entities.length; i++) {
Entities.editEntity(entities[i], {
billboardMode: billboardModes[billboardMode]
});
}
} else if (event.text === 'u') {
alpha = alpha == 1 ? 0.9 : 1;
for (var i = 0; i < entities.length; i++) {
Entities.editEntity(entities[i], {
alpha: alpha,
backgroundAlpha: alpha,
textAlpha: alpha,
ring: {
innerStartAlpha: alpha,
outerStartAlpha: alpha
}
});
}
} else if (event.text === 'y') {
primitiveMode = (primitiveMode + 1) % primitiveModes.length;
for (var i = 0; i < entities.length; i++) {
Entities.editEntity(entities[i], {
primitiveMode: primitiveModes[primitiveMode]
});
}
} else if (event.text === 'h') {
parentID = parentID === undefined ? MyAvatar.SELF_ID : undefined;
for (var i = 0; i < entities.length; i++) {
Entities.editEntity(entities[i], {
parentID: parentID
});
}
}
}
Controller.keyPressEvent.connect(keyPressEvent);
function cleanup() {
for (var i = 0; i < entities.length; i++) {
Entities.deleteEntity(entities[i]);
}
}
Script.scriptEnding.connect(cleanup);
}()); // END LOCAL_SCOPE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment