1: package
2: {
3: import away3d.cameras.Camera3D;
4: import away3d.containers.Scene3D;
5: import away3d.containers.View3D;
6:
7: import away3d.materials.BitmapMaterial;
8: import away3d.materials.PhongBitmapMaterial;
9: import away3d.materials.TransformBitmapMaterial;
10:
11: import away3d.primitives.Cube;
12: import away3d.primitives.Cylinder;
13: import away3d.primitives.Sphere;
14: import away3d.primitives.Torus;
15: import away3d.containers.ObjectContainer3D;
16: import away3d.lights.DirectionalLight3D;
17:
18: import away3d.core.math.Number3D;
19: import away3d.core.utils.Cast;
20:
21: import flash.display.Sprite;
22: import flash.events.Event;
23:
24: [SWF(width="700",height="600",backgroundColor="#000000")]
25: public class textmapping extends Sprite
26: {
27: //声明变量
28: private var view:View3D;
29: private var cam:Camera3D;
30: private var sce:Scene3D;
31:
32: private var group:ObjectContainer3D;
33: private var sphere:Sphere;
34: private var cube:Cube;
35: private var centerCube:Cube;
36: private var torus:Torus;
37: private var cylinder:Cylinder;
38: private var light:DirectionalLight3D;
39:
40: private var earthMaterial:BitmapMaterial;
41: private var checkerMaterial:BitmapMaterial;
42: private var away3dMaterial:PhongBitmapMaterial;
43: private var tiledAway3dMaterial:TransformBitmapMaterial;
44: private var woodMaterial:BitmapMaterial;
45:
46: private static const ORBITAL_RADIUS:Number = 150;
47: //插入图片资源用于贴图(分类flex里用Embed标签、Cast.bitmap嵌入、使用图片资源,flash cs3如何嵌入看附录1)
48: [Embed(source="resources/earth.jpg")] private var earthImage:Class;
49: [Embed(source="resources/away3D.png")] private var away3dImage:Class;
50: [Embed(source="resources/checker.jpg")] private var checkerImage:Class;
51: [Embed(source="resources/wood.jpg")] private var woodImage:Class;
52: public function textmapping():void
53: {
54: //3D初始化
55: init3D();
56: //创建场景
57: createScene();
58: //添加侦听器-逐帧执行onEF(渲染并产生运动)
59: this.addEventListener(Event.ENTER_FRAME,onEF);
60: }
61:
62: private function init3D():void
63: {
64: //初始化摄像机
65: cam=new Camera3D({zoom:25, focus:30, x:-200, y:400, z:-400});
66: cam.lookAt(new Number3D(0, 0, 0));
67: //初始化场景
68: sce=new Scene3D();
69: //初始化视口
70: view=new View3D({camera:cam,scene:sce,x:350,y:300});
71: addChild(view);
72: };
73: private function createScene():void
74: {
75: //生成位图材质(78行定义的away3dMaterial是phongBitmapMaterial类型,该类型需要光源)
76: earthMaterial=new BitmapMaterial(Cast.bitmap(new earthImage()));
77: checkerMaterial=new BitmapMaterial(Cast.bitmap(new checkerImage()));
78: away3dMaterial=new PhongBitmapMaterial(Cast.bitmap(new away3dImage()),{smooth:true, precision:2});
79: tiledAway3dMaterial=new TransformBitmapMaterial(Cast.bitmap(new away3dImage()),{repeat:true, scaleX:.5, scaleY:.5});
80: woodMaterial=new BitmapMaterial(Cast.bitmap(new woodImage()));
81:
82: //添加光源(有了光源phongBitmapMaterial才能有光影效果,有光影效果会在下节讲到)
83: light=new DirectionalLight3D();
84: light.position=new Number3D(100,100,-200);
85: sce.addChild(light);
86: //新建容器并显示
87: group=new ObjectContainer3D();
88: sce.addChild(group);
89: //新建3D元素,并使用material属性为3D元素添加贴图材质
90: //新建3D元素-centerCube
91: centerCube=new Cube({material:away3dMaterial,width:75,height:75,depth:75});
92: group.addChild(centerCube);
93: //新建3d 元素 - sphere
94: sphere=new Sphere({radius:50,segmentsW:10,segmentsH:10,material:earthMaterial});
95: group.addChild(sphere);
96: sphere.x=ORBITAL_RADIUS;
97: //新建3d 元素 - totrus
98: torus=new Torus({radius:50,tube:20,segmentsT:8,segmentsR:16,material:checkerMaterial});
99: group.addChild(torus);
100: torus.x=-ORBITAL_RADIUS;
101: //新建3d 元素 - cylinder
102: cylinder=new Cylinder({radius:25,height:100,segmentsW:16,material:woodMaterial});
103: group.addChild(cylinder);
104: cylinder.z=ORBITAL_RADIUS;
105: //新建3d 元素 - totrus
106: cube=new Cube({width:75,height:75,depth:75,material:tiledAway3dMaterial});
107: group.addChild(cube);
108: cube.z=-ORBITAL_RADIUS;
109: };
110: private function onEF(e:Event):void
111: {
112: // 旋转3D物体
113: group.yaw(1);
114:
115: sphere.yaw(-4);
116: cube.yaw(-4);
117: cylinder.yaw(-4);
118: torus.yaw(-4);
119: //一定要渲染哟
120: view.render();
121: };
122:
123: }
124: }
这些平面图片是如何贴到3D模型上的呢,看下图就明白了:
更详细内容看:http://blog.tartiflop.com/2008/11/first-steps-in-away3d-part-3-texture-mapping/
相关推荐
Away3D中文学习资料集锦...实例教程 - 贴图(texture mapping) 学习笔记 - away3d类库下载 学习笔记1 - 戏说Flash 三维引擎 学习笔记2-三维世界的四个基本构件 学习笔记3--3D世界的坐标系 学习笔记4-View3D(视口)
Seamless Image-Based Texture Atlases using Multi-band Blending
LCPrinter - Simple Texture Printer Unity调用打印机服务,Asset Store插件
投影矩阵的教程 Introduction Projective texture mapping is a method of texture mapping described by Segal [3] that allows the texture image to be projected onto the scene as if by a slide projector. ...
一个原创的sphere texture mapping实例(附sphere mapping详解pdf) 一个原创的 OpenGL 键盘控制模型 rotation实例 键盘操作: 按空格键可切换兔子模型的自转轴:x-》y,y-》x (source包含loadpng.c(贴图loading)...
OpenGLES 入门编程代码的第12课中讲解材质贴图的代码
Texture Mapping
All of these objects are texture-mapped (mipmapping). 3. There is a point light and a single directional light in the scene. 4. There is one rotating triangle floating in the air, casting a shadow on...
Texture mapping Texture mapping Texture mapping
graphics 中texture 是其中很重要的一块,这篇专利里面的方法可以借鉴一下
Real-Time Texture Synthesis by Patch-Based Sampling基于样图的纹理合成 论文
三维图像重构,三维图像重构,三维图像重构
该文章是一种适应多几何面投影的校正算法,通过阅读能够给同仁提供参考和帮助
By encoding such surface patterns in texture maps, texture-based bump mapping simulates a surface’s irregular lighting appearance without modeling the patterns as true geometric perturbations to the...
三维重建纹理贴图,已知ply网格模型、摄像机拍摄的图片以及对应的内外参数,可生成obj带mtl纹理的模型文件。基于pcl或者openmvs。
Advanced Topics in Computer Graphics Texture Mapping by Steve Olivieri
C++ code for globe-style texture mapping
Abstract We present a simple image-based method of generating novel visual appearance in which a new image is synthesized by ...Keywords: Texture Synthesis, Texture Mapping, Image-based Rendering