stlviewer.js

Thu, 06 Apr 2017 16:21:21 +0200

author
mdd
date
Thu, 06 Apr 2017 16:21:21 +0200
changeset 18
ff1941c85fd3
parent 17
dee15870206a
child 19
32de35694e56
permissions
-rw-r--r--

added 2d image to 3d viewer

11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
1 $( function() {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
2 $( "#sortable1 li" ).draggable({
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
3 helper: "clone",
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
4 containment:"document"
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
5 });
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
6 $( "#sortable2" ).droppable({
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
7 accept: "#sortable1 li",
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
8 drop: function( event, ui ) {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
9 ui.draggable.clone(false).appendTo($(this));
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
10 for (i =0; i<10; i++) clear_scene();
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
11 window.setTimeout(update_scene,500);
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
12 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
13 });
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
14 $( "#sortable2" ).sortable({
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
15 placeholder: "ui-state-highlight",
13
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
16 forcePlaceholderSize: true,
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
17 connectWith: '#sortable1',
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
18 start: clear_scene,
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
19 stop: function() {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
20 for (i =0; i<10; i++) clear_scene();
13
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
21 window.setTimeout(update_scene,500);
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
22 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
23 });
13
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
24 c = $("<li key='10'>").html("Steel, 10ℓ");
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
25 $( "#sortable2" )
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
26 .disableSelection()
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
27 .append(c.clone())
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
28 .append(c.clone());
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
29
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
30 $("#clearselected").click(function(){
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
31 $( "#sortable2 li" ).remove();
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
32 for (i =0; i<10; i++) clear_scene();
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
33 });
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
34 update_scene();
18
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
35
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
36 $("#image2d").click(function() {
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
37 var img = $("#image2d").clone();
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
38 //img.css('width', '100%');
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
39 img.css('margin', '0 auto');
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
40 $("<div>")
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
41 .append(img)
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
42 .dialog({
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
43 modal: true,
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
44 draggable: false,
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
45 resizable: false,
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
46 title: "2D Layout view",
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
47 height: window.innerHeight,
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
48 width: window.innerWidth,
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
49 buttons: {
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
50 Close: function() {
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
51 $( this ).dialog( "close" );
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
52 }
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
53 }
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
54 });
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
55 });
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
56 } );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
57
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
58 function clear_scene() {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
59 scene.children.forEach(function(v){
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
60 if(v.stlfile === true) {
12
b3cf0176512e finished webrenderer
mdd
parents: 11
diff changeset
61 //v.material.dispose();
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
62 v.geometry.dispose();
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
63 scene.remove(v);
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
64 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
65 //scene.remove(object);
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
66 });
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
67 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
68
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
69 function update_scene() {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
70 var cylinders = [];
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
71 $("#sortable2 li").each(function(idx, e){
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
72 cylinders.push($(e).attr('key'));
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
73 });
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
74 if (cylinders.length < 2) return;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
75
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
76 // fetch new objects list
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
77 $.ajax({
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
78 url: "#",
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
79 method: 'post',
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
80 dataType: 'json',
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
81 data: {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
82 action: 'calculate',
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
83 cylinders: cylinders
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
84 },
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
85 success: function(data) {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
86 //console.log(data);
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
87 // remove all meshes
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
88 clear_scene();
17
dee15870206a added text info box
mdd
parents: 13
diff changeset
89 var content = "<h2>Material:</h2><ul>";
dee15870206a added text info box
mdd
parents: 13
diff changeset
90 var weight = 0.0;
dee15870206a added text info box
mdd
parents: 13
diff changeset
91 var length = 0;
dee15870206a added text info box
mdd
parents: 13
diff changeset
92 var volume = 0;
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
93 // append the objects with positioning
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
94 for (i = 0; i<data.objects.length; i++) {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
95 var obj = data.objects[i];
17
dee15870206a added text info box
mdd
parents: 13
diff changeset
96 content += "<li>";
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
97 if (obj[5] == "") {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
98 // spacer
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
99 filename = "stl/spacer_" + obj[4][0] + '.stl';
12
b3cf0176512e finished webrenderer
mdd
parents: 11
diff changeset
100 material = 'm_spacer';
17
dee15870206a added text info box
mdd
parents: 13
diff changeset
101 content += "Spacer: " + obj[4][0] + " (" + obj[4][1] + "mm)"
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
102 } else {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
103 // cylinder
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
104 filename = "stl/cylinder_" + obj[5] + '.stl';
12
b3cf0176512e finished webrenderer
mdd
parents: 11
diff changeset
105 material = 'm_cylinder';
17
dee15870206a added text info box
mdd
parents: 13
diff changeset
106 content += "Cylinder: " + obj[4][4] + " (" + obj[4][0] + "mm)"
dee15870206a added text info box
mdd
parents: 13
diff changeset
107 weight += obj[4][3];
dee15870206a added text info box
mdd
parents: 13
diff changeset
108 volume += obj[4][2];
dee15870206a added text info box
mdd
parents: 13
diff changeset
109 if (obj[4][1] > length) length = obj[4][1];
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
110 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
111 position = [data.scale3d * 0.01 * obj[0], 0, 0];
12
b3cf0176512e finished webrenderer
mdd
parents: 11
diff changeset
112 loadSTL(filename, material + "", position);
17
dee15870206a added text info box
mdd
parents: 13
diff changeset
113 content += "</li>"
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
114 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
115
17
dee15870206a added text info box
mdd
parents: 13
diff changeset
116 content += "</ul><br/>Total cylinder weight: " + Math.ceil(weight) + " kg<br/>";
dee15870206a added text info box
mdd
parents: 13
diff changeset
117 content += "Total cylinder volume: " + Math.floor(volume) + " ℓ<br/>";
dee15870206a added text info box
mdd
parents: 13
diff changeset
118 content += "Max cylinder length: " + Math.ceil(length / 10) + " cm<br/>"
dee15870206a added text info box
mdd
parents: 13
diff changeset
119
dee15870206a added text info box
mdd
parents: 13
diff changeset
120 $("#infocontainer").html(content);
dee15870206a added text info box
mdd
parents: 13
diff changeset
121
18
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
122 $("#image2d").attr('src', 'data:image/png;base64,' + data.image);
ff1941c85fd3 added 2d image to 3d viewer
mdd
parents: 17
diff changeset
123
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
124 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
125 });
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
126 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
127
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
128 function loadSTL(filename, material, position, rotation, scale) {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
129 //console.log(filename, position);
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
130 var loader = new THREE.STLLoader();
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
131 loader.load( filename, function ( geometry ) {
13
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
132 if (material == 'm_spacer') material = m_spacer;
12
b3cf0176512e finished webrenderer
mdd
parents: 11
diff changeset
133 else if (material == 'm_cylinder') material = m_cylinder;
13
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
134
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
135 var mesh = new THREE.Mesh( geometry, material );
13
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
136
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
137 mesh["stlfile"] = true;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
138 if (!position) mesh.position.set( 0, -0.25, 0 ); else
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
139 mesh.position.set( position[0], position[1], position[2] );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
140 if (!rotation) mesh.rotation.set( 0, 0, 0 ); else
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
141 mesh.rotation.set( rotation[0], rotation[1], rotation[2] );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
142 if (!scale) mesh.scale.set( 0.01, 0.01, 0.01 ); else
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
143 mesh.scale.set( scale[0], scale[1], scale[2] );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
144
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
145 mesh.castShadow = true;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
146 mesh.receiveShadow = true;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
147
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
148 scene.add( mesh );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
149
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
150 } );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
151
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
152 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
153
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
154 function init() {
13
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
155 container = document.getElementById( 'rendercontainer' );
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
156 //document.body.appendChild( container );
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
157
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
158 camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 20 );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
159 camera.position.set( 0.5, 0.35, 2 );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
160
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
161 cameraTarget = new THREE.Vector3( 0, -0.25, 0 );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
162
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
163 scene = new THREE.Scene();
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
164 scene.fog = new THREE.Fog( 0x72645b, 2, 15 );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
165
13
39fb313ba27c finished viewer again, giving up with texturing mesh without uv mapping
mdd
parents: 12
diff changeset
166 controls = new THREE.OrbitControls(camera);
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
167
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
168 // Ground
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
169
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
170 var plane = new THREE.Mesh(
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
171 new THREE.PlaneBufferGeometry( 40, 40 ),
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
172 new THREE.MeshPhongMaterial( { color: 0x999999, specular: 0x101010 } )
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
173 );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
174 plane.rotation.x = -Math.PI/2;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
175 plane.position.y = -0.5;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
176 scene.add( plane );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
177
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
178 plane.receiveShadow = true;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
179
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
180 // Lights
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
181
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
182 scene.add( new THREE.HemisphereLight( 0x443333, 0x111122 ) );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
183
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
184 addShadowedLight( 1, 1, 1, 0xffffff, 1.35 );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
185 //addShadowedLight( 0.5, 1, -1, 0xffaa00, 1 );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
186 // renderer
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
187
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
188 renderer = new THREE.WebGLRenderer( { antialias: true } );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
189 renderer.setClearColor( scene.fog.color );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
190 renderer.setPixelRatio( window.devicePixelRatio );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
191 renderer.setSize( window.innerWidth, window.innerHeight );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
192
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
193 renderer.gammaInput = true;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
194 renderer.gammaOutput = true;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
195
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
196 renderer.shadowMap.enabled = true;
12
b3cf0176512e finished webrenderer
mdd
parents: 11
diff changeset
197 renderer.shadowMap.renderReverseSided = false;
11
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
198
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
199 container.appendChild( renderer.domElement );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
200
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
201 window.addEventListener( 'resize', onWindowResize, false );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
202
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
203 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
204
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
205 function addShadowedLight( x, y, z, color, intensity ) {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
206
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
207 var directionalLight = new THREE.DirectionalLight( color, intensity );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
208 directionalLight.position.set( x, y, z );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
209 scene.add( directionalLight );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
210
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
211 directionalLight.castShadow = true;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
212
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
213 var d = 5;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
214 directionalLight.shadow.camera.left = -d;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
215 directionalLight.shadow.camera.right = d;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
216 directionalLight.shadow.camera.top = d;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
217 directionalLight.shadow.camera.bottom = -d;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
218
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
219 directionalLight.shadow.camera.near = 1;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
220 directionalLight.shadow.camera.far = 20;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
221
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
222 directionalLight.shadow.mapSize.width = 1024;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
223 directionalLight.shadow.mapSize.height = 1024;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
224
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
225 directionalLight.shadow.bias = -0.005;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
226
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
227 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
228
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
229 function onWindowResize() {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
230
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
231 camera.aspect = window.innerWidth / window.innerHeight;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
232 camera.updateProjectionMatrix();
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
233
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
234 renderer.setSize( window.innerWidth, window.innerHeight );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
235
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
236 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
237
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
238 function animate() {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
239
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
240 requestAnimationFrame( animate );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
241
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
242 //render();
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
243 renderer.render( scene, camera );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
244 //stats.update();
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
245
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
246 }
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
247
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
248 function render() {
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
249 var timer = Date.now() * 0.0005;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
250 camera.position.x = Math.cos( timer ) * 3;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
251 camera.position.z = Math.sin( timer ) * 3;
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
252 camera.lookAt( cameraTarget );
098335a1d510 web viewer 3d finished
mdd
parents:
diff changeset
253 renderer.render( scene, camera );
12
b3cf0176512e finished webrenderer
mdd
parents: 11
diff changeset
254 }

mercurial