mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 05:24:06 +02:00
Update fuse and add collider
This commit is contained in:
parent
55586ccedb
commit
a6fadd2fa8
2 changed files with 105 additions and 4 deletions
|
@ -1,4 +1,38 @@
|
|||
(function() {
|
||||
var findEntity = function(properties, searchRadius, filterFn) {
|
||||
var entities = findEntities(properties, searchRadius, filterFn);
|
||||
return entities.length > 0 ? entities[0] : null;
|
||||
}
|
||||
|
||||
// Return all entities with properties `properties` within radius `searchRadius`
|
||||
var findEntities = function(properties, searchRadius, filterFn) {
|
||||
if (!filterFn) {
|
||||
filterFn = function(properties, key, value) {
|
||||
return value == properties[key];
|
||||
}
|
||||
}
|
||||
searchRadius = searchRadius ? searchRadius : 100000;
|
||||
var entities = Entities.findEntities({ x: 0, y: 0, z: 0 }, searchRadius);
|
||||
var matchedEntities = [];
|
||||
var keys = Object.keys(properties);
|
||||
for (var i = 0; i < entities.length; ++i) {
|
||||
var match = true;
|
||||
var candidateProperties = Entities.getEntityProperties(entities[i], keys);
|
||||
for (var key in properties) {
|
||||
if (!filterFn(properties, key, candidateProperties[key])) {
|
||||
// This isn't a match, move to next entity
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
matchedEntities.push(entities[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return matchedEntities;
|
||||
}
|
||||
|
||||
var fuseSound = SoundCache.getSound("https://hifi-content.s3.amazonaws.com/DomainContent/Tutorial/Sounds/fuse.wav");
|
||||
function getChildProperties(entityID, propertyNames) {
|
||||
var childEntityIDs = Entities.getChildrenIDs(entityID);
|
||||
|
@ -13,12 +47,18 @@
|
|||
var Fuse = function() {
|
||||
};
|
||||
Fuse.prototype = {
|
||||
onLit: function() {
|
||||
light: function() {
|
||||
print("LIT", this.entityID);
|
||||
var anim = Entities.getEntityProperties(this.entityID, ['animation']).animation;
|
||||
print("anim: ", anim.currentFrame, Object.keys(anim));
|
||||
|
||||
if (anim.currentFrame < 140) {
|
||||
return;
|
||||
}
|
||||
Entities.editEntity(this.entityID, {
|
||||
animation: {
|
||||
currentFrame: 0,
|
||||
//"lastFrame": 130,
|
||||
currentFrame: 1,
|
||||
lastFrame: 150,
|
||||
running: 1,
|
||||
url: "https://hifi-content.s3.amazonaws.com/ozan/dev/anim/fuse/fuse.fbx",
|
||||
loop: 0
|
||||
|
@ -47,7 +87,8 @@
|
|||
var self = this;
|
||||
Script.setTimeout(function() {
|
||||
print("BLOW UP");
|
||||
Entities.callEntityMethod("{dd13fcd5-616f-4749-ab28-2e1e8bc512e9}", "onLit");
|
||||
var spinnerID = findEntity({ name: "tutorial/equip/spinner" }, 20);
|
||||
Entities.callEntityMethod(spinnerID, "onLit");
|
||||
injector.stop();
|
||||
|
||||
var childrenProps = getChildProperties(self.entityID, ['type']);
|
||||
|
|
60
tutorial/fuseCollider.js
Normal file
60
tutorial/fuseCollider.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
(function() {
|
||||
var findEntity = function(properties, searchRadius, filterFn) {
|
||||
var entities = findEntities(properties, searchRadius, filterFn);
|
||||
return entities.length > 0 ? entities[0] : null;
|
||||
}
|
||||
|
||||
// Return all entities with properties `properties` within radius `searchRadius`
|
||||
var findEntities = function(properties, searchRadius, filterFn) {
|
||||
if (!filterFn) {
|
||||
filterFn = function(properties, key, value) {
|
||||
return value == properties[key];
|
||||
}
|
||||
}
|
||||
searchRadius = searchRadius ? searchRadius : 100000;
|
||||
var entities = Entities.findEntities({ x: 0, y: 0, z: 0 }, searchRadius);
|
||||
var matchedEntities = [];
|
||||
var keys = Object.keys(properties);
|
||||
for (var i = 0; i < entities.length; ++i) {
|
||||
var match = true;
|
||||
var candidateProperties = Entities.getEntityProperties(entities[i], keys);
|
||||
for (var key in properties) {
|
||||
if (!filterFn(properties, key, candidateProperties[key])) {
|
||||
// This isn't a match, move to next entity
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
matchedEntities.push(entities[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return matchedEntities;
|
||||
}
|
||||
|
||||
function getChildProperties(entityID, propertyNames) {
|
||||
var childEntityIDs = Entities.getChildrenIDs(entityID);
|
||||
var results = {}
|
||||
for (var i = 0; i < childEntityIDs.length; ++i) {
|
||||
var childEntityID = childEntityIDs[i];
|
||||
var properties = Entities.getEntityProperties(childEntityID, propertyNames);
|
||||
results[childEntityID] = properties;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
var Fuse = function() {
|
||||
};
|
||||
Fuse.prototype = {
|
||||
onLit: function() {
|
||||
print("LIT", this.entityID);
|
||||
var fuseID = findEntity({ name: "tutorial/equip/fuse" }, 20);
|
||||
Entities.callEntityMethod(fuseID, "light");
|
||||
},
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
},
|
||||
};
|
||||
return new Fuse();
|
||||
});
|
Loading…
Reference in a new issue