2018-02-12 15:15:47 +01:00
|
|
|
if (this.parentEntity === data.entity) {
|
2018-02-16 11:34:19 +01:00
|
|
|
console.log('Entity FSDemo Loaded');
|
2018-02-16 11:22:56 +01:00
|
|
|
} else {
|
2018-02-16 11:34:19 +01:00
|
|
|
return;
|
2018-02-12 15:15:47 +01:00
|
|
|
}
|
|
|
|
|
2018-02-16 11:22:56 +01:00
|
|
|
/**
|
|
|
|
* Images
|
|
|
|
*/
|
|
|
|
this.imageSpoon = GameLib.EntityManager.Instance.findComponentById('g6oggbsg5k');
|
|
|
|
this.imageEarth = GameLib.EntityManager.Instance.findComponentById('fo1einfper');
|
2018-02-16 13:28:25 +01:00
|
|
|
this.imageBK = GameLib.EntityManager.Instance.findComponentById('3ufmzrnewa');
|
|
|
|
this.imageHorse = GameLib.EntityManager.Instance.findComponentById('w4koth16uf');
|
2018-02-16 11:22:56 +01:00
|
|
|
|
|
|
|
this.images = [
|
2018-03-19 14:49:27 +01:00
|
|
|
this.imageBK,
|
|
|
|
this.imageBK,
|
2018-02-16 13:28:25 +01:00
|
|
|
this.imageBK,
|
2018-03-19 14:49:27 +01:00
|
|
|
this.imageBK
|
2018-02-16 11:22:56 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Meshes
|
|
|
|
*/
|
|
|
|
this.meshBox = GameLib.EntityManager.Instance.findComponentById('2ehdod2g2a');
|
|
|
|
this.meshImageGrid = GameLib.EntityManager.Instance.findComponentById('9qkka13nor');
|
|
|
|
|
2018-02-16 11:38:02 +01:00
|
|
|
/**
|
|
|
|
* Camera
|
|
|
|
*/
|
|
|
|
this.camera = GameLib.EntityManager.Instance.findComponentById('j36eiamn0s');
|
|
|
|
|
2018-02-16 11:22:56 +01:00
|
|
|
/**
|
|
|
|
* Geometry
|
|
|
|
*/
|
|
|
|
this.instancedGeometry = GameLib.EntityManager.Instance.findComponentById('s5dfh75zza');
|
|
|
|
this.boxGeometry = GameLib.EntityManager.Instance.findComponentById('pwzyukkviy');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Textures
|
|
|
|
*/
|
|
|
|
this.textureWhite = GameLib.EntityManager.Instance.findComponentById('642tyh30uo');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Materials
|
|
|
|
*/
|
|
|
|
this.materialRawPhong = GameLib.EntityManager.Instance.findComponentById('r153c4450d');
|
|
|
|
|
2018-02-20 16:05:44 +01:00
|
|
|
/**
|
2018-02-20 16:18:04 +01:00
|
|
|
* Mouse and Raycasting
|
2018-02-20 16:05:44 +01:00
|
|
|
*/
|
2018-02-20 16:18:04 +01:00
|
|
|
this.mouse = GameLib.EntityManager.Instance.findComponentById('znif4n23an');
|
|
|
|
this.raycaster = GameLib.EntityManager.Instance.findComponentById('69s5vsshb9');
|
2018-02-20 16:05:44 +01:00
|
|
|
|
2018-02-16 11:22:56 +01:00
|
|
|
/**
|
|
|
|
* Custom Code Components
|
2018-02-16 11:34:19 +01:00
|
|
|
*/
|
|
|
|
this.beforeRender = GameLib.EntityManager.Instance.findComponentById('wlw063ovw9');
|
|
|
|
this.keyUp = GameLib.EntityManager.Instance.findComponentById('ip0443a52d');
|
2018-02-20 16:05:44 +01:00
|
|
|
this.mouseMove = GameLib.EntityManager.Instance.findComponentById('n9evs68jpd');
|
2018-02-16 11:22:56 +01:00
|
|
|
|
2018-02-16 11:34:19 +01:00
|
|
|
/**
|
|
|
|
* Program parameters
|
|
|
|
*/
|
2018-02-16 12:15:28 +01:00
|
|
|
this.attributeData = null;
|
|
|
|
this.updateInformation = [];
|
2018-02-16 12:26:43 +01:00
|
|
|
this.currentIndex = 0;
|
|
|
|
this.maxIndex = this.images.length - 1;
|
2018-02-16 12:15:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attributes
|
|
|
|
*/
|
|
|
|
this.offsetAttribute = null;
|
|
|
|
this.scaleAttribute = null;
|
2018-02-16 11:22:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates new Attribute Data based on the image index according to 'width' and 'height'
|
|
|
|
*/
|
2018-03-19 14:40:12 +01:00
|
|
|
GameLib.CustomCode.prototype.generateAttributeData = function(index) {
|
2018-02-16 11:34:19 +01:00
|
|
|
|
2018-03-19 14:40:12 +01:00
|
|
|
var width = this.images[index].width;
|
|
|
|
var height = this.images[index].height;
|
|
|
|
|
2018-02-16 11:34:19 +01:00
|
|
|
var heightData = this.images[index].getHeightData();
|
|
|
|
|
|
|
|
var offsets = [];
|
|
|
|
var scales = [];
|
|
|
|
var orientations = [];
|
|
|
|
|
2018-02-19 12:00:12 +01:00
|
|
|
var x, y, z, scale, h = 0;
|
2018-02-16 11:34:19 +01:00
|
|
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
for (y = 0; y < height; y++) {
|
2018-02-19 12:00:12 +01:00
|
|
|
|
|
|
|
h = heightData[(y * width) + x];
|
2018-02-19 12:08:25 +01:00
|
|
|
z = h * 50;
|
2018-02-19 12:00:12 +01:00
|
|
|
scale = h * 1.9;
|
|
|
|
|
2018-02-16 11:34:19 +01:00
|
|
|
offsets.push((x - 64) * 2, (64 - y) * 2, z);
|
|
|
|
orientations.push(0, 0, 0, 1);
|
|
|
|
scales.push(scale, scale, scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
offsets : offsets,
|
|
|
|
scales : scales,
|
|
|
|
orientations : orientations
|
|
|
|
};
|
|
|
|
|
2018-02-16 11:14:31 +01:00
|
|
|
}.bind(this);
|
|
|
|
|
2018-02-16 11:22:56 +01:00
|
|
|
/**
|
|
|
|
* Builds our instanced geometry
|
|
|
|
*/
|
2018-02-16 11:14:31 +01:00
|
|
|
GameLib.CustomCode.prototype.buildInstancedGeometry = function(index) {
|
|
|
|
|
2018-03-19 14:40:12 +01:00
|
|
|
this.attributeData = this.generateAttributeData(index);
|
2018-02-16 11:34:19 +01:00
|
|
|
|
|
|
|
var uniforms = Object.assign(
|
|
|
|
THREE.UniformsLib['lights'],
|
|
|
|
THREE.UniformsLib['common'],
|
|
|
|
{
|
|
|
|
map : {
|
|
|
|
value : this.textureWhite.instance
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-02-19 15:14:41 +01:00
|
|
|
uniforms.opacity.value = 0.7;
|
2018-02-19 12:11:43 +01:00
|
|
|
|
2018-02-20 15:33:29 +01:00
|
|
|
uniforms.diffuse.value.r = 0.349;
|
2018-02-20 15:54:25 +01:00
|
|
|
uniforms.diffuse.value.g = 0.556;
|
2018-02-20 15:33:29 +01:00
|
|
|
uniforms.diffuse.value.b = 0.729;
|
2018-02-16 11:34:19 +01:00
|
|
|
|
|
|
|
this.materialRawPhong.instance.uniforms = uniforms;
|
|
|
|
|
|
|
|
this.instancedGeometry.instance.index = this.boxGeometry.instance.index;
|
|
|
|
this.instancedGeometry.instance.groups = this.boxGeometry.instance.groups;
|
|
|
|
this.instancedGeometry.instance.attributes.position = this.boxGeometry.instance.attributes.position;
|
|
|
|
this.instancedGeometry.instance.attributes.normal = this.boxGeometry.instance.attributes.normal;
|
|
|
|
this.instancedGeometry.instance.attributes.uv = this.boxGeometry.instance.attributes.uv;
|
|
|
|
|
2018-02-16 12:15:28 +01:00
|
|
|
this.offsetAttribute = new THREE.InstancedBufferAttribute(
|
2018-02-16 11:34:19 +01:00
|
|
|
new Float32Array(this.attributeData.offsets),
|
|
|
|
3
|
|
|
|
).setDynamic(true);
|
|
|
|
|
|
|
|
var orientationAttribute = new THREE.InstancedBufferAttribute(
|
|
|
|
new Float32Array(this.attributeData.orientations),
|
|
|
|
4
|
|
|
|
);
|
|
|
|
|
2018-02-16 12:15:28 +01:00
|
|
|
this.scaleAttribute = new THREE.InstancedBufferAttribute(
|
2018-02-16 11:34:19 +01:00
|
|
|
new Float32Array(this.attributeData.scales),
|
|
|
|
3
|
|
|
|
).setDynamic(true);
|
|
|
|
|
2018-02-16 12:15:28 +01:00
|
|
|
this.instancedGeometry.instance.addAttribute('offset', this.offsetAttribute);
|
2018-02-16 11:34:19 +01:00
|
|
|
this.instancedGeometry.instance.addAttribute('orientation', orientationAttribute);
|
2018-02-16 12:15:28 +01:00
|
|
|
this.instancedGeometry.instance.addAttribute('scale', this.scaleAttribute);
|
2018-02-16 11:34:19 +01:00
|
|
|
|
|
|
|
}.bind(this);
|
|
|
|
|
2018-02-16 12:34:49 +01:00
|
|
|
/**
|
|
|
|
* Builds update information holding our current position and scale, and our target position and scale
|
|
|
|
*/
|
2018-02-16 12:15:28 +01:00
|
|
|
GameLib.CustomCode.prototype.generateAnimationVectors = function(attributeData) {
|
|
|
|
|
|
|
|
if (!attributeData) {
|
|
|
|
console.warn('animation not ready');
|
|
|
|
}
|
|
|
|
|
2018-02-16 13:06:54 +01:00
|
|
|
var i, index0, index1, index2, itemSize;
|
2018-02-16 12:15:28 +01:00
|
|
|
|
2018-02-16 13:06:54 +01:00
|
|
|
itemSize = this.offsetAttribute.itemSize;
|
|
|
|
|
2018-02-16 12:43:58 +01:00
|
|
|
this.updateInformation = [];
|
2018-02-16 13:04:20 +01:00
|
|
|
|
2018-02-16 12:15:28 +01:00
|
|
|
for (i = 0; i < this.offsetAttribute.count; i++) {
|
2018-02-16 12:43:58 +01:00
|
|
|
|
2018-02-16 13:06:54 +01:00
|
|
|
index0 = itemSize * i;
|
|
|
|
index1 = index0 + 1;
|
|
|
|
index2 = index1 + 1;
|
2018-02-16 13:04:20 +01:00
|
|
|
|
2018-02-16 12:15:28 +01:00
|
|
|
this.updateInformation.push(
|
|
|
|
{
|
|
|
|
offset : {
|
|
|
|
current : new THREE.Vector3(
|
2018-02-16 13:04:20 +01:00
|
|
|
this.offsetAttribute.array[index0],
|
|
|
|
this.offsetAttribute.array[index1],
|
|
|
|
this.offsetAttribute.array[index2]
|
2018-02-16 12:15:28 +01:00
|
|
|
),
|
|
|
|
target : new THREE.Vector3(
|
2018-02-16 13:04:20 +01:00
|
|
|
attributeData.offsets[index0],
|
|
|
|
attributeData.offsets[index1],
|
|
|
|
attributeData.offsets[index2]
|
2018-02-16 12:15:28 +01:00
|
|
|
)
|
|
|
|
},
|
|
|
|
scale : {
|
|
|
|
current : new THREE.Vector3(
|
2018-02-16 13:04:20 +01:00
|
|
|
this.scaleAttribute.array[index0],
|
|
|
|
this.scaleAttribute.array[index1],
|
|
|
|
this.scaleAttribute.array[index2]
|
2018-02-16 12:15:28 +01:00
|
|
|
),
|
|
|
|
target : new THREE.Vector3(
|
2018-02-16 13:04:20 +01:00
|
|
|
attributeData.scales[index0],
|
|
|
|
attributeData.scales[index1],
|
|
|
|
attributeData.scales[index2]
|
2018-02-16 12:15:28 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2018-02-16 12:43:58 +01:00
|
|
|
|
2018-02-16 12:15:28 +01:00
|
|
|
}
|
|
|
|
}.bind(this);
|
|
|
|
|
2018-02-16 12:34:49 +01:00
|
|
|
/**
|
2018-02-16 12:43:58 +01:00
|
|
|
* Load the next animation
|
2018-02-16 12:34:49 +01:00
|
|
|
*/
|
2018-02-16 12:43:58 +01:00
|
|
|
GameLib.CustomCode.prototype.loadNext = function() {
|
|
|
|
|
|
|
|
this.currentIndex++
|
|
|
|
|
|
|
|
if (this.currentIndex > this.maxIndex) {
|
|
|
|
this.currentIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var attributeData = this.generateAttributeData(this.currentIndex, 128, 128);
|
|
|
|
|
|
|
|
this.generateAnimationVectors(attributeData);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify our render component that we are ready to start animating
|
|
|
|
*/
|
|
|
|
this.beforeRender.startAnimation = true;
|
|
|
|
|
2018-02-16 12:19:15 +01:00
|
|
|
}.bind(this);
|
|
|
|
|
2018-02-16 12:26:43 +01:00
|
|
|
/**
|
2018-02-16 12:43:58 +01:00
|
|
|
* Performs the actual update to our instanced geometry
|
2018-02-16 12:26:43 +01:00
|
|
|
*/
|
2018-02-16 12:43:58 +01:00
|
|
|
GameLib.CustomCode.prototype.updateAttributeArrays = function(alpha) {
|
|
|
|
|
|
|
|
var i, offset, scale;
|
|
|
|
|
2018-02-16 12:55:34 +01:00
|
|
|
var offsets = [];
|
|
|
|
var scales = [];
|
|
|
|
|
2018-02-16 12:43:58 +01:00
|
|
|
for (i = 0; i < this.updateInformation.length; i++) {
|
|
|
|
|
|
|
|
offset = this.updateInformation[i].offset;
|
|
|
|
scale = this.updateInformation[i].scale;
|
2018-02-16 12:55:34 +01:00
|
|
|
|
2018-02-16 12:58:04 +01:00
|
|
|
offset.current.lerp(
|
2018-02-16 12:55:34 +01:00
|
|
|
offset.target,
|
|
|
|
alpha
|
|
|
|
);
|
|
|
|
|
2018-02-16 13:11:25 +01:00
|
|
|
offsets.push(
|
|
|
|
offset.current.x,
|
|
|
|
offset.current.y,
|
|
|
|
offset.current.z
|
|
|
|
);
|
2018-02-16 12:43:58 +01:00
|
|
|
|
2018-02-16 12:58:04 +01:00
|
|
|
scale.current.lerp(
|
2018-02-16 12:55:34 +01:00
|
|
|
scale.target,
|
|
|
|
alpha
|
2018-02-16 12:43:58 +01:00
|
|
|
);
|
2018-02-16 12:55:34 +01:00
|
|
|
|
2018-02-16 13:11:25 +01:00
|
|
|
scales.push(
|
|
|
|
scale.current.x,
|
|
|
|
scale.current.y,
|
|
|
|
scale.current.z
|
|
|
|
);
|
2018-02-16 12:43:58 +01:00
|
|
|
}
|
|
|
|
|
2018-02-16 12:55:34 +01:00
|
|
|
this.offsetAttribute.setArray(new Float32Array(offsets));
|
|
|
|
this.scaleAttribute.setArray(new Float32Array(scales));
|
|
|
|
|
2018-02-16 12:48:27 +01:00
|
|
|
this.offsetAttribute.needsUpdate = true;
|
|
|
|
this.scaleAttribute.needsUpdate = true;
|
|
|
|
|
2018-02-16 12:28:35 +01:00
|
|
|
}.bind(this);
|
2018-02-16 12:26:43 +01:00
|
|
|
|
2018-02-16 12:43:58 +01:00
|
|
|
|
2018-02-16 11:22:56 +01:00
|
|
|
this.buildInstancedGeometry(0);
|
|
|
|
|
2018-02-16 11:34:19 +01:00
|
|
|
this.beforeRender.entityLoaded = this;
|
|
|
|
this.keyUp.entityLoaded = this;
|
2018-02-20 16:05:44 +01:00
|
|
|
this.mouseMove.entityLoaded = this;
|
2018-02-16 11:34:19 +01:00
|
|
|
|
2018-03-06 12:19:04 +01:00
|
|
|
window.setInterval(this.loadNext, 10000);
|
2018-03-06 12:14:10 +01:00
|
|
|
|
2018-03-06 12:31:44 +01:00
|
|
|
GameLib.Event.Emit(GameLib.Event.WINDOW_RESIZE, GameLib.Utils.GetWindowSize());
|
|
|
|
|
2018-03-06 12:41:09 +01:00
|
|
|
this.meshImageGrid.updateInstance('lookAt');
|
|
|
|
|
2018-02-16 12:15:28 +01:00
|
|
|
//@ sourceURL=entityLoaded.js
|