Anonymous     ActionScript     09 Sep 2008    
  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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
import flash.display.DisplayObject;
//********Import Tweener classes*******//
import caurina.transitions.Tweener;
import caurina.transitions.properties.FilterShortcuts;
import caurina.transitions.properties.CurveModifiers;
import caurina.transitions.properties.DisplayShortcuts;
import caurina.transitions.properties.FilterShortcuts;
import caurina.transitions.properties.ColorShortcuts;
FilterShortcuts.init();
DisplayShortcuts.init();
CurveModifiers.init();
FilterShortcuts.init();
ColorShortcuts.init();
//********Import Papervision3D classes********//
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.lights.*;
import org.papervision3d.render.*;
import org.papervision3d.view.*;
import org.papervision3d.events.*;
import org.papervision3d.core.utils.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.utils.virtualmouse.VirtualMouse;
import org.papervision3d.objects.parsers.Collada;
import org.papervision3d.objects.parsers.DAE;
//shaders
import org.papervision3d.materials.shaders.*;
//********Declare variables********//
var viewport: Viewport3D;
var scene: Scene3D;
var camera: Camera3D;
var primitive: Plane;
var renderer: BasicRenderEngine;
var puppy: Collada;
var tree: Collada;
var materialsList1: MaterialsList;
var colorMaterial1: ColorMaterial;
var colorMaterial2: ColorMaterial;
var bitmapFileMaterial: BitmapFileMaterial;
var light: PointLight3D;
var cube:Cube;
//var flatShadeMat:FlatShadeMaterial;
var xDist:Number;
var yDist:Number;
//Коэффициент изменения размеров
var sizer:Number = 1000;
//viewport = new BasicRenderEngine(width, height, scaleToStage, interactive);
viewport = new Viewport3D(800, 480, false, true);
addChild(viewport);
//Ставим кнопку закрытия
var close_but:close_button = new close_button();
close_but.x = 740;
close_but.y = 10;
addChild(close_but);
//instantiates a Scene3D instance
scene = new Scene3D();
//instantiates a Camera3D instance
camera = new Camera3D();
camera.focus = 1100;
camera.z = 0;
camera.rotationY = 0;
//Камера смотрит сверху под углом
camera.zoom = 0.65;
camera.y = -400;
camera.x = -1200;
camera.pitch(15);
//camera.lookAt(pc);
//renderer draws the scene to the stage
renderer = new BasicRenderEngine();
//FPS Monitor
addChild(new FPSMonitor());
//--------------------------------------
//--------------------------------------
//--------------------------------------
//
// TESTED AREA
//
//--------------------------------------
//--------------------------------------
//--------------------------------------
var pc_case:DisplayObject3D = new DisplayObject3D();
pc_case.x = -320;
pc_case.z = -350;
pc_case.y = -700;
//pc_case.rotationY = -100;
scene.addChild(pc_case);
//-------------------------------------------
// PC
//-------------------------------------------
var movieAssetMat_PC:MovieAssetMaterial = new MovieAssetMaterial("comp", false, true);
movieAssetMat_PC.smooth = true;
movieAssetMat_PC.interactive = true;
//movieAssetMat_PC.needsFaceNormals = true;
var materialsList_PC:MaterialsList = new MaterialsList();
materialsList_PC.addMaterial( movieAssetMat_PC, "comp" );
var pc:Collada = new Collada("models/pc.dae", materialsList_PC, 0.8);
pc.x = 85;
pc.z = 0;
pc.y = 40;
pc.rotationY = 90;
pc.addEventListener(FileLoadEvent.LOAD_COMPLETE, pc_LoadComplete);
pc_case.addChild(pc);
function pc_LoadComplete(e:Event):void {
pc.getChildByName("pc",true).addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, pc_Click );
pc.getChildByName("pc",true).addEventListener( InteractiveScene3DEvent.OBJECT_OVER, pc_Over );
pc.getChildByName("pc",true).addEventListener( InteractiveScene3DEvent.OBJECT_OUT, pc_Out );
}
function pc_Click( evt:InteractiveScene3DEvent ):void{
this.buttonMode = false;
/* Tweener.addTween(camera, { x:380, z:240, y:-4020, rotationY:0, time:1, transition:"lineral"} );
puppy.stop();*/
//TIPS: получаем доступ к свойства материала pc_plane3
var mat:MovieAssetMaterial = pc_plane3.material as MovieAssetMaterial;
var mc = MovieClip(mat.movie);
mc.hand.play();
Tweener.addTween(pc_folio_plane, { x:-60, z:-2, y:145, scale:1, time:1.5, transition:"easeInOutElastic"} );
//TIPS: удаление объекта
//убираем руку после клика
pc_case.removeChild(pc_plane5);
}
function pc_Over( evt:InteractiveScene3DEvent ):void{
this.buttonMode = true;
}
function pc_Out( evt:InteractiveScene3DEvent ):void{
this.buttonMode = false;
}
//--------------------------------
// Камера смотрит на PC
//--------------------------------
//camera.target = pc;
//camera.orbit(5, 5, true, pc);
//-------------------------------------------
// PC Plane
//-------------------------------------------
//TODO: разобраться с настройками MovieAssetMaterial - Linkage, Transparent, Animatted
var pc_plane_skin:MovieAssetMaterial = new MovieAssetMaterial( "pc_plane1",true,true);
pc_plane_skin.smooth = true;
pc_plane_skin.doubleSided = true;
var pc_plane:Plane = new Plane(pc_plane_skin, 175, 175, 2, 2);
pc_plane.x = 125;
pc_plane.z = 65;
pc_plane.y = 130;
pc_plane.rotationY = 90;
pc_case.addChild(pc_plane);
//-------------------------------------------
// PC Plane 2
//-------------------------------------------
var pc_plane_skin2:MovieAssetMaterial = new MovieAssetMaterial( "pc_plane2",true,true);
pc_plane_skin2.smooth = true;
pc_plane_skin2.doubleSided = true;
var pc_plane2:Plane = new Plane(pc_plane_skin2, 120, 120, 2, 2);
pc_plane2.x = 125;
pc_plane2.z = -20;
pc_plane2.y = 125;
pc_plane2.rotationY = 90;
pc_case.addChild(pc_plane2);
//-------------------------------------------
// PC Plane 3
//-------------------------------------------
var pc_plane_skin3:MovieAssetMaterial = new MovieAssetMaterial( "pc_plane3",true,true);
pc_plane_skin3.smooth = true;
pc_plane_skin3.doubleSided = true;
//TIPS: Прячет текстуру - как бы пропадает объект!!!!!
//pc_plane_skin3.invisible = true;
var pc_plane3:Plane = new Plane(pc_plane_skin3, 120, 120, 2, 2);
pc_plane3.x = 100;
pc_plane3.z = -137;
pc_plane3.y = 85;
pc_plane3.rotationY = 90;
pc_case.addChild(pc_plane3);
//pc_plane3.getChildByName("pc",true).addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, pc_plane3_Click );
/*pc_plane3.getChildByName("pc",true).addEventListener( InteractiveScene3DEvent.OBJECT_OVER, pc_plane3_Over );
pc_plane3.getChildByName("pc",true).addEventListener( InteractiveScene3DEvent.OBJECT_OUT, pc_plane3_Out );*/
function pc_plane3_Click( evt:InteractiveScene3DEvent ):void{
this.buttonMode = false;
/* Tweener.addTween(camera, { x:380, z:240, y:-4020, rotationY:0, time:1, transition:"lineral"} );
puppy.stop();*/
//TIPS: получаем доступ к свойства материала pc_plane3
var mat:MovieAssetMaterial = pc_plane3.material as MovieAssetMaterial;
var mc = MovieClip(mat.movie);
mc.hand.play();
Tweener.addTween(pc_folio_plane, { x:-60, z:-2, y:145, scale:1, time:1.5, transition:"easeInOutElastic"} );
//TIPS: удаление объекта
//убираем руку после клика
pc_case.removeChild(pc_plane5);
}
function pc_plane3_Over( evt:InteractiveScene3DEvent ):void{
this.buttonMode = true;
}
function pc_plane3_Out( evt:InteractiveScene3DEvent ):void{
this.buttonMode = false;
}
//-------------------------------------------
// PC Plane 4
//-------------------------------------------
var pc_plane_skin4:MovieAssetMaterial = new MovieAssetMaterial( "pc_plane4",true,true);
pc_plane_skin4.smooth = true;
pc_plane_skin4.doubleSided = true;
var pc_plane4:Plane = new Plane(pc_plane_skin4, 200, 100, 2, 2);
pc_plane4.scale = 1.2;
pc_plane4.x = -20;
pc_plane4.z = 273;
pc_plane4.y = 135;
pc_plane4.rotationY = 90;
pc_case.addChild(pc_plane4);
//-------------------------------------------
// PC Plane ClickHand
//-------------------------------------------
var pc_plane_skin5:MovieAssetMaterial = new MovieAssetMaterial( "clickHand",true,true);
pc_plane_skin5.smooth = true;
pc_plane_skin5.doubleSided = true;
var pc_plane5:Plane = new Plane(pc_plane_skin5, 100, 100, 2, 2);
pc_plane5.scale = 1;
pc_plane5.x = 100;
pc_plane5.z = -127;
pc_plane5.y = 190;
pc_plane5.rotationY = 90;
pc_case.addChild(pc_plane5);
//-------------------------------------------
// PC Folio Plane
//-------------------------------------------
var pc_folio_plane_skin:MovieAssetMaterial = new MovieAssetMaterial( "web_folio_01",true,true);
pc_folio_plane_skin.smooth = true;
pc_folio_plane_skin.doubleSided = true;
var pc_folio_plane:Plane = new Plane(pc_folio_plane_skin, 315, 278, 4, 4);
/*pc_folio_plane.x = -60;
pc_folio_plane.z = 28;
pc_folio_plane.y = 135;
pc_folio_plane.rotationY = 90;*/
pc_folio_plane.scale = .3;
pc_folio_plane.x = 110;
pc_folio_plane.z = 3;
pc_folio_plane.y = 80;
pc_folio_plane.rotationY = 90;
pc_case.addChild(pc_folio_plane);
//-------------------------------------------
// ISLAND
//-------------------------------------------
//-------------------------------------------
// TIPS: в 3D объектаx не нужно включать doubleSided, это портит текстуру. doubleSided - только для 2D!!!
//-------------------------------------------
var movieAssetMat_island:MovieAssetMaterial = new MovieAssetMaterial("platform");
movieAssetMat_island.interactive = true;
var materialsList_island:MaterialsList = new MaterialsList();
materialsList_island.addMaterial( movieAssetMat_island, "cone" );
var island:Collada = new Collada("models/platform.dae", materialsList_island, 2);
island.x = 0;
island.z = 170;
island.y = 0;
island.rotationY = 0;
island.addEventListener(FileLoadEvent.LOAD_COMPLETE, island_LoadComplete);
pc_case.addChild(island);
function island_LoadComplete(e:Event):void {
island.getChildByName("Cone",true).addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, island_Click );
island.getChildByName("Cone",true).addEventListener( InteractiveScene3DEvent.OBJECT_OVER, island_Over );
island.getChildByName("Cone",true).addEventListener( InteractiveScene3DEvent.OBJECT_OUT, island_Out );
}
function island_Click( evt:InteractiveScene3DEvent ):void{
this.buttonMode = false;
/* Tweener.addTween(puppy, { x:-290, z:-275, y:-4145, rotationY:-10, time:1.5, transition:"easeInOutElastic",
onStart:function() { Tweener.addTween(camera, { x:-540, z:-380, y:-4135, rotationY:30, time:1, transition:"lineral"} );
}} ); */
}
function island_Over( evt:InteractiveScene3DEvent ):void{
this.buttonMode = true;
}
function island_Out( evt:InteractiveScene3DEvent ):void{
this.buttonMode = false;
}
// показывает иерархию объектов
//new ec_show_DO3D_list ( container );
//-----------------------------------------------------
// Перемещаем заданный объект с помощью клавиатуры
// 1 = +z; 2 = -z; 3 = +x; 4 = -x; 5 = +y; 6 = -y; 7 = +rY; 8 = -rY;
//-----------------------------------------------------
// какой объект двигаем
// TODO: как двигать клоны?
var test_axis = camera;
trace("CAMERA SELECTED!");
// с какой точностью (px)?
var test_axis_pix:Number = 5;
viewport.stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownEvent_CAM );
function keyDownEvent_CAM( event:KeyboardEvent ) {
switch ( event.charCode ) {
case 47 :
test_axis = camera;
trace("CAMERA SELECTED!");
break;
case 42 :
test_axis = pc_case;
trace("OBJECT1 SELECTED!");
break;
case 45 :
test_axis = island;
trace("OBJECT SELECTED!");
break;
case 49 :
test_axis.z += test_axis_pix;
trace("Obj x: "+test_axis.x+" z: "+test_axis.z+" y: "+test_axis.y+" rY: "+test_axis.rotationY);
break;
case 50 :
test_axis.z -= test_axis_pix;
trace("Obj x: "+test_axis.x+" z: "+test_axis.z+" y: "+test_axis.y+" rY: "+test_axis.rotationY);
break;
case 51 :
test_axis.x += test_axis_pix;
trace("Obj x: "+test_axis.x+" z: "+test_axis.z+" y: "+test_axis.y+" rY: "+test_axis.rotationY);
break;
case 52 :
test_axis.x -= test_axis_pix;
trace("Obj x: "+test_axis.x+" z: "+test_axis.z+" y: "+test_axis.y+" rY: "+test_axis.rotationY);
break;
case 53 :
test_axis.y += test_axis_pix;
trace("Obj x: "+test_axis.x+" z: "+test_axis.z+" y: "+test_axis.y+" rY: "+test_axis.rotationY);
break;
case 54 :
test_axis.y -= test_axis_pix;
trace("Obj x: "+test_axis.x+" z: "+test_axis.z+" y: "+test_axis.y+" rY: "+test_axis.rotationY);
break;
case 55 :
test_axis.rotationY += test_axis_pix;
trace("Obj x: "+test_axis.x+" z: "+test_axis.z+" y: "+test_axis.y+" rY: "+test_axis.rotationY);
break;
case 56 :
test_axis.rotationY -= test_axis_pix;
trace("Obj x: "+test_axis.x+" z: "+test_axis.z+" y: "+test_axis.y+" rY: "+test_axis.rotationY);
break;
}
}
//-------------------------------------------
// Запускаем сцену и всё такое
//-------------------------------------------
addEventListener(Event.ENTER_FRAME, onEnterFrame);
var pan:Number;
function onEnterFrame(e:Event):void {
renderer.renderScene(scene, camera, viewport);
/* pan = camera.rotationY - 100 * this.mouseX/(this.stage.stageWidth/1);
//pan = Math.max( -100, Math.min( pan, 100 ) );
camera.rotationY -= pan / 12;*/
var rotX:Number = -130+(stage.mouseX-(stage.stageWidth / 1))/8;
var rotY:Number = 100+((stage.mouseY-(stage.stageHeight / 1))/10);
//var rotY = 90;
trace("x: "+rotX+"; y: "+rotY);
camera.orbit(rotY, rotX, true, pc);
//trace(rotY);
//camera.pan(rotX);
//camera.x = rotX;
//camera.y = rotY;
//camera.lookAt(pc_case);
}