mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-22 21:40:07 +02:00
attaching trigger box to base of lamp in living room
This commit is contained in:
parent
54e125871f
commit
aa4817ea26
2 changed files with 64 additions and 16 deletions
|
@ -255,6 +255,13 @@
|
||||||
z:-73.22
|
z:-73.22
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var livingRoomLampTriggerBoxName = "hifi-home-living-room-desk-lamp-trigger";
|
||||||
|
var livingRoomLampModelName = "hifi-home-model-bulldog-base";
|
||||||
|
Script.setTimeout(function() {
|
||||||
|
attachChildToParent(livingRoomLampTriggerBoxName, livingRoomLampModelName, MyAvatar.position, 20);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
findAndDeleteHomeEntities: function() {
|
findAndDeleteHomeEntities: function() {
|
||||||
|
@ -288,4 +295,4 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
return new Reset();
|
return new Reset();
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,14 +11,18 @@ map = function(value, min1, max1, min2, max2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3toStr = function(v, digits) {
|
vec3toStr = function(v, digits) {
|
||||||
if (!digits) { digits = 3; }
|
if (!digits) {
|
||||||
return "{ " + v.x.toFixed(digits) + ", " + v.y.toFixed(digits) + ", " + v.z.toFixed(digits)+ " }";
|
digits = 3;
|
||||||
|
}
|
||||||
|
return "{ " + v.x.toFixed(digits) + ", " + v.y.toFixed(digits) + ", " + v.z.toFixed(digits) + " }";
|
||||||
}
|
}
|
||||||
|
|
||||||
quatToStr = function(q, digits) {
|
quatToStr = function(q, digits) {
|
||||||
if (!digits) { digits = 3; }
|
if (!digits) {
|
||||||
|
digits = 3;
|
||||||
|
}
|
||||||
return "{ " + q.w.toFixed(digits) + ", " + q.x.toFixed(digits) + ", " +
|
return "{ " + q.w.toFixed(digits) + ", " + q.x.toFixed(digits) + ", " +
|
||||||
q.y.toFixed(digits) + ", " + q.z.toFixed(digits)+ " }";
|
q.y.toFixed(digits) + ", " + q.z.toFixed(digits) + " }";
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3equal = function(v0, v1) {
|
vec3equal = function(v0, v1) {
|
||||||
|
@ -33,7 +37,7 @@ colorMix = function(colorA, colorB, mix) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
scaleLine = function (start, end, scale) {
|
scaleLine = function(start, end, scale) {
|
||||||
var v = Vec3.subtract(end, start);
|
var v = Vec3.subtract(end, start);
|
||||||
var length = Vec3.length(v);
|
var length = Vec3.length(v);
|
||||||
v = Vec3.multiply(scale, v);
|
v = Vec3.multiply(scale, v);
|
||||||
|
@ -61,7 +65,9 @@ addLine = function(origin, vector, color) {
|
||||||
// FIXME fetch from a subkey of user data to support non-destructive modifications
|
// FIXME fetch from a subkey of user data to support non-destructive modifications
|
||||||
setEntityUserData = function(id, data) {
|
setEntityUserData = function(id, data) {
|
||||||
var json = JSON.stringify(data)
|
var json = JSON.stringify(data)
|
||||||
Entities.editEntity(id, { userData: json });
|
Entities.editEntity(id, {
|
||||||
|
userData: json
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME do non-destructive modification of the existing user data
|
// FIXME do non-destructive modification of the existing user data
|
||||||
|
@ -71,7 +77,7 @@ getEntityUserData = function(id) {
|
||||||
if (properties.userData) {
|
if (properties.userData) {
|
||||||
try {
|
try {
|
||||||
results = JSON.parse(properties.userData);
|
results = JSON.parse(properties.userData);
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
logDebug(err);
|
logDebug(err);
|
||||||
logDebug(properties.userData);
|
logDebug(properties.userData);
|
||||||
}
|
}
|
||||||
|
@ -169,7 +175,7 @@ findSphereHit = function(point, sphereRadius) {
|
||||||
}
|
}
|
||||||
|
|
||||||
findSpherePointHit = function(sphereCenter, sphereRadius, point) {
|
findSpherePointHit = function(sphereCenter, sphereRadius, point) {
|
||||||
return findSphereHit(Vec3.subtract(point,sphereCenter), sphereRadius);
|
return findSphereHit(Vec3.subtract(point, sphereCenter), sphereRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
findSphereSphereHit = function(firstCenter, firstRadius, secondCenter, secondRadius) {
|
findSphereSphereHit = function(firstCenter, firstRadius, secondCenter, secondRadius) {
|
||||||
|
@ -188,8 +194,8 @@ getAvatarRelativeRotation = function(q) {
|
||||||
|
|
||||||
pointInExtents = function(point, minPoint, maxPoint) {
|
pointInExtents = function(point, minPoint, maxPoint) {
|
||||||
return (point.x >= minPoint.x && point.x <= maxPoint.x) &&
|
return (point.x >= minPoint.x && point.x <= maxPoint.x) &&
|
||||||
(point.y >= minPoint.y && point.y <= maxPoint.y) &&
|
(point.y >= minPoint.y && point.y <= maxPoint.y) &&
|
||||||
(point.z >= minPoint.z && point.z <= maxPoint.z);
|
(point.z >= minPoint.z && point.z <= maxPoint.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -293,14 +299,49 @@ calculateHandSizeRatio = function() {
|
||||||
// Right now units are in cm, so convert to meters
|
// Right now units are in cm, so convert to meters
|
||||||
wristToFingertipDistance /= 100;
|
wristToFingertipDistance /= 100;
|
||||||
|
|
||||||
var centerHandPoint = wristToFingertipDistance/2;
|
var centerHandPoint = wristToFingertipDistance / 2;
|
||||||
|
|
||||||
// Compare against standard hand (Owen)
|
// Compare against standard hand (Owen)
|
||||||
var handSizeRatio = centerHandPoint/standardCenterHandPoint;
|
var handSizeRatio = centerHandPoint / standardCenterHandPoint;
|
||||||
return handSizeRatio;
|
return handSizeRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
clamp = function(val, min, max){
|
clamp = function(val, min, max) {
|
||||||
return Math.max(min, Math.min(max, val))
|
return Math.max(min, Math.min(max, val))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attachChildToParent = function(childName, parentName, position, searchRadius) {
|
||||||
|
var childEntity, parentEntity;
|
||||||
|
var entities = Entities.findEntities(position, searchRadius)
|
||||||
|
for (var i = 0; i < entities.length; i++) {
|
||||||
|
// first go through and find the entity we want to attach to its parent
|
||||||
|
var entity = entities[i];
|
||||||
|
var name = Entities.getEntityProperties(entity, "name").name;
|
||||||
|
if (name === childName) {
|
||||||
|
childEntity = entity;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!childEntity) {
|
||||||
|
print("You are trying to attach an entity that doesn't exist! Returning");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < entities.length; i++) {
|
||||||
|
// first go through and find the entity we want to attach to its parent
|
||||||
|
var entity = entities[i];
|
||||||
|
var name = Entities.getEntityProperties(entity, "name").name;
|
||||||
|
if (name === parentName) {
|
||||||
|
parentEntity = entity;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parentEntity) {
|
||||||
|
print("You are trying to attach an entity to a parent that doesn't exist! Returning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Successfully attached " + childName + " to " + parentName);
|
||||||
|
Entities.editEntity(childEntity, {parentID: parentEntity});
|
||||||
|
}
|
Loading…
Reference in a new issue