stlviewer.js

Thu, 06 Apr 2017 19:00:07 +0200

author
mdd
date
Thu, 06 Apr 2017 19:00:07 +0200
changeset 22
08f0118587d7
parent 19
32de35694e56
permissions
-rw-r--r--

ht is not PVC....

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

mercurial