Тема: [Away3D] Away3d chrome material
Показать сообщение отдельно
Старый 26.02.2013, 20:52
bav вне форума Посмотреть профиль Отправить личное сообщение для bav Найти все сообщения от bav
  № 9  
Ответить с цитированием
bav
 
Аватар для bav

Регистрация: Oct 2010
Сообщений: 1,049
Отправить сообщение для bav с помощью ICQ
Цитата:
3,4,5- отвечает за тень, то есть как ее визуализировать и ее интенсивность, в Вашем случии наверно очень важные.
Это несомненно :-)
Выложу-ка я код и полные исходники, чтобы было понятно, что и как я делаю, может это поможет найти проблему.
Вот главный класс:
Код AS3:
package
{
	import away3d.containers.*;
	import away3d.core.base.*;
	import away3d.entities.*;
	import away3d.lights.*;
	import away3d.materials.*;
	import away3d.materials.methods.*;
	import away3d.primitives.*;
	import away3d.textures.*;
	import away3d.utils.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.ui.*;
 
	[SWF(backgroundColor="#000000", frameRate="30", quality="LOW")]
 
	public class Main extends Base
	{
		// Текстуры
		[Embed(source = "../lib/images/allum.png")]
		public static var Allum:Class;
		[Embed(source = "../lib/images/green_metal.png")]
		public static var GMetal:Class;
		[Embed(source = "../lib/images/trinket_diffuse.jpg")]
		public static var TrinketDiffuse:Class;
		[Embed(source = "../lib/images/radial_gray_2.jpg")]
		public static var RadialBlue:Class;
		[Embed(source = "../lib/images/st.jpg")]
		public static var Photo:Class;
 
		private var reflectionTexture:CubeReflectionTexture;
		private var reflectiveMaterial : ColorMaterial;
		private var cylinderSegments:int = 16;
		private var cylinderRadius:int = 8;
 
		private var texs:Array;
 
		//setup the cube texture
		private var cubeTexture:BitmapCubeTexture;
		private var skyBox:SkyBox;
 
		private var b:Boolean = false;
		private var texture:BitmapTexture;
		private var material:TextureMaterial;
 
		private var atexture:BitmapTexture;
		private var amaterial:TextureMaterial;
 
		// Свет
		private var light:PointLight;
		private var light_2:PointLight;
 
		// Контейнеры
		private var _topSquare:ObjectContainer3D;
		private var _bottomCircle:ObjectContainer3D;
		private var _legCylinder:ObjectContainer3D;
		// Меши
		private var _topSquareMesh:Mesh;
		private var _legCylinderMesh:Mesh;
		private var _bottomCircleMesh:Mesh;
 
		private var _legMeshes:Vector.<Mesh> = new Vector.<Mesh>();
		private var _currLegTexture:int = 0;
 
		public function Main() {
			super();
		}
 
		override protected function onSetup():void {
			// Создаем освещение
			createSun();
			// Создаем объекты
			createObjects();
			// Включаем переключение текстур по пробелу
			stage.addEventListener(KeyboardEvent.KEY_DOWN, clickHand);
			// Массив переключаемых текстур.
			texs = [GMetal, TrinketDiffuse, Allum, Photo];
		}
 
		/**
		 * В этой функции переключаются текстуры.
		 */
		private function clickHand(e:KeyboardEvent):void 
		{
			if (e.keyCode == Keyboard.SPACE)
			{
				++_currLegTexture;
				if (_currLegTexture == texs.length)
					_currLegTexture = 0;
				amaterial.texture = Cast.bitmapTexture( texs[_currLegTexture] );
			}
		}
 
		/**
		 * Здесь создаются объекты и настраиваются текстуры.
		 */
		private function createObjects():void
		{
			// Текстура для SkyBox'а.
			cubeTexture = new BitmapCubeTexture(Cast.bitmapData(RadialBlue), Cast.bitmapData(RadialBlue), Cast.bitmapData(RadialBlue), Cast.bitmapData(RadialBlue), Cast.bitmapData(RadialBlue), Cast.bitmapData(RadialBlue));
 
			//==========================================================================================
			// REFLECTION TEXTURE
			// create reflection texture with a dimension of 512x512x512
			reflectionTexture = new CubeReflectionTexture(512);
			reflectionTexture.farPlaneDistance = 3000;
			reflectionTexture.nearPlaneDistance = 1;
 
			// center the reflection at (0, 0, 0) where our reflective object will be
			reflectionTexture.position = new Vector3D(0, 0, 0);
 
			// setup fresnel method using our reflective texture in the place of a static environment map
			var fresnelMethod : FresnelEnvMapMethod = new FresnelEnvMapMethod(reflectionTexture);
			fresnelMethod.normalReflectance = .6;
			fresnelMethod.fresnelPower = 2;
 
			var refractionMethod : RefractionEnvMapMethod = new RefractionEnvMapMethod( cubeTexture );
 
			//setup the reflective material
			reflectiveMaterial = new ColorMaterial(0x000000);
			reflectiveMaterial.addMethod(fresnelMethod);
 
			// Следующая строка включает refractionMethod.
			//reflectiveMaterial.addMethod(refractionMethod);
 
			// Создание текстур ==========================================================================
			// Текстура для столешницы
			material = new TextureMaterial( Cast.bitmapTexture( TrinketDiffuse ) );
			material.lightPicker = _lightPicker;
 
			// Начальная текстура для нижнего подстолья
			atexture = Cast.bitmapTexture( Photo );
			amaterial = new TextureMaterial( atexture );
			amaterial.lightPicker = _lightPicker;
 
			// SkyBox
			skyBox = new SkyBox(cubeTexture);
			_view.scene.addChild(skyBox);
 
			// Создание квадратного стола =================================================================
			var topSquareSurfaceGeometry:CubeGeometry = new CubeGeometry( 100, 2, 100, 1, 1, 1, false );
			_topSquareMesh = new Mesh( topSquareSurfaceGeometry, material );
			_topSquare = new ObjectContainer3D();
			_view.scene.addChild( _topSquare );
			_topSquareMesh.y = 75;
			_topSquare.addChild( _topSquareMesh );
 
			// Создание цилиндрической ноги =================================================================
			// (массив _legMeshes сохранился с прошлых версий)
			_legMeshes.push(new Mesh( new CylinderGeometry( cylinderRadius, cylinderRadius, 150, cylinderSegments, cylinderSegments ), reflectiveMaterial ));
 
			_legCylinder = new ObjectContainer3D();
			_view.scene.addChild( _legCylinder );
			_legCylinder.addChild( _legMeshes[_currLegTexture] );
 
 
			// Колдунство
			twist(_legCylinder, 1.5);
 
 
			// Создание круглого подстолья ================================================================
			var bottomCircleSurfaceGeometry:CylinderGeometry = new CylinderGeometry( 50, 50, 3, 64 );
			_bottomCircleMesh = new Mesh( bottomCircleSurfaceGeometry, amaterial );
			_bottomCircle = new ObjectContainer3D();
			_view.scene.addChild( _bottomCircle );
			_bottomCircleMesh.y = -75;
			_bottomCircle.addChild( _bottomCircleMesh );
 
		}
 
		/**
		 * Твиситит все мешы по обьекту
		 * @param	content3D
		 * @param	twistX
		 * @param	twistY
		 * @param	twistZ
		 * @param	startBool в первый раз создают клон геометриии
		 */
		private function twist(content3D:ObjectContainer3D, twistX:Number, zX:Number=0, zZ:Number=0):void{
 
			var subGeom:CompactSubGeometry;
			var sah:Number = 0;
			var point0:Point=new Point(zX, zZ);
			var point1:Point=new Point();
 
			var ang:Number = 0;
			var dist:Number = 0;
			var maxY:Number = content3D.maxY;
			var mmY:Number = content3D.maxY - content3D.minY;
			var pros:Number = 0;
 
			var vTest:Vector.<Number>; //вершины субмеша			
			var iSub:int = 0;	//счетчик субмешей
			var lSub:uint = 0; //количество субмешей
			var i:int
			var j:int
 
			for (i = 0; i < content3D.numChildren; i++)
			{
				if (content3D.getChildAt(i) is Mesh)
				{
					var mesh:Mesh = content3D.getChildAt(i) as Mesh;
					lSub = mesh.subMeshes.length; //количество субмешей
 
					if (!mesh.extra)
					{
						mesh.extra = { };
					}
					if (mesh.extra.arrSM == undefined || mesh.extra.arrSM == null)
					{
						mesh.extra.arrSM = [];
					}
					for (iSub = 0; iSub < lSub; iSub++)
					{
						if (mesh.extra.arrSM[iSub] == undefined)
						{
							mesh.extra.arrSM[iSub] = new Vector.<Number>;
							for (j = 0; j < mesh.subMeshes[iSub].vertexData.length; j++)
							{
								mesh.extra.arrSM[iSub].push(mesh.subMeshes[iSub].vertexData[j]);
							}
						}
						vTest = new Vector.<Number>;
						for (j = 0; j < mesh.subMeshes[iSub].vertexData.length; j++)
						{
							vTest.push(mesh.extra.arrSM[iSub][j]);
						}
 
						for (j = 0; j < mesh.extra.arrSM[iSub].length; j += 13)
						{
							// Вот здесь все изменения ============================================
							if ((j / 13) >= cylinderSegments * 15 - 2)
							{
								vTest[j + 1] -= (75 + vTest[j + 1]) / 1.3;
								vTest[j + 4] = -0.3;
							}
							// ====================================================================
						}
						subGeom = mesh.subMeshes[iSub].subGeometry as CompactSubGeometry;
						subGeom.updateData(vTest);
					}
				}			
			}		
		}
 
		private function createSun():void
		{
			// Light objects.
			light = new PointLight();
			light.ambient = 0.3;
			light.diffuse = 2;
			light.specular = 0.75;
			light.x = 500;
			light.z = 300;
			light.y = 200;
 
			light_2 = new PointLight();
			light_2.ambient = 0.3;
			light_2.diffuse = 2;
			light_2.specular = 0.75;
			light_2.x = -500;
			light_2.z = 300;
			light_2.y = 200;
 
			_lightPicker.lights = [ light, light_2 ];
		}
 
		override protected function onUpdate():void
		{
			reflectionTexture.render(_view);
			super.onUpdate();
		}
 
	}
}
А вот чего хочется:
Нажмите на изображение для увеличения
Название: wish.jpg
Просмотров: 412
Размер:	14.9 Кб
ID:	29192
Кстати попытка применить reflectiveMaterial к нижнему плоскому подстолью не приносит желаемого результата – в нем не отражается вертикальная цилиндрическая нога.
Вложения
Тип файла: zip table.zip (533.7 Кб, 179 просмотров)
Тип файла: swf table_4.swf (722.9 Кб, 173 просмотров)