Skip to content

Commit 8873971

Browse files
committed
Fixed loading local files (no HTTPRequest)
1 parent cd75013 commit 8873971

File tree

6 files changed

+301
-17
lines changed

6 files changed

+301
-17
lines changed

Diff for: index.html

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<a href="https://github.com/drojdjou/basicwebgl/zipball/master">WebGL training files</a>
4+
</body>
5+
</html>

Diff for: samples/009_j3d.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html>
22
<head>
33
<script type="text/javascript" src="lib/j3d.js"></script>
4+
<script type="text/javascript" src="lib/cubeLocal.js"></script>
45

56
<script>
67
var engine, cube;
@@ -10,8 +11,8 @@
1011
engine.setClearColor(J3D.Color.white);
1112

1213
cube = new J3D.Transform();
13-
J3D.Loader.loadJSON("http://localhost/basicwebgl/samples/lib/cube.json", function(j) { cube.mesh = new J3D.Mesh(j); } );
14-
//J3D.Loader.loadJSON("lib/cube.json", function(j) { cube.mesh = new J3D.Mesh(j); } );
14+
//J3D.Loader.loadJSON("lib/cube.json", function(j) { cube.mesh = new J3D.Mesh(j); } );
15+
cube.mesh = new J3D.Mesh(Cube);
1516
cube.renderer = new J3D.Normal2Color();
1617

1718
var camera = new J3D.Camera(45);

Diff for: samples/010_j3d.html

+13-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
<script type="text/javascript" src="lib/j3d.js"></script>
55

6+
<script type="text/javascript" src="lib/textLocal.js"></script>
7+
<script type="text/javascript" src="lib/textLocalScene.js"></script>
8+
69
<script>
710
var mx, my = 0;
811
var jsonScene;
@@ -12,24 +15,19 @@
1215
function init() {
1316
engine = new J3D.Engine();
1417

15-
J3D.Loader.loadJSON("lib/text.json", function(jsmeshes) {
16-
J3D.Loader.loadJSON("lib/textScene.json", function(jsscene) {
17-
jsonScene = jsscene;
18-
J3D.Loader.parseJSONScene(jsscene, jsmeshes, engine);
18+
J3D.Loader.parseJSONScene(TextScene, Text, engine);
1919

20-
root = engine.scene.find("root");
20+
root = engine.scene.find("root");
2121

22-
rings[0] = engine.scene.find("root/ring1");
23-
rings[1] = engine.scene.find("root/ring1/ring2");
24-
rings[2] = engine.scene.find("root/ring1/ring2/ring3");
25-
rings[3] = engine.scene.find("root/ring1/ring2/ring3/ring4");
26-
rings[4] = engine.scene.find("root/ring1/ring2/ring3/ring4/ring5");
27-
rings[5] = engine.scene.find("root/ring1/ring2/ring3/ring4/ring5/ring6");
28-
rings[6] = engine.scene.find("root/ring1/ring2/ring3/ring4/ring5/ring6/ring7");
22+
rings[0] = engine.scene.find("root/ring1");
23+
rings[1] = engine.scene.find("root/ring1/ring2");
24+
rings[2] = engine.scene.find("root/ring1/ring2/ring3");
25+
rings[3] = engine.scene.find("root/ring1/ring2/ring3/ring4");
26+
rings[4] = engine.scene.find("root/ring1/ring2/ring3/ring4/ring5");
27+
rings[5] = engine.scene.find("root/ring1/ring2/ring3/ring4/ring5/ring6");
28+
rings[6] = engine.scene.find("root/ring1/ring2/ring3/ring4/ring5/ring6/ring7");
2929

30-
draw();
31-
})
32-
});
30+
draw();
3331

3432
document.onmousemove = onMouseMove;
3533
}

Diff for: samples/lib/cubeLocal.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var Cube = {
2+
"vertices": [0.5,-0.5,-0.5,-0.5,-0.5,-0.5,0.5,0.5,-0.5,-0.5,0.5,-0.5,0.5,0.5,0.5,-0.5,0.5,0.5,0.5,-0.5,0.5,-0.5,-0.5,0.5,0.5,0.5,-0.5,-0.5,0.5,-0.5,0.5,0.5,0.5,-0.5,0.5,0.5,0.5,-0.5,0.5,-0.5,-0.5,-0.5,-0.5,-0.5,0.5,0.5,-0.5,-0.5,-0.5,-0.5,-0.5,-0.5,0.5,0.5,-0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,-0.5,0.5,0.5,0.5,-0.5,0.5,-0.5,-0.5,0.5,0.5,0.5],
3+
"normals": [0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0,1,0,0,1,0,0,1,0,0],
4+
"colors": [],
5+
"uv1": [0,0,1,0,0,1,1,1,0,1,1,1,0,1,1,1,0,0,1,0,0,0,1,0,0,0,1,1,1,0,0,1,0,0,1,1,1,0,0,1,0,0,1,1,1,0,0,1],
6+
"uv2": [],
7+
"tris": [1,0,3,3,0,2,9,8,5,5,8,4,11,10,7,7,10,6,14,12,13,13,12,15,18,16,17,17,16,19,22,20,21,21,20,23]
8+
}

Diff for: samples/lib/textLocal.js

+75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: samples/lib/textLocalScene.js

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
var TextScene = {
2+
3+
"path" : "",
4+
"ambient": { "r":0, "g":0, "b":0, "a":1 },
5+
"background": { "r":0, "g":0, "b":0, "a":1 },
6+
7+
"textures": {
8+
},
9+
10+
"materials": {
11+
12+
"violet": {
13+
"type": "Phong",
14+
"color": { "r":0.6074271, "g":0, "b":1, "a":1 },
15+
"specularIntensity": 31.54149,
16+
"textureTile": [ ],
17+
"textureOffset": [ ]
18+
},
19+
20+
"yellow": {
21+
"type": "Phong",
22+
"color": { "r":1, "g":1, "b":0, "a":1 },
23+
"specularIntensity": 29.65015,
24+
"textureTile": [ ],
25+
"textureOffset": [ ]
26+
},
27+
28+
"grey": {
29+
"type": "Gouraud",
30+
"color": { "r":0.5074627, "g":0.5074627, "b":0.5074627, "a":1 },
31+
"specularIntensity": 80.71642,
32+
"textureTile": [ ],
33+
"textureOffset": [ ]
34+
},
35+
36+
"green": {
37+
"type": "Phong",
38+
"color": { "r":0, "g":1, "b":0, "a":1 },
39+
"specularIntensity": 76.93373,
40+
"textureTile": [ ],
41+
"textureOffset": [ ]
42+
},
43+
44+
"light_green": {
45+
"type": "Phong",
46+
"color": { "r":0.7078295, "g":1, "b":0, "a":1 },
47+
"specularIntensity": 31.54149,
48+
"textureTile": [ ],
49+
"textureOffset": [ ]
50+
},
51+
52+
"orange": {
53+
"type": "Phong",
54+
"color": { "r":1, "g":0.4980392, "b":0, "a":1 },
55+
"specularIntensity": 27.7588,
56+
"textureTile": [ ],
57+
"textureOffset": [ ]
58+
},
59+
60+
"redlight": {
61+
"type": "Phong",
62+
"color": { "r":1, "g":0, "b":0, "a":1 },
63+
"specularIntensity": 0,
64+
"textureTile": [ ],
65+
"textureOffset": [ ]
66+
},
67+
68+
"blue": {
69+
"type": "Phong",
70+
"color": { "r":0, "g":0.4980392, "b":1, "a":1 },
71+
"specularIntensity": 8.845374,
72+
"textureTile": [ ],
73+
"textureOffset": [ ]
74+
}
75+
76+
},
77+
78+
"lights": {
79+
80+
"sun": {
81+
"type": 1,
82+
"color": { "r":1, "g":1, "b":1, "a":1 },
83+
"direction": [ -0.1517519,0.7256743,0.6710949 ]
84+
}
85+
86+
},
87+
88+
"cameras": {
89+
90+
"camera": {
91+
"fov": 60,
92+
"near": 0.3,
93+
"far": 1000
94+
}
95+
96+
},
97+
98+
"transforms": [
99+
100+
{
101+
"name": "sun",
102+
"position": [ 0,0,0.01425409 ],
103+
"rotation": [ -0.8351003,-3.136525,0.2129833 ],
104+
"light": "sun"
105+
},
106+
107+
{
108+
"name": "root",
109+
"position": [ 0,0,2 ],
110+
"rotation": [ 0,0,0 ]
111+
},
112+
113+
{
114+
"name": "ring1",
115+
"parent": "root",
116+
"position": [ 0,0,0 ],
117+
"rotation": [ 0,0,0 ],
118+
"renderer": "redlight",
119+
"mesh": "ring1"
120+
},
121+
122+
{
123+
"name": "ring2",
124+
"parent": "ring1",
125+
"position": [ 0,0,0 ],
126+
"rotation": [ 0,0,0 ],
127+
"renderer": "orange",
128+
"mesh": "ring2"
129+
},
130+
131+
{
132+
"name": "ring3",
133+
"parent": "ring2",
134+
"position": [ 0,0,0 ],
135+
"rotation": [ 0,0,0 ],
136+
"renderer": "yellow",
137+
"mesh": "ring3"
138+
},
139+
140+
{
141+
"name": "ring4",
142+
"parent": "ring3",
143+
"position": [ 0,0,0 ],
144+
"rotation": [ 0,0,0 ],
145+
"renderer": "light_green",
146+
"mesh": "ring4"
147+
},
148+
149+
{
150+
"name": "ring5",
151+
"parent": "ring4",
152+
"position": [ 0,0,0 ],
153+
"rotation": [ 0,0,0 ],
154+
"renderer": "green",
155+
"mesh": "ring5"
156+
},
157+
158+
{
159+
"name": "ring6",
160+
"parent": "ring5",
161+
"position": [ 0,0,0 ],
162+
"rotation": [ 0,0,0 ],
163+
"renderer": "blue",
164+
"mesh": "ring6"
165+
},
166+
167+
{
168+
"name": "ring7",
169+
"parent": "ring6",
170+
"position": [ 0,0,0 ],
171+
"rotation": [ 0,0,0 ],
172+
"renderer": "violet",
173+
"mesh": "ring7"
174+
},
175+
176+
{
177+
"name": "text",
178+
"parent": "root",
179+
"position": [ 0,0,0 ],
180+
"rotation": [ 0,0,0 ],
181+
"renderer": "grey",
182+
"mesh": "text"
183+
},
184+
185+
{
186+
"name": "camera",
187+
"position": [ 0,0,-0.5 ],
188+
"rotation": [ 0,3.141592,0 ],
189+
"camera": "camera"
190+
}
191+
192+
]
193+
}
194+
195+
196+
197+

0 commit comments

Comments
 (0)