-
Notifications
You must be signed in to change notification settings - Fork 33
/
ThreeJS-Demo.html
123 lines (92 loc) · 3.31 KB
/
ThreeJS-Demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Three.js - Basic scene</title>
<style>
html, body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script src="http://threejs.org/build/three.js"></script>
<script src="gl-matrix.js"></script>
<script src="flatbuffers.js"></script>
<script src="CreatureFlatData_generated.js"></script>
<script src="CreatureMeshBone.js"></script>
<script src="CreatureThreeJSRenderer.js"></script>
<script>
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', 'fox0x.json', true); // Replace 'my_data' with the path to your file
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
// callback(xobj.responseText);
var response = xobj.responseText;
// Parse JSON string into object
var actual_JSON = JSON.parse(response);
var scene;
var camera;
var renderer;
var new_creature;
var new_manager;
var new_creature_renderer;
function initScene() {
// Create scene
scene = new THREE.Scene();
// This creates and positions a free camera
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = -20;
camera.lookAt(scene.position);
scene.add(camera);
// create renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
new_creature = new Creature(actual_JSON, false);
var new_animation_1 = new CreatureAnimation(actual_JSON, "default", false);
var new_animation_2 = new CreatureAnimation(actual_JSON, "run", false);
new_manager = new CreatureManager(new_creature);
new_manager.AddAnimation(new_animation_1);
new_manager.AddAnimation(new_animation_2);
new_manager.SetActiveAnimationName("default", false);
new_manager.SetShouldLoop(true);
new_manager.SetIsPlaying(true);
new_manager.RunAtTime(0);
//var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var texture = new THREE.TextureLoader().load("fox.png");
var material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side:THREE.DoubleSide
});
// Create creature renderer
new_creature_renderer = new CreatureRenderer("CreatureRenderer",
scene, new_manager,
material);
// Flip creature to the right
new_creature_renderer.renderMesh.scale.x = -1;
}
var animateScene = function () {
new_manager.Update(0.05);
new_creature_renderer.UpdateData();
requestAnimationFrame(animateScene);
renderer.render(scene, camera);
};
initScene();
animateScene();
}
};
xobj.send(null);
</script>
</body>
</html>