我最近一直在玩增强现实(并且也有很多乐趣!)我已经能够创建PaperVision原语(立方体,圆柱体,圆锥体等......并与它们配合使用)但是添加了DAE模型被证明是虚幻的!
var cubeMaterialList:MaterialsList = new MaterialsList( { all: new FlatShadeMaterial(light, 0x0099FF, 0x0066AA) } );
var cube:Cube = new Cube(cubeMaterialList,
30,
30,
30);
cube.z += 15;
mainContainer.addChild(cube);
一切正常!
我用它来导入/尝试导入dae!
private var mCollada:Collada;
private var universe:DisplayObject3D;
mCollada = new Collada("sample.dae");
universe = new DisplayObject3D();
universe.addChild(mCollada);
mainContainer.addChild(universe);
我已经使用这种将DAE导入非增强现实PaperVision项目的方法,这是一种享受!所以只是想知道是否有人有幸用AR导入DAE!
答案 0 :(得分:3)
Click here to view a video of the necessary imports and working demo on my site.
我注意到你使用的是Collada Class,而不是DAE,类,它们的行为有点不同,如视频abobe中所示。
同样重要的是要注意,您可能正确地执行此操作,并且模型或甚至纹理可能存在问题。如果没有加载纹理,您应该立即从控制台知道。尝试创建ColorMaterial并创建一个MaterialsList对象,将“all”属性设置为您创建的ColorMaterial。最后通过实例化或加载方法将列表传递给Collada或DAE Classes的实例化。还要确保相机未放大以关闭,可能会将3D物体留在其后面。最后使用比例尺,并非所有模型都以相同的比例进入,而使用Collada类而不是DAE,似乎可以大大提升模型,如上面的视频链接所示。
我最近在筹备Tony Hawk XI网站时,有很多时间玩FlarToolkit / Papervision3D / Collada合作伙伴。
package
{
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Camera;
import flash.media.Video;
import flash.utils.ByteArray;
import org.libspark.flartoolkit.core.FLARCode;
import org.libspark.flartoolkit.core.param.FLARParam;
import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
import org.libspark.flartoolkit.core.transmat.FLARTransMat;
import org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
import org.libspark.flartoolkit.pv3d.FLARBaseNode;
import org.libspark.flartoolkit.pv3d.FLARCamera3D;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.render.LazyRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.objects.parsers.Collada;
import org.papervision3d.objects.parsers.DAE;
/**
* ...
* @author Brian Hodge
*/
public class Main extends Sprite
{
[Embed(source="../lib/camera_para.dat", mimeType="application/octet-stream")]
private var CameraParameters:Class;
[Embed(source="../lib/collada.pat", mimeType="application/octet-stream")]
private var MarkerPattern:Class;
private var cameraParameters:FLARParam;
private var markerPattern:FLARCode;
private var raster:FLARRgbRaster_BitmapData;
private var detector:FLARSingleMarkerDetector;
private var cam:Camera;
private var vid:Video;
private var capture:BitmapData;
private var cam3D:FLARCamera3D;
private var scene3D:Scene3D;
private var viewPort:Viewport3D;
private var mainContainer:FLARBaseNode;
private var renderer:LazyRenderEngine;
private var trans:FLARTransMatResult;
private var prevSet:Boolean = false;
private var prevZ:Number = 0;
private var _collada:Collada;
private var _dae:DAE;
public function Main():void
{
cameraParameters = new FLARParam();
cameraParameters.loadARParam(new CameraParameters() as ByteArray);
markerPattern = new FLARCode(16, 16);
markerPattern.loadARPatt(new MarkerPattern());
cam = Camera.getCamera();
cam.setMode(640, 480, 30);
vid = new Video();
vid.width = 640;
vid.height = 480;
vid.attachCamera(cam);
addChild(vid);
capture = new BitmapData(vid.width, vid.height, false, 0x0);
capture.draw(vid);
raster = new FLARRgbRaster_BitmapData(capture);
detector = new FLARSingleMarkerDetector(cameraParameters, markerPattern, 80);
cam3D = new FLARCamera3D(cameraParameters);
scene3D = new Scene3D();
mainContainer = new FLARBaseNode();
scene3D.addChild(mainContainer);
viewPort = new Viewport3D(vid.width, vid.height);
viewPort.scaleX = viewPort.scaleY = 2;
addChild(viewPort);
renderer = new LazyRenderEngine(scene3D, cam3D, viewPort);
_dae = new DAE();
_dae.load("assets/dae/apc.dae");
_dae.rotationZ -= 90;
mainContainer.addChild(_dae);
/*
_collada = new Collada("assets/dae/apc.dae");
_collada.scale = 0.05;
_collada.rotationZ -= 90;
mainContainer.addChild(_collada);
*/
trans = new FLARTransMatResult();
this.addEventListener(Event.ENTER_FRAME, mainEnter);
}
private function mainEnter(e:Event):void
{
capture.draw(vid);
if (detector.detectMarkerLite(raster, 80) && detector.getConfidence() > 0.5)
{
detector.getTransformMatrix(trans);
mainContainer.setTransformMatrix(trans);
mainContainer.visible = true;
renderer.render();
}
else
{
mainContainer.visible = false;
renderer.render();
}
}
}
}
希望这一切对您有所帮助,我建议您继续玩它并继续熟悉它。
答案 1 :(得分:0)
@Brady,
嘿,我认为这可能是错误:
[Embed(source =“pat1.pat”,mimeType =“application / octet-stream”)] private var CameraParameters:Class;
[Embed(source =“pat1.pat”,mimeType =“application / octet-stream”)] private var MarkerPattern:Class;
在“CameraParameters”中你应该嵌入“camera_para.dat”而不是 - pat1.pat 。试试这个。
答案 2 :(得分:0)
我在this site实际上找到了一些很好的信息。我用那里的代码将模型导入到我的AR中。它概述了一种导入collada模型的非常简单的方法。我刚刚采用了示例FlarToolkit示例(simpleCube示例)并在该文章中添加了代码,这足以让我前进。
以下是代码:
package {
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.objects.primitives.Cylinder;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.Collada;
import flash.events.*;
public class SimpleCube extends PV3DARApp {
public var FAlogo:DisplayObject3D;
public var light :PointLight3D;
public function SimpleCube() {
this.init('Data/camera_para.dat', 'Data/flarlogo.pat');
}
protected override function onInit():void {
super.onInit();
this.addEventListener( Event.ENTER_FRAME, EROnEnterFrame );
// let there be light
this.light = new PointLight3D;
this.light.x = 0;
this.light.y = 1000;
this.light.z = -1000;
// cow model
FAlogo = new Collada("http://papervision2.com/wp-content/downloads/dae/cow.dae");
FAlogo.rotationZ = -90;
FAlogo.rotationY = -90;
FAlogo.x = -100;
FAlogo.z = 100;
FAlogo.scale = 0.1;
// re-orient the logo model before adding it to the scene
this._baseNode.addChild(this.FAlogo);
}
private function EROnEnterFrame( event :Event ):void
{
// spins the cow yay!
FAlogo.yaw(3);
}
}
}