AS3 DAE 增强现实 PaperVision 3D

发布于 2024-07-15 09:56:35 字数 869 浏览 8 评论 0原文

我最近一直在玩增强现实(并且也从中获得了很多乐趣!)我已经能够创建 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!

I have been playing with Augmented Reality recently (and having lots of fun with it too!!) I have been able to create PaperVision primitives (cube, cylinder, cone, etc.. and work with them) But adding a DAE model is proving to be illusive!

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);

This all works fine!

I am using this to import/attempt to import a dae!

private var mCollada:Collada;
private var universe:DisplayObject3D;
mCollada = new Collada("sample.dae");
universe = new DisplayObject3D();
universe.addChild(mCollada);
        mainContainer.addChild(universe);

I have used this method of importing DAEs into a non-Augmented Reality PaperVision projects and it works a treat! So just wondering if anyone had any luck at importing DAEs with AR!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

橘味果▽酱 2024-07-22 09:56:35

单击此处在我的网站上观看必要导入和工作演示的视频。

我注意到您使用的是 Collada 类,而不是 DAE 类,两者的行为与视频 abobe 中显示的有所不同。

同样重要的是要注意,您很可能做得正确,并且模型甚至纹理可能存在问题。 如果纹理未加载,您应该立即从控制台知道。 尝试创建一个 ColorMaterial 并创建一个 MaterialsList 对象,将“all”属性设置为您创建的 ColorMaterial。 最后通过实例化或load方法将列表传递给Collada或DAE类的实例化。 还要确保相机没有放大到关闭状态,否则可能会将 3D 对象留在后面。 最后玩一下比例,并非所有模型都以相同的比例出现,并且使用 Collada 类(而不是 DAE)似乎会使模型变得相当大,如上面的视频链接所示。

最近,我花了很多时间与 FlarToolkit / Papervision3D / Collada 合作伙伴合作,准备 Tony Hawk XI 网站。

-您需要什么

  • IDE,我使用 FlashDevelop3 RC2,但 Flex Builder 或您选择的 IDE 也可以。
  • Papervision3D 2.0 Whiteshark、(最新版本)
  • Flex 3.3 SDK
  • Patience

- 查找并准备模型

  • 使用 Google 3D Warehouse 我的 Collada 文件。
  • 接下来将“.skp”sketchup 文件导入 Google Sketchup。
  • 确保 Sketchup 窗口具有焦点并同时按下 CTRL 和 A。 (全选)
  • 向上进行编辑,然后转到下拉列表的底部,通常会显示您选择了多少个组。
  • 选择爆炸。
  • 重复直到不再爆炸。 (如果您像预期那样使用低多边形模型,这不会花费很长时间。)
  • CTRL + A 再次选择全部。
  • 转到文件> 出口> 3D 模型并选择“.dae” //如果您没有 Sketchup,则 .dae 扩展名不可用,请查找解决方法:)(本质上 .dae 包含在“.skp”中,
  • 您现在将拥有一个 .dae文件,以及一个具有相同名称的文件夹,其中包含与其中的模型相关的纹理

- 导入/解析模型并显示它

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();
        }
    }
}

}

希望这一切对您有所帮助,我建议您继续使用它并不断熟悉它。它。

Click here to view a video of the necessary imports and working demo on my site.

I notice that you are using the Collada Class, as opposed to the DAE, class, which both act a bit differently as is displayed in the video abobe.

It is also important to note that you may very well be doing this correctly and that there is a problem with the model or possibly even the texture. If the texture isn't loading you should know immediately from the console. Try creating a ColorMaterial and create a MaterialsList object setting the "all" property to the ColorMaterial you created. Finally pass the list to the instantiation of Collada or DAE Classes through the instantiation or load method. Also make sure that the camera isn't zoomed in to close, possibly leaving the 3D Object behind it. Finally play with the scale, not all models come in at the same scale, and using Collada class, as opposed to DAE, seems to blow the model up considerable as shown in the video link above.

I have had a lot of time to play with the FlarToolkit / Papervision3D / Collada partnership lately in preparations for the Tony Hawk XI website.

-What you need

  • An IDE, I use FlashDevelop3 RC2, but Flex Builder or your IDE of choice will work.
  • Papervision3D 2.0 Whiteshark, (latest build)
  • Flex 3.3 SDK
  • Patience

-Finding and prepping the model

  • Use Google 3D Warehouse for my Collada files.
  • Next take the ".skp" sketchup file into Google Sketchup.
  • Make sure the sketchup window has focus and hit CTRL and A at the same time. (Select all)
  • Head up to edit, and go down to the bottom of the drop-down list where it will typically say how many groups you have selected.
  • Choose explode.
  • Repeat until you cannot explode any more. (If you are using low-poly models like you are supposed to, this shouldn't take long.)
  • CTRL + A to select all again.
  • Goto File > Export > 3D Model and choose ".dae" //If you do not own Sketchup the .dae extension is not available, lookup the work around :) (Essentially the .dae is wrapped in the ".skp"
  • You will now have a .dae file, and a folder with the same EXACT name, with textures pertaining to the model inside of it.

- Importing / parsing the model and displaying it

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();
        }
    }
}

}

Hopefully all this helps you, I suggest you just keep playing with it and keep familiarizing yourself with it.

So要识趣 2024-07-22 09:56:35

@Brady,

嘿,我认为这可能是错误:

[Embed(source="pat1.pat", mimeType="application/octet-stream")]
私有 var CameraParameters:类;

[嵌入(源=“pat1.pat”,mimeType=“应用程序/八位字节流”)]
私有 var MarkerPattern:类;

在“CameraParameters”处,您应该嵌入“camera_para.dat”而不是 - pat1.pat
。 尝试一下这个。

@Brady,

Hey I think this could be the error:

[Embed(source="pat1.pat", mimeType="application/octet-stream")]
private var CameraParameters:Class;

[Embed(source="pat1.pat", mimeType="application/octet-stream")]
private var MarkerPattern:Class;

Here at the "CameraParameters" you should embed "camera_para.dat" rather than - pat1.pat
. try with this one.

标点 2024-07-22 09:56:35

我实际上在这个网站找到了一些很好的信息。 我使用那里的代码将模型导入到我的 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);
        }
    }
}

I found some good information actually at this site. I used the code there to import models into my AR stuff. It outlines a very simple method for importing collada models. I just took the sample FlarToolkit example (the simpleCube example) and added the code in that article and that was enough to get me going.

Here's the code:

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);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文