From ea9fcd03a75b060dece4bb52e78ae85d148b2e9b Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Fri, 16 Feb 2018 11:34:19 +0100 Subject: [PATCH] Update: CC - Demo New - Entity Loaded (tuby5lj4di.js) 570 bytes modified --- tuby5lj4di.js | 159 +++++++++++++++++++++++++++----------------------- 1 file changed, 85 insertions(+), 74 deletions(-) diff --git a/tuby5lj4di.js b/tuby5lj4di.js index 1f5d997..d71628b 100644 --- a/tuby5lj4di.js +++ b/tuby5lj4di.js @@ -1,7 +1,7 @@ if (this.parentEntity === data.entity) { - console.log('Entity FSDemo Loaded'); + console.log('Entity FSDemo Loaded'); } else { - return; + return; } /** @@ -11,8 +11,8 @@ this.imageSpoon = GameLib.EntityManager.Instance.findComponentById('g6oggbsg5k this.imageEarth = GameLib.EntityManager.Instance.findComponentById('fo1einfper'); this.images = [ - this.imageSpoon, - this.imageEarth + this.imageSpoon, + this.imageEarth ]; /** @@ -39,42 +39,44 @@ this.materialRawPhong = GameLib.EntityManager.Instance.findComponentById('r153c4 /** * Custom Code Components - */ -this.ccBeforeRender = GameLib.EntityManager.Instance.findComponentById('wlw063ovw9'); -this.ccKeyUp = GameLib.EntityManager.Instance.findComponentById('ip0443a52d'); + */ +this.beforeRender = GameLib.EntityManager.Instance.findComponentById('wlw063ovw9'); +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' */ 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; - - for (x = 0; x < width; x++) { - for (y = 0; y < height; y++) { - z = heightData[(y * width) + x] * 10; - scale = z * 0.19; - 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 - }; - + var heightData = this.images[index].getHeightData(); + + var offsets = []; + var scales = []; + var orientations = []; + + var x, y, z = 0; + + for (x = 0; x < width; x++) { + for (y = 0; y < height; y++) { + z = heightData[(y * width) + x] * 10; + scale = z * 0.19; + 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 + }; + }.bind(this); /** @@ -82,51 +84,60 @@ GameLib.CustomCode.prototype.generateAttributeData = function(index, width, heig */ GameLib.CustomCode.prototype.buildInstancedGeometry = function(index) { - var 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; + this.attributeData = this.generateAttributeData(index, 128, 128); - var offsetAttribute = new THREE.InstancedBufferAttribute( - new Float32Array(attributeData.offsets), - 3 - ).setDynamic(true); - - var orientationAttribute = new THREE.InstancedBufferAttribute( - new Float32Array(attributeData.orientations), - 4 - ); + var uniforms = Object.assign( + THREE.UniformsLib['lights'], + THREE.UniformsLib['common'], + { + map : { + value : this.textureWhite.instance + } + } + ); - var scaleAttribute = new THREE.InstancedBufferAttribute( - new Float32Array(attributeData.scales), - 3 - ).setDynamic(true); - - this.instancedGeometry.instance.addAttribute('offset', offsetAttribute); - this.instancedGeometry.instance.addAttribute('orientation', orientationAttribute); - this.instancedGeometry.instance.addAttribute('scale', scaleAttribute); - + 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( + 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); this.buildInstancedGeometry(0); +this.beforeRender.entityLoaded = this; +this.keyUp.entityLoaded = this; + //@ sourceURL=entiyLoaded.js \ No newline at end of file