Показать сообщение отдельно
Старый 06.05.2013, 19:34
olexandr вне форума Посмотреть профиль Отправить личное сообщение для olexandr Посетить домашнюю страницу olexandr Найти все сообщения от olexandr
  № 3  
Ответить с цитированием
olexandr
 
Аватар для olexandr

Регистрация: Aug 2007
Адрес: Ukraine, Kyiv
Сообщений: 643
Отправить сообщение для olexandr с помощью ICQ Отправить сообщение для olexandr с помощью MSN Отправить сообщение для olexandr с помощью Skype™
рейкастинг помог, но не совсем.
координаты uv для текстуры мне нужно получать не из видимого 3d-пространства, а из развертки текстуры - насколько я понял, там можно обойтись обычными процентами.
вот, на тестовом примере вроде как получилось все реализовать для примитива plane, а для sphere пока никак

Код AS3:
package {
	import alternativa.engine3d.core.Camera3D;
	import alternativa.engine3d.core.Object3DContainer;
	import alternativa.engine3d.core.RayIntersectionData;
	import alternativa.engine3d.core.View;
	import alternativa.engine3d.materials.TextureMaterial;
	import alternativa.engine3d.primitives.Plane;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Vector3D;
	import ua.olexandr.utils.GeomUtils;
 
	public class Main extends Sprite {
 
		public static const TEST_POINT:Point = new Point(663, 410);
 
		private var _holder:Object3DContainer;
		private var _camera:Camera3D;
		private var _texture:BitmapData;
		private var _plane:Plane;
//private var _sphere:Sphere;
		private var _shape:Shape;
 
		[Embed(source="texture.jpg")]
		private var _Texture:Class;
 
		public function Main():void {
			if (stage)
				init();
			else
				addEventListener(Event.ADDED_TO_STAGE, init);
		}
 
		private function init(e:Event = null):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
 
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
 
			_holder = new Object3DContainer();
 
			_camera = new Camera3D();
			_camera.view = new View(640, 480);
			_camera.view.hideLogo();
			_camera.view.contextMenu = null;
			_camera.fov = GeomUtils.degreesToRadians(120);
			_holder.addChild(_camera);
 
			_texture = Bitmap(new _Texture()).bitmapData;
 
			_plane = new Plane(100, 100, 100, 1, true);
			_plane.setMaterialToAllFaces(new TextureMaterial(_texture));
			_holder.addChild(_plane);
 
			_camera.z = -80;
			_camera.rotationX = GeomUtils.degreesToRadians(0);
			_camera.rotationY = GeomUtils.degreesToRadians(-30);
			_camera.rotationZ = GeomUtils.degreesToRadians(180);
 
			_camera.view.x = stage.stageWidth - _camera.view.width >> 1;
			_camera.view.y = stage.stageHeight - _camera.view.height >> 1;
			addChild(_camera.view);
 
			_shape = new Shape();
			_shape.x = _camera.view.x;
			_shape.y = _camera.view.y;
			addChild(_shape);
 
			addEventListener(Event.ENTER_FRAME, efHandler);
		}
 
		private function efHandler(e:Event):void {
			var _degreesZ:Number = GeomUtils.radiansToDegrees(_camera.rotationZ) + 1;
			_camera.rotationZ = GeomUtils.degreesToRadians(_degreesZ);
 
			var _u:Number = (_texture.width - TEST_POINT.x) / _texture.width - .5;
			var _v:Number = (_texture.height - TEST_POINT.y) / _texture.height - .5;
 
			var _origin:Vector3D = new Vector3D(_camera.x, _camera.y, _camera.z);
			var _direction:Vector3D = new Vector3D(_u, _v, 1);
			var _data:RayIntersectionData = _holder.intersectRay(_origin, _direction);
 
			if (_data) {
				var _vec:Vector3D = _camera.projectGlobal(_data.point);
 
				_shape.graphics.clear();
				_shape.graphics.beginFill(0xFF0000, .5);
				_shape.graphics.drawRect(_vec.x - 5, _vec.y - 5, 10, 10);
			}
 
			_camera.render();
		}
 
	}
 
}
__________________
сайт, vk