Comparing version 0.0.28 to 0.0.30
@@ -15,4 +15,4 @@ /* global Cervus */ | ||
], | ||
texture: '../textures/4.png', | ||
normal_map: '../textures/uv4.png' | ||
texture: Cervus.core.image_loader('../textures/4.png'), | ||
normal_map: Cervus.core.image_loader('../textures/uv4.png') | ||
}); | ||
@@ -19,0 +19,0 @@ |
@@ -15,3 +15,3 @@ /* global Cervus */ | ||
// texture: '../textures/4.png', | ||
normal_map: '../textures/normal2.jpg' | ||
normal_map: Cervus.core.image_loader('../textures/normal2.jpg') | ||
}); | ||
@@ -18,0 +18,0 @@ |
@@ -39,3 +39,3 @@ /* global Cervus */ | ||
for (let i = 0; i < 100; i++) { | ||
for (let i = 0; i < 15; i++) { | ||
const cube = new Cervus.shapes.Box(); | ||
@@ -46,6 +46,6 @@ const cube_transform = cube.get_component(Cervus.components.Transform); | ||
cube_render.material = material; | ||
cube_render.color = '#'+(Math.random()*0xFFFFFF<<0).toString(16); | ||
cube_render.color = '#'+Math.floor(Math.random()*1677215).toString(16); | ||
cube_transform.position = [ | ||
0, | ||
1 * i, | ||
4 * i, | ||
-10 | ||
@@ -52,0 +52,0 @@ ]; |
@@ -7,4 +7,4 @@ /* global Cervus */ | ||
], | ||
texture: '../textures/4.png', | ||
normal_map: '../textures/normal2.jpg' | ||
texture: Cervus.core.image_loader('../textures/4.png'), | ||
normal_map: Cervus.core.image_loader('../textures/normal2.jpg') | ||
}); | ||
@@ -11,0 +11,0 @@ |
import { create_program_object, create_shader_object, gl } from './context'; | ||
import { Transform, Render } from '../components'; | ||
import { image_loader } from './'; | ||
@@ -69,23 +68,20 @@ import { vertex } from '../shaders'; | ||
set texture(url) { | ||
this.build_texture(url, this._texture_url, 'TEXTURE', 'gl_texture'); | ||
set texture(image_promise) { | ||
this.build_texture(image_promise, this._texture_image, 'TEXTURE', 'gl_texture'); | ||
} | ||
get texture() { | ||
return this._texture_url; | ||
return this._texture_image; | ||
} | ||
set normal_map(url) { | ||
this.build_texture(url, this._normal_map_url, 'NORMAL_MAP', 'gl_normal_map'); | ||
set normal_map(image_promise) { | ||
this.build_texture(image_promise, this._normal_map_image, 'NORMAL_MAP', 'gl_normal_map'); | ||
} | ||
get normal_map() { | ||
return this._normal_map_url; | ||
return this._normal_map_image; | ||
} | ||
build_texture(new_url, url_location, feature, gl_texture_key) { | ||
if (new_url !== url_location && new_url) { | ||
url_location = new_url; | ||
build_texture(image_promise, url_location, feature, gl_texture_key) { | ||
if (image_promise) { | ||
if (!this._textures[gl_texture_key]) { | ||
@@ -95,12 +91,14 @@ this._textures[gl_texture_key] = gl.createTexture(); | ||
image_loader(new_url) | ||
.then(image => { | ||
image_promise.then(image => { | ||
if (url_location !== image) { | ||
url_location = image; | ||
gl.bindTexture(gl.TEXTURE_2D, this._textures[gl_texture_key]); | ||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA,gl.UNSIGNED_BYTE, image); | ||
gl.generateMipmap(gl.TEXTURE_2D); | ||
gl.bindTexture(gl.TEXTURE_2D, this._textures[gl_texture_key]); | ||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA,gl.UNSIGNED_BYTE, image); | ||
gl.generateMipmap(gl.TEXTURE_2D); | ||
if (!this.has_feature(feature)) { | ||
this.add_feature(feature); | ||
this.setup_program(); | ||
if (!this.has_feature(feature)) { | ||
this.add_feature(feature); | ||
this.setup_program(); | ||
} | ||
} | ||
@@ -110,5 +108,5 @@ }) | ||
} else if (!new_url) { | ||
} else if (!image_promise) { | ||
url_location = new_url; | ||
url_location = null; | ||
this.remove_feature(feature); | ||
@@ -115,0 +113,0 @@ this.setup_program(); |
{ | ||
"name": "cervus", | ||
"version": "0.0.28", | ||
"version": "0.0.30", | ||
"author": "Michał Budzyński <michal@virtualdesign.pl>", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:michalbe/cervus.git", |
3649932