107 lines
No EOL
3.2 KiB
JavaScript
107 lines
No EOL
3.2 KiB
JavaScript
(function() {
|
|
|
|
// subscribe
|
|
var channels = "abc".split("").map(function(chan){return "com.henkel."+chan});
|
|
channels.forEach(function(chan) {
|
|
Messages.subscribe(chan);
|
|
});
|
|
|
|
// receive messages
|
|
function onMessageReceived(chan, msg) {
|
|
var json = undefined;
|
|
try { json = JSON.parse(msg);
|
|
} catch(err) { return; }
|
|
|
|
switch (json.position) {
|
|
case "card":
|
|
// update selected entity
|
|
var selectedEntityID = Entities.findEntitiesByName(
|
|
json.room+"_"+json.type+"_selected",
|
|
{x:0,y:0,z:0}, 100
|
|
)[0];
|
|
if (!selectedEntityID) return;
|
|
|
|
var selectedEntity = Entities.getEntityProperties(selectedEntityID, ["dimensions"]);
|
|
Entities.editEntity(selectedEntityID, {
|
|
modelURL: json.modelURL,
|
|
dimensions: {
|
|
x: selectedEntity.dimensions.x,
|
|
y: selectedEntity.dimensions.y,
|
|
z: 0.0011,
|
|
}
|
|
});
|
|
|
|
// weird dimensions bug
|
|
Script.setTimeout(function() {
|
|
Entities.editEntity(selectedEntityID, {
|
|
dimensions: {
|
|
x: selectedEntity.dimensions.x,
|
|
y: selectedEntity.dimensions.y,
|
|
z: 0.001,
|
|
}
|
|
});
|
|
}, 100);
|
|
break;
|
|
case "workmat":
|
|
var selectedEntityID = Entities.findEntitiesByName(
|
|
json.room+"_"+json.type+"_selected",
|
|
{x:0,y:0,z:0}, 100
|
|
)[0];
|
|
if (!selectedEntityID) return;
|
|
|
|
var selectedEntity = Entities.getEntityProperties(selectedEntityID, ["modelURL", "originalTextures"]);
|
|
var selectedFilename = selectedEntity.modelURL.split("/").pop();
|
|
var selectedResults = new RegExp(/([ABC])_(value|function)(.*?)_(card|workmat)(?:_[A-Z]|)\.fbx/).exec(selectedFilename);
|
|
|
|
if (json.room!=selectedResults[1]) return;
|
|
if (json.number!=selectedResults[3]) {
|
|
console.log("Incorrect!");
|
|
return;
|
|
}
|
|
|
|
// spawn on top of workmat
|
|
// var onTopWorkmatID = Entities.cloneEntity(selectedEntityID);
|
|
// Script.setTimeout(function() {
|
|
// Entities.editEntity(onTopWorkmatID, {
|
|
// name: "Clone",
|
|
// position: Vec3.sum(json.workmat.position, {x:0,y:0.02,z:0}),
|
|
// rotation: json.workmat.rotation,
|
|
// dimensions: json.workmat.dimensions,
|
|
// collisionless: true,
|
|
// userData: "{\"grabbableKey\":{\"grabbable\":false}}",
|
|
// lifetime: -1
|
|
// });
|
|
// }, 100);
|
|
Entities.addEntity({
|
|
type: "Model",
|
|
name: "Clone",
|
|
modelURL: selectedEntity.modelURL,
|
|
position: Vec3.sum(json.workmat.position, {x:0,y:0.01,z:0}),
|
|
rotation: Quat.multiply(json.workmat.rotation, Quat.fromPitchYawRollDegrees(90,0,0)),
|
|
dimensions: {
|
|
x: json.workmat.dimensions.x,
|
|
y: json.workmat.dimensions.z,
|
|
z: json.workmat.dimensions.y,
|
|
},
|
|
originalTextures: selectedEntity.originalTextures,
|
|
collisionless: true,
|
|
userData: "{\"grabbableKey\":{\"grabbable\":false}}",
|
|
lifetime: -1,
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
|
|
Messages.messageReceived.connect(onMessageReceived);
|
|
|
|
// script ending
|
|
//Script.scriptEnding.connect(function() {
|
|
// Script.setTimeout(function() {
|
|
// console.log("unloading");
|
|
// Messages.messageReceived.disconnect(onMessageReceived);
|
|
// channels.forEach(function(chan) {
|
|
// Messages.unsubscribe(chan);
|
|
// });
|
|
// }, 1000*30);
|
|
|
|
}) |