" device is not defined "

Hey,

I’ve just tried to run the code from:

This script is attached to an empty entity in my scene.

So, how do i define device ?

The script :

var MeshGeneration = pc.createScript('meshGeneration');

// initialize code called once per entity
MeshGeneration.prototype.initialize = function() {
// Render a single, unindexed triangle
var mesh = new pc.Mesh(device);
var positions = [0, 0, 0,     1, 0, 0,     1, 1, 0];
mesh.setPositions(positions);
mesh.update();
};

Could you post the full error message @qtestman?

I’m not sure, but maybe this?

pc.app.graphicsDevice
2 Likes

Ok,
device = pc.app.graphicsDevice; var mesh = new pc.Mesh(device)
or
var mesh = new pc.Mesh(pc.app.graphicsDevice);

Do i have to add uvs and a material to be able to see the mesh ?

Do you know a good tutorial to generate a sphere ( like a planet ) in JS ?

i don’t see any console when i launch the game, just the error pop-up.
Is there a runtime console ?

The console is in the browser devtools.

Also, note that the param for the constructor is optional:

So you can just do:

var mesh = new pc.Mesh();
1 Like

Actually, it’s:

this.app.graphicsDevice

pc.app is not currently public API.

Wouldn’t that make it impossible to troubleshoot from the console? eg pc.app.scene.root.findByName won’t be possible from console. Or is it only possible to use in the console?

It’s not public API in the sense that it isn’t officially supported and could change at any time. In this case where we are creating a mesh in a pc.script, this.app should be used instead.

If needed globally, please use pc.Application.getApplication() instead as that is public API.

1 Like

…I need to fix my code :sweat_smile: