Loading a texture remotely

Trying out PlayCanvas for the first time, and very impressed at how fast it is to get started!

I’d like to load a texture remotely and assign it to a primitive’s material(?) - I’m not sure how to go about that. Please help. Thanks!

Scriptwise, I’ve found pc.gfx.Texture and such, but I am not sure how the texels and materials work as components of a cube primitive.

Hi,

Sorry, took a little while to respond to this…

Currently you can’t modify the material on a primitive. We’re going to be fixing this soon. But at the moment the best way to achieve this is to export a simple primitive from Blender or 3DS Max etc. And then import that as an asset. You can then edit the material by selecting the model in the design view and then clicking again on material that you want to edit. You’ll see the Material Editor on the right.

Maybe @will can talk you through modifying materials via scripts?

Hi there!

Here’s an example that loads a Google Maps image tile:

http://apps.playcanvas.com/will/crossorigin/demo

Here’s the accompanying project:

http://playcanvas.com/will/crossorigin

Here’s the script that does the work:

http://playcanvas.com/will/crossorigin/editor/texture.js

Note that we’ll soon be updating primitive component to support material assignment so the code might have to change a little, but it’ll work fine for now. :slight_smile: Also, I wasn’t sure what you meant by ‘remotely’. I thought you might be asking about loading images for textures from other domains (cross origin). See here for details on that:

https://hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/

Anyway, if you just want to load images you’ve uploaded to your asset list in your PlayCanvas project, let me know and I’ll tweak the code to show how that’s done.

1 Like