Salut à tous, je suis actuellement en train d'essayer d'intégrer du WebGL dans un projet Webdev voici mon code que j'utilise hors Webdev :
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>WebGL 3D model viewer using three.js</title>
 
</head>
<body>
<script type="text/javascript" src="build/three.js"></script>
 
<script type="text/javascript" src="examples/js/controls/TrackballControls.js"></script>
 
<script type="text/javascript" src="examples/js/libs/stats.min.js"></script>
 
<script type="text/javascript" src="examples/js/loaders/OBJLoader.js"></script>
 
<script  type="text/javascript">
 
var container, stats;
var camera, controls, scene, projector, renderer;
var objects = [], plane;
 
var mouse = new THREE.Vector2(),
offset = new THREE.Vector3(),
INTERSECTED, SELECTED;
 
init();
animate();
 
function init() {
 
        container = document.createElement( 'div' );
        document.body.appendChild( container );
 
        camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 );
        camera.position.z = 100;
 
        controls = new THREE.TrackballControls( camera );
        controls.rotateSpeed = 1.0;
        controls.zoomSpeed = 1.2;
        controls.panSpeed = 0.8;
        controls.noZoom = false;
        controls.noPan = false;
        controls.staticMoving = true;
        controls.dynamicDampingFactor = 0.3;
 
        scene = new THREE.Scene();
 
        scene.add( new THREE.AmbientLight( 0x505050 ) );
 
        var light = new THREE.SpotLight( 0xffffff, 1.5 );
        light.position.set( 0, 500, 2000 );
        light.castShadow = true;
 
        light.shadowCameraNear = 200;
        light.shadowCameraFar = camera.far;
        light.shadowCameraFov = 50;
 
        light.shadowBias = -0.00022;
        light.shadowDarkness = 0.5;
 
        light.shadowMapWidth = 2048;
        light.shadowMapHeight = 2048;
 
        scene.add( light );
 
                // texture
                
                var manager = new THREE.LoadingManager();
                manager.onProgress = function ( item, loaded, total ) {
                
                console.log( item, loaded, total );
                
                };
                
                var texture = new THREE.Texture();
                
                var loader = new THREE.ImageLoader( manager );
                loader.load('examples/textures/bois.jpg', function ( image ) {
                
                texture.image = image;
                texture.needsUpdate = true;
                
                } );
                
                // model
                
                var loader = new THREE.OBJLoader( manager );
                loader.load('5388.obj', function ( object ) {
                
                object.traverse( function ( child ) {
                
                if ( child instanceof THREE.Mesh ) {
                
                child.material.map = texture;
                
                }
                
                } );
                
                object.position.y = 0;
                scene.add( object );
                objects.push( object );
                } );
                
                plane = new THREE.Mesh( new THREE.PlaneGeometry( 2000, 2000, 8, 8 ), new THREE.MeshBasicMaterial( { color: 0x000000, opacity: 0.25, transparent: true, wireframe: true } ) );
                plane.visible = false;
                scene.add( plane );
                
                projector = new THREE.Projector();
                
                renderer = new THREE.WebGLRenderer( { antialias: true } );
                renderer.setClearColor( 0xf0f0f0 );
                renderer.setSize( window.innerWidth, window.innerHeight );
                renderer.sortObjects = false;
                
                renderer.shadowMapEnabled = true;
                renderer.shadowMapType = THREE.PCFShadowMap;
                
                container.appendChild( renderer.domElement );
                
                var Info = document.createElement( 'div' );
                Info.style.position = 'absolute';
                Info.style.top = '10px';
                Info.style.width = '100%';
                Info.style.textAlign = 'center';
                container.appendChild( Info );
                
                stats = new Stats();
                stats.domElement.style.position = 'absolute';
                stats.domElement.style.top = '0px';
                container.appendChild( stats.domElement );
                
                renderer.domElement.addEventListener( 'mousemove', onDocumentMouseMove, false );
                renderer.domElement.addEventListener( 'mousedown', onDocumentMouseDown, false );
                renderer.domElement.addEventListener( 'mouseup', onDocumentMouseUp, false );
                
                //
                
                window.addEventListener( 'resize', onWindowResize, false );
        
}
        
function onWindowResize() {
        
        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();
                
        renderer.setSize( window.innerWidth, window.innerHeight );
        
}
        
function onDocumentMouseMove( Event ) {
        
        Event.preventDefault();
        
        mouse.x = ( Event.clientX / window.innerWidth ) * 2 - 1;
        mouse.y = - ( Event.clientY / window.innerHeight ) * 2 + 1;
        
        //
        
        var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
        projector.unprojectVector( vector, camera );
        
        var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
        
        
        if ( SELECTED ) {
                
                var intersects = raycaster.intersectObject( plane );
                SELECTED.position.copy( intersects[ 0 ].point.sub( offset ) );
                RETURN;
                
        }
                
                
        var intersects = raycaster.intersectObjects( objects );
                
        if ( intersects.Length > 0 ) {
                        
                if ( INTERSECTED != intersects[ 0 ].object ) {
                                        
                        if ( INTERSECTED ) INTERSECTED.material.color.setHex( INTERSECTED.currentHex );
                                        
                        INTERSECTED = intersects[ 0 ].object;
                        INTERSECTED.currentHex = INTERSECTED.material.color.getHex();
                                                
                        plane.position.copy( INTERSECTED.position );
                        plane.lookAt( camera.position );
                                        
                }
                                        
                container.style.cursor = 'pointer';
                                
        } else {
                                
                if ( INTERSECTED ) INTERSECTED.material.color.setHex( INTERSECTED.currentHex );
                                        
                INTERSECTED = null;
                                        
                container.style.cursor = 'auto';
                                
        }
                                
}
                                
function onDocumentMouseDown( Event ) {
                                
        Event.preventDefault();
                                        
        var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
        projector.unprojectVector( vector, camera );
                                        
        var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
                                        
        var intersects = raycaster.intersectObjects( objects );
                                        
        if ( intersects.Length > 0 ) {
                                        
                controls.enabled = false;
                                        
                SELECTED = intersects[ 0 ].object;
                                                
                var intersects = raycaster.intersectObject( plane );
                offset.copy( intersects[ 0 ].point ).sub( plane.position );
                                                
                container.style.cursor = 'Move';
                                        
        }
                                
}
                                        
function onDocumentMouseUp( Event ) {
                                        
        Event.preventDefault();
                                        
        controls.enabled = true;
                                        
        if ( INTERSECTED ) {
 
                plane.position.copy( INTERSECTED.position );
 
                SELECTED = null;
 
        }
 
        container.style.cursor = 'auto';
 
}
 
//
 
function animate() {
 
        requestAnimationFrame( animate );
 
        render();
        stats.update();
 
}
 
function render() {
 
        controls.update();
 
        renderer.render( scene, camera );
 
}
 
</script>  
 
</body>
</html>

Avec ceci j'ai un objet qui apparait à l'écran et que je peux visualiser sous tout les angles, mais dès que je fais les adaptations nécessaires pour l'intégrer dans Webdev et bien plus rien ne s'affiche.
Dans la description de la page, j'ajoute bien les fichiers .js nécessaire (Three, Trackball, stats.min, OBJLoader) et j'ajoute le code dans des chaînes dans l'initialisation du champ HTML et quand j'utilise Firebug quand je clique sur le nom du fichier .obj dans l'onglet HTML j'ai un fameux L'url '/' n'est pas valide (ICU226). (20, ERR_BAD_URL)

Du coup est-ce que ce n'est pas encore possible d'utiliser du WebGL dans Webdev ou ai-je fais une erreur (ce qui est plus probable).

Après j'ai un autre petit problème, la zone d'affichage de l'objet se met en bas à gauche de l'écran, hors de la zone du champ HTML sous Webdev. Mais ça c'est moins important pour le moment