michalbe / cervus

:video_game: tiny WebGL 3d game engine
MIT License
28 stars 4 forks source link

Material constructors should expect images, not urls. #123

Closed michalbe closed 7 years ago

michalbe commented 7 years ago

Right now material constructor looks more/less like this:

const textured_phong_material = new PhongMaterial({
  requires: [ Render, Transform ],
  texture: '../textures/4.png',
  normal_map: '../textures/uv4.png'
});

Texture is fetched & built in core/material::build_texture.

This way we cannot set dynamic texture rendered for instance on canvas. image_loader should be used instead, for example like that:

const textured_phong_material = new PhongMaterial({
  requires: [ Render, Transform ],
  texture: image_loader('../textures/4.png'),
  normal_map: image_loader('../textures/uv4.png')
});

and materials should operate on promises/images, not `urls.