javascript - Adding a button to change mesh in babylon.js -



javascript - Adding a button to change mesh in babylon.js -

i'm having terrible time trying show/hide mesh in babylon.js scene button. assumed create function show/hide meshes , phone call said button page impact scene , wrote following:

<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="assets/js/babylon.js"></script> <script src="assets/js/hand-1.3.8.js"></script> <script src="assets/js/cannon.js"></script> <!-- optional physics engine --> </head> <body> <div id="container"> <!-- page content --> <div id="content"> <div id="tablebuilder"> <div id='cssmenu'> <ul id="tops"> <button type="button" onclick="showtop('t115')">round</button> <button type="button" onclick="showtop('t345')">rectangular</button> </ul> </div> <canvas id="rendercanvas"></canvas> </div> </div> </div> <script> if (babylon.engine.issupported()) { var mynewscene = null; var canvas = document.getelementbyid("rendercanvas"); var engine = new babylon.engine(canvas, true); babylon.sceneloader.load("", "test.babylon", engine, function (newscene) { mynewscene = newscene; var mesht115 = newscene.getmeshbyname("t115").visibility = 0; var mesh510 = newscene.getmeshbyname("510").visibility = 1; var mesht345 = newscene.getmeshbyname("t345").visibility = 1; var mesh350 = newscene.getmeshbyname("350").visibility = 0; var mybasemesh = newscene.getmeshbyname("510"); var materialmymesh = new babylon.standardmaterial("texture1", newscene); materialmymesh.diffusetexture = new babylon.texture("assets/images/stain/natural.jpg", newscene); materialmymesh.specularpower = 50; mybasemesh.material = materialmymesh; var mytopmesh = newscene.getmeshbyname("t345"); var materialmymesh = new babylon.standardmaterial("texture2", newscene); materialmymesh.diffusetexture = new babylon.texture("assets/images/stain/natural.jpg", newscene); materialmymesh.specularpower = 50; mytopmesh.material = materialmymesh; // wait textures , shaders ready newscene.executewhenready(function () { // attach photographic camera canvas inputs var mycamera = new babylon.arcrotatecamera("arcrotatecamera", 1.2, 1.2, 5, new babylon.vector3(0, 0.1, 0.1), newscene); mycamera.wheelprecision = 10; var light0 = new babylon.hemisphericlight("hemi0", new babylon.vector3(0, 50, 0), newscene); light0.diffuse = new babylon.color3(1, 1, 1); light0.specular = new babylon.color3(1, 1, 1); light0.groundcolor = new babylon.color3(.5, .5, .5); newscene.activecamera = mycamera; newscene.activecamera.attachcontrol(canvas); // 1 time scene loaded, register render loop render engine.runrenderloop(function() { newscene.render(); }); }); }, function (progress) { // do: give progress feedback user }); } function showtop (x) { mynewscene.getmeshbyid("mytopmesh").visibility = 0; mynewscene.getmeshbyid(x).visibility = 1; } </script> </body> </html>

however, error.

uncaught typeerror: undefined not function showtop 3d.php::88 onclick 3d.php::88

line 88 is:

mynewscene.getmeshbyid(x).visibility = 1;

my question is, if declaring mynewscene global variable , assigning within scene creation why browser think should function?

thanks.

change this:

if (babylon.engine.issupported()) { var mynewscene = null; var canvas = document.getelementbyid("rendercanvas"); var engine = new babylon.engine(canvas, true);

to this:

var mynewscene, canvas, engine; if (babylon.engine.issupported()) { mynewscene = null; canvas = document.getelementbyid("rendercanvas"); engine = new babylon.engine(canvas, true);

javascript babylonjs

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -