Skip to content

Instantly share code, notes, and snippets.

@SamGondelman
Last active May 17, 2019 03:16
Show Gist options
  • Save SamGondelman/df6f6c63bc8297a7d4a2dd439b72d8fb to your computer and use it in GitHub Desktop.
Save SamGondelman/df6f6c63bc8297a7d4a2dd439b72d8fb to your computer and use it in GitHub Desktop.
(function() { // BEGIN LOCAL_SCOPE
var entities = [];
function getPos(x, y) {
return Vec3.sum(MyAvatar.position, Vec3.sum(Vec3.multiply(x, Quat.getRight(MyAvatar.orientation)),
Vec3.sum(Vec3.multiply(y, Quat.getUp(MyAvatar.orientation)),
Vec3.multiply(3, Quat.getForward(MyAvatar.orientation)))));
}
entities.push(Entities.addEntity({
type: "Material",
materialURL: "materialData",
priority: 1,
parentMaterialName: "0",
position: getPos(-0.5, 1),
materialData: JSON.stringify({
materials: {
"model": "hifi_shader_simple",
"procedural": {
"version": 2,
"fragmentShaderURL": "https://gist.githubusercontent.com/SamGondelman/0f0bc47a1113bfe0dee0996bd43acc79/raw/009f804ea9f033e96c9a7ea4b768193b77ba587e/proceduralMaterialTestNormal.fs"
}
}
})
}));
entities.push(Entities.addEntity({
type: "Sphere",
position: getPos(-1, 0),
dimensions: 0.5,
rotation: MyAvatar.orientation
}));
entities.push(Entities.addEntity({
type: "Model",
modelURL: "qrc:////meshes/mannequin/mannequin.baked.fbx",
position: getPos(0, 0),
rotation: MyAvatar.orientation
}));
entities.push(Entities.addEntity({
type: "Model",
modelURL: "qrc:////meshes/tablet-with-home-button-small-bezel.fbx",
position: getPos(1, 0),
rotation: Quat.multiply(MyAvatar.orientation, Quat.fromPitchYawRollDegrees(0, 180, 0))
}));
var index = 0;
var parent = [entities[entities.length - 3], entities[entities.length - 2], entities[entities.length - 1], MyAvatar.SELF_ID, Uuid.NULL ];
var parentMaterialName = ["0", "0", "[0, 9]", "all", ""];
Controller.keyPressEvent.connect(function(event) {
if (event.text === 'u') {
for (var i = 0; i < 1; i++) {
Entities.editEntity(entities[i], {
parentID: parent[index],
parentMaterialName: parentMaterialName[index]
});
}
index = (index + 1) % parent.length;
}
})
Script.scriptEnding.connect(function() {
for (var i = 0; i < entities.length; i++) {
Entities.deleteEntity(entities[i]);
}
});
}()); // END LOCAL_SCOPE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment