-
Book Overview & Buying
-
Table Of Contents
WebGL Beginner's Guide
Let's create a simple model: a 3D line. Here we will be focusing on how we do JSON encoding and decoding. Follow the given steps:
Go to your Internet browser and open the interactive JavaScript console. Use the following table for assistance:
|
Web browser |
Menu option |
Shortcut keys (PC / Mac) |
|
Firefox |
Tools | Web Developer | Web Console |
Ctrl + Shift + K / Command + Alt + K |
|
Safari |
Develop | Show Web Inspector |
Ctrl + Shift + C / Command + Alt + C |
|
Chrome |
Tools | JavaScript Console |
Ctrl + Shift + J / Command + Alt + J |
Create a JSON object by typing:
var model = {"vertices":[0,0,0,1,1,1], "indices":[0,1]};Verify that the model is an object by writing:
typeof(model)
Now, let's print the model attributes. Write this in the console (press Enter at the end of each line):
model.vertices model.indices
Now, let's create a JSON text:
var text = JSON.stringify(model) alert(text)
What happens when you type text.vertices?
As you can see, you get an...
Change the font size
Change margin width
Change background colour