-
Notifications
You must be signed in to change notification settings - Fork 7
/
example_spinning_cube.html
159 lines (99 loc) · 3.3 KB
/
example_spinning_cube.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<title>crayon.js - spinning cube example</title>
<meta charset="utf-8">
<style>
body {
margin: 0px;
background-color: #000000;
overflow: hidden;
}
</style>
</head>
<body>
<!--
This example demostrates a simple scene
with post processing nodes.
You can connect nodes to each other
in different ways.
-->
<script src="three.min.js"></script>
<script src="ThreeUtils2.js"></script>
<!-- <script src="toon.js"></script> -->
<script src="crayon.js"></script>
<script>
var camera, scene, renderer;
var mesh;
init();
animate();
function init() {
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
//
CRAYON.extends( 'SceneNode', CRAYON.ShaderNode, {
init: function() {
CRAYON.ShaderNode.call( this );
// Renders scene to Render Target
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
// camera.position.z = 400;
camera.position.y = 50;
camera.position.z = 500;
scene = new THREE.Scene();
var geometry = new THREE.CubeGeometry( 200, 200, 200 );
material_depth = new THREE.MeshDepthMaterial();
function directionalLight(x, y, z, color) {
var light = new THREE.DirectionalLight(color);
light.position.set(x,y,z).normalize();
return light;
}
var material = new THREE.MeshPhongMaterial( { // MeshPhongMaterial MeshLambertMaterial
color: 0xfa9204,
emissive: 0x333333,
specular: 0xffffff,
shininess: 20
// shading: THREE.FlatShading
} );
// scene.add(new THREE.AmbientLight(0x333333));
scene.add(directionalLight(.2,0,1, 0xeeeeee));
// cube = new THREE.Mesh( geometry, material );
// cube.rotation.x = 0.2;
// scene.add( cube );
var geometry = new THREE.TorusKnotGeometry( 120 );
torus = new THREE.Mesh( geometry, material );
scene.add( torus );
},
render: function() {
var timer = Date.now();
torus.rotation.y = timer * 0.0005;
renderer.render( scene, camera, this.renderTarget );
}
} );
//
sceneNode = new CRAYON.SceneNode();
sceneDepthNode = new CRAYON.SceneDepthNode( sceneNode );
screenNode = new CRAYON.RenderToScreenNode( renderer );
edgeNode = new CRAYON.EdgeFilterNode( renderer );
multiplyNode = new CRAYON.MultiplyNode( renderer );
executorNode = new CRAYON.ExecutorNode( renderer );
sceneNode.connect(sceneDepthNode, 'texture');
sceneDepthNode.connect(edgeNode, 'texture');
edgeNode.connect(multiplyNode, 'texture1')
sceneNode.connect(multiplyNode, 'texture2')
multiplyNode.connect(screenNode, 'texture') //
screenNode.connect(executorNode, 'edge') //
// window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
executorNode.renderAll();
}
</script>
</body>
</html>