Update: CC - Demo New - Entity Loaded (tuby5lj4di.js) 570 bytes modified

beta.r3js.org
-=yb4f310 2018-02-16 11:34:19 +01:00
parent 299f539a2e
commit ea9fcd03a7
1 changed files with 85 additions and 74 deletions

View File

@ -1,7 +1,7 @@
if (this.parentEntity === data.entity) { if (this.parentEntity === data.entity) {
console.log('Entity FSDemo Loaded'); console.log('Entity FSDemo Loaded');
} else { } else {
return; return;
} }
/** /**
@ -11,8 +11,8 @@ this.imageSpoon = GameLib.EntityManager.Instance.findComponentById('g6oggbsg5k
this.imageEarth = GameLib.EntityManager.Instance.findComponentById('fo1einfper'); this.imageEarth = GameLib.EntityManager.Instance.findComponentById('fo1einfper');
this.images = [ this.images = [
this.imageSpoon, this.imageSpoon,
this.imageEarth this.imageEarth
]; ];
/** /**
@ -39,42 +39,44 @@ this.materialRawPhong = GameLib.EntityManager.Instance.findComponentById('r153c4
/** /**
* Custom Code Components * Custom Code Components
*/ */
this.ccBeforeRender = GameLib.EntityManager.Instance.findComponentById('wlw063ovw9'); this.beforeRender = GameLib.EntityManager.Instance.findComponentById('wlw063ovw9');
this.ccKeyUp = GameLib.EntityManager.Instance.findComponentById('ip0443a52d'); this.keyUp = GameLib.EntityManager.Instance.findComponentById('ip0443a52d');
this.ccBeforeRender.entityLoaded = this; /**
this.ccKeyUp.entityLoaded = this; * Program parameters
*/
this.attributeData = null;
/** /**
* Generates new Attribute Data based on the image index according to 'width' and 'height' * Generates new Attribute Data based on the image index according to 'width' and 'height'
*/ */
GameLib.CustomCode.prototype.generateAttributeData = function(index, width, height) { GameLib.CustomCode.prototype.generateAttributeData = function(index, width, height) {
var heightData = this.images[index].getHeightData();
var offsets = [];
var scales = [];
var orientations = [];
var x, y, z = 0; var heightData = this.images[index].getHeightData();
for (x = 0; x < width; x++) { var offsets = [];
for (y = 0; y < height; y++) { var scales = [];
z = heightData[(y * width) + x] * 10; var orientations = [];
scale = z * 0.19;
offsets.push((x - 64) * 2, (64 - y) * 2, z); var x, y, z = 0;
orientations.push(0, 0, 0, 1);
scales.push(scale, scale, scale); for (x = 0; x < width; x++) {
} for (y = 0; y < height; y++) {
} z = heightData[(y * width) + x] * 10;
scale = z * 0.19;
return { offsets.push((x - 64) * 2, (64 - y) * 2, z);
offsets : offsets, orientations.push(0, 0, 0, 1);
scales : scales, scales.push(scale, scale, scale);
orientations : orientations }
}; }
return {
offsets : offsets,
scales : scales,
orientations : orientations
};
}.bind(this); }.bind(this);
/** /**
@ -82,51 +84,60 @@ GameLib.CustomCode.prototype.generateAttributeData = function(index, width, heig
*/ */
GameLib.CustomCode.prototype.buildInstancedGeometry = function(index) { GameLib.CustomCode.prototype.buildInstancedGeometry = function(index) {
var attributeData = this.generateAttributeData(index, 128, 128); this.attributeData = this.generateAttributeData(index, 128, 128);
var uniforms = Object.assign(
THREE.UniformsLib['lights'],
THREE.UniformsLib['common'],
{
map : {
value : this.textureWhite.instance
}
}
);
uniforms.diffuse.value.r = 0.47;
uniforms.diffuse.value.g = 0.72;
uniforms.diffuse.value.b = 1.0;
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;
var offsetAttribute = new THREE.InstancedBufferAttribute( var uniforms = Object.assign(
new Float32Array(attributeData.offsets), THREE.UniformsLib['lights'],
3 THREE.UniformsLib['common'],
).setDynamic(true); {
map : {
var orientationAttribute = new THREE.InstancedBufferAttribute( value : this.textureWhite.instance
new Float32Array(attributeData.orientations), }
4 }
); );
var scaleAttribute = new THREE.InstancedBufferAttribute( uniforms.diffuse.value.r = 0.47;
new Float32Array(attributeData.scales), uniforms.diffuse.value.g = 0.72;
3 uniforms.diffuse.value.b = 1.0;
).setDynamic(true);
this.materialRawPhong.instance.uniforms = uniforms;
this.instancedGeometry.instance.addAttribute('offset', offsetAttribute);
this.instancedGeometry.instance.addAttribute('orientation', orientationAttribute); this.instancedGeometry.instance.index = this.boxGeometry.instance.index;
this.instancedGeometry.instance.addAttribute('scale', scaleAttribute); 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;
var offsetAttribute = new THREE.InstancedBufferAttribute(
new Float32Array(this.attributeData.offsets),
3
).setDynamic(true);
var orientationAttribute = new THREE.InstancedBufferAttribute(
new Float32Array(this.attributeData.orientations),
4
);
var scaleAttribute = new THREE.InstancedBufferAttribute(
new Float32Array(this.attributeData.scales),
3
).setDynamic(true);
this.instancedGeometry.instance.addAttribute('offset', offsetAttribute);
this.instancedGeometry.instance.addAttribute('orientation', orientationAttribute);
this.instancedGeometry.instance.addAttribute('scale', scaleAttribute);
}.bind(this);
GameLib.CustomCode.prototype.startAnimation = function(attributeData) {
this.beforeRender.currentAttributeData = this.attributeData;
this.beforeRender.freshAttributeData = attributeData;
this.beforeRender.animate = true;
}.bind(this); }.bind(this);
this.buildInstancedGeometry(0); this.buildInstancedGeometry(0);
this.beforeRender.entityLoaded = this;
this.keyUp.entityLoaded = this;
//@ sourceURL=entiyLoaded.js //@ sourceURL=entiyLoaded.js