parent
431797fdaa
commit
bcfa3b6df2
|
@ -5,7 +5,9 @@
|
||||||
GameLib.D3.ComponentTriggerBoxSphere = function(
|
GameLib.D3.ComponentTriggerBoxSphere = function(
|
||||||
componentId,
|
componentId,
|
||||||
entitiesToCheck,
|
entitiesToCheck,
|
||||||
callback
|
onInside,
|
||||||
|
onEnter,
|
||||||
|
onLeave
|
||||||
) {
|
) {
|
||||||
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
||||||
this.parentEntity = null;
|
this.parentEntity = null;
|
||||||
|
@ -14,7 +16,12 @@ GameLib.D3.ComponentTriggerBoxSphere = function(
|
||||||
GameLib.D3.Utils.Extend(GameLib.D3.ComponentTriggerBoxSphere, GameLib.D3.ComponentInterface);
|
GameLib.D3.Utils.Extend(GameLib.D3.ComponentTriggerBoxSphere, GameLib.D3.ComponentInterface);
|
||||||
|
|
||||||
this.entitiesToCheck = entitiesToCheck || [];
|
this.entitiesToCheck = entitiesToCheck || [];
|
||||||
this.callback = callback || null;
|
this.onInside = onInside || null;
|
||||||
|
this.onEnter = onEnter || null;
|
||||||
|
this.onLeave = onLeave || null;
|
||||||
|
|
||||||
|
// runtime code
|
||||||
|
this.entitiesInside = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
if(typeof THREE != "undefined") {
|
if(typeof THREE != "undefined") {
|
||||||
|
@ -46,6 +53,7 @@ GameLib.D3.ComponentTriggerBoxSphere.prototype.onUpdate = function(
|
||||||
if (!entityToCheck.mesh.geometry.boundingSphere) {
|
if (!entityToCheck.mesh.geometry.boundingSphere) {
|
||||||
entityToCheck.mesh.geometry.computeBoundingSphere();
|
entityToCheck.mesh.geometry.computeBoundingSphere();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var spherePosition = new THREE.Vector3(
|
var spherePosition = new THREE.Vector3(
|
||||||
entityToCheck.position.x,
|
entityToCheck.position.x,
|
||||||
|
@ -57,33 +65,32 @@ GameLib.D3.ComponentTriggerBoxSphere.prototype.onUpdate = function(
|
||||||
|
|
||||||
var sphere = new THREE.Sphere(
|
var sphere = new THREE.Sphere(
|
||||||
spherePosition,
|
spherePosition,
|
||||||
entityToCheck.mesh.geometry.boundingSphere.radius
|
entityToCheck.mesh ? entityToCheck.mesh.geometry.boundingSphere.radius : 1
|
||||||
);
|
);
|
||||||
|
|
||||||
if(this.callback && parentEntity.mesh.geometry.boundingBox.intersectsSphere(sphere)) {
|
if(parentEntity.mesh.geometry.boundingBox.intersectsSphere(sphere)) {
|
||||||
this.callback(parentEntity, entityToCheck);
|
|
||||||
|
if(this.entitiesInside.indexOf(entityToCheck) <= -1) { // check if this is the first time the entity enters the trigger
|
||||||
|
this.entitiesInside.push(entityToCheck);
|
||||||
|
|
||||||
|
if(this.onEnter) {
|
||||||
|
this.onEnter(parentEntity, entityToCheck);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // no target mesh geometry.
|
|
||||||
|
|
||||||
var spherePosition = new THREE.Vector3(
|
if(this.onInside) {
|
||||||
entityToCheck.position.x,
|
this.onInside(parentEntity, entityToCheck);
|
||||||
entityToCheck.position.y,
|
|
||||||
entityToCheck.position.z
|
|
||||||
);
|
|
||||||
|
|
||||||
spherePosition.applyMatrix4(ComponentTriggerBoxSphere_BoxInverseTransform);
|
|
||||||
|
|
||||||
var sphere = new THREE.Sphere(
|
|
||||||
spherePosition,
|
|
||||||
1
|
|
||||||
);
|
|
||||||
|
|
||||||
if(this.callback && parentEntity.mesh.geometry.boundingBox.intersectsSphere(sphere)) {
|
|
||||||
this.callback(parentEntity, entityToCheck);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if(this.entitiesInside.indexOf(entityToCheck) > -1) { // entity WAS inside the trigger
|
||||||
|
this.entitiesInside.splice(this.entitiesInside.indexOf(entityToCheck), 1);
|
||||||
|
|
||||||
|
if(this.onLeave) {
|
||||||
|
this.onLeave(parentEntity, entityToCheck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -5,7 +5,9 @@ GameLib.D3.ComponentTriggerSphereSphere = function(
|
||||||
componentId,
|
componentId,
|
||||||
sphereRadius,
|
sphereRadius,
|
||||||
entitiesToCheck,
|
entitiesToCheck,
|
||||||
callback
|
onInside,
|
||||||
|
onEnter,
|
||||||
|
onLeave
|
||||||
) {
|
) {
|
||||||
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
||||||
this.parentEntity = null;
|
this.parentEntity = null;
|
||||||
|
@ -15,7 +17,12 @@ GameLib.D3.ComponentTriggerSphereSphere = function(
|
||||||
|
|
||||||
this.entitiesToCheck = entitiesToCheck || [];
|
this.entitiesToCheck = entitiesToCheck || [];
|
||||||
this.sphereRadius = sphereRadius || 1.0;
|
this.sphereRadius = sphereRadius || 1.0;
|
||||||
this.callback = callback || null;
|
this.onInside = onInside || null;
|
||||||
|
this.onEnter = onEnter || null;
|
||||||
|
this.onLeave = onLeave || null;
|
||||||
|
|
||||||
|
// runtime code
|
||||||
|
this.entitiesInside = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
if(typeof THREE != "undefined") {
|
if(typeof THREE != "undefined") {
|
||||||
|
@ -63,8 +70,24 @@ GameLib.D3.ComponentTriggerSphereSphere.prototype.onUpdate = function(
|
||||||
var length = ComponentTriggerSphereSphere_sphereToSphere_Vector3.length();
|
var length = ComponentTriggerSphereSphere_sphereToSphere_Vector3.length();
|
||||||
|
|
||||||
if((length - (ComponentTriggerSphereSphere_targetBoundingSphereRadius + this.sphereRadius)) < 0) {
|
if((length - (ComponentTriggerSphereSphere_targetBoundingSphereRadius + this.sphereRadius)) < 0) {
|
||||||
if(this.callback) {
|
|
||||||
this.callback(parentEntity, entityToCheck);
|
if(this.entitiesInside.indexOf(entityToCheck) <= -1) { // check if this is the first time the entity enters the trigger
|
||||||
|
this.entitiesInside.push(entityToCheck);
|
||||||
|
|
||||||
|
if(this.onEnter) {
|
||||||
|
this.onEnter(parentEntity, entityToCheck);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.onInside) {
|
||||||
|
this.onInside(parentEntity, entityToCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if(this.entitiesInside.indexOf(entityToCheck) > -1) { // entity WAS inside the trigger
|
||||||
|
this.entitiesInside.splice(this.entitiesInside.indexOf(entityToCheck), 1);
|
||||||
|
|
||||||
|
if(this.onLeave) {
|
||||||
|
this.onLeave(parentEntity, entityToCheck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ GameLib.D3.Game.prototype.render = function(
|
||||||
) {
|
) {
|
||||||
for(var s in this.scenes) {
|
for(var s in this.scenes) {
|
||||||
var scene = this.scenes[s];
|
var scene = this.scenes[s];
|
||||||
scene.render(dt, renderer, camera);
|
scene.render(dt, renderer, scene.camera);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -224,10 +224,10 @@ GameLib.D3.Scene.prototype.loadTextures = function(urls, onLoadedCallback) {
|
||||||
gameLibTexture.wrapS,
|
gameLibTexture.wrapS,
|
||||||
gameLibTexture.wrapT,
|
gameLibTexture.wrapT,
|
||||||
gameLibTexture.magFilter,
|
gameLibTexture.magFilter,
|
||||||
gameLibTexture.minFilter,
|
gameLibTexture.minFilter
|
||||||
gameLibTexture.format,
|
//gameLibTexture.format,
|
||||||
gameLibTexture.textureType,
|
//gameLibTexture.textureType,
|
||||||
gameLibTexture.anisotropy
|
//gameLibTexture.anisotropy
|
||||||
);
|
);
|
||||||
|
|
||||||
instanceMaterial[instanceMapId].name = gameLibTexture.name;
|
instanceMaterial[instanceMapId].name = gameLibTexture.name;
|
||||||
|
@ -735,6 +735,13 @@ GameLib.D3.Scene.FromAPIScene = function(
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set on runtime.
|
||||||
|
*/
|
||||||
|
GameLib.D3.Scene.prototype.setCamera = function(camera) {
|
||||||
|
this.sceneCamera = camera;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the scene
|
* Updates the scene
|
||||||
* @param deltaTime
|
* @param deltaTime
|
||||||
|
@ -767,10 +774,11 @@ GameLib.D3.Scene.prototype.lateUpdate = function(
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Scene.prototype.render = function(
|
GameLib.D3.Scene.prototype.render = function(
|
||||||
deltaTime,
|
deltaTime,
|
||||||
renderer,
|
renderer
|
||||||
camera
|
|
||||||
) {
|
) {
|
||||||
renderer.render(this.instance, camera);
|
if(this.sceneCamera) {
|
||||||
|
renderer.render(this.instance, this.sceneCamera);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue