`
hereson
  • 浏览: 1454311 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

PV3D2 .0 的经典 包含各种渲染和触发

    博客分类:
  • Pv3d
阅读更多
最近发现的宝贝,分享下!!值得收藏!!

/*
        Papervision 2.0a Example
        Lee Felarca
        12/12/2007, plus
       
        Examine the source for examples of ...
       
                - Setting up and rendering a simple 3d scene
               
                - Utilizing new materials found in the org.papervision3d.materials.shadematerials package (GouraudMaterial, PhongMaterial, CellMaterial, FlatShadeMaterial, EnvMapMaterial). Plus, CompositeMaterial.
               
                - Utilizing Shaders (viz., EnvMapShader)
               
                - Utilizing a second viewport (used here to create the 'reflection' on the floor)

                - Handling simple user interaction with the 3d scene with InteractiveSceneManager
*/

package
{
        import caurina.transitions.*;
       
        import flash.display.BitmapData;
        import flash.display.Sprite;
        import flash.display.StageScaleMode;
        import flash.events.Event;
        import flash.filters.BlurFilter;
        import flash.geom.Matrix;
       
        import org.papervision3d.cameras.Camera3D;
        import org.papervision3d.cameras.FreeCamera3D;
        import org.papervision3d.core.math.Number3D;
        import org.papervision3d.core.proto.MaterialObject3D;
        import org.papervision3d.core.utils.InteractiveSceneManager;
        import org.papervision3d.core.utils.Mouse3D;
        import org.papervision3d.events.InteractiveScene3DEvent;
        import org.papervision3d.lights.PointLight3D;
        import org.papervision3d.materials.BitmapMaterial;
        import org.papervision3d.materials.ColorMaterial;
        import org.papervision3d.materials.WireframeMaterial;
        import org.papervision3d.materials.shadematerials.CellMaterial;
        import org.papervision3d.materials.shadematerials.EnvMapMaterial;
        import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
        import org.papervision3d.materials.shadematerials.GouraudMaterial;
        import org.papervision3d.materials.shadematerials.PhongMaterial;
        import org.papervision3d.materials.shaders.EnvMapShader;
        import org.papervision3d.materials.shaders.ShadedMaterial;
        import org.papervision3d.materials.special.CompositeMaterial;
        import org.papervision3d.objects.DisplayObject3D;
        import org.papervision3d.objects.primitives.Plane;
        import org.papervision3d.objects.primitives.Sphere;
        import org.papervision3d.render.BasicRenderEngine;
        import org.papervision3d.scenes.Scene3D;
        import org.papervision3d.view.Viewport3D;
       

        [SWF(width="950", height="500", frameRate="45", backgroundColor="#444444", pageTitle="PV2 Sandbox")]

        public class Pv2Example extends Sprite
        {
                private static const DEGREE:Number = Math.PI/180;
                private const NUMSPHERES:int = 7;

                private const FLOORBMP_SIDE:Number = 500;
                private const ENVSPHEREBMP_WIDTH:Number = stage.stageWidth/2;
                private const ENVSPHEREBMP_HEIGHT:Number = stage.stageHeight/2;

                private var sprScene:Sprite;

                // 3d-related variables
                private var scene:Scene3D;
                private var ism:InteractiveSceneManager;
                private var renderer:BasicRenderEngine;
                private var viewportMain:Viewport3D;
                private var viewportFloor:Viewport3D;
                private var cameraMain:Camera3D;
                private var cameraFloor:FreeCamera3D;
                private var light:PointLight3D;
                private var lightSphereEnv:PointLight3D;
                private var floor:Plane;
                private var matSphereEnv:EnvMapMaterial;
                private var matSphereComposite:CompositeMaterial;
                private var matFloor:CompositeMaterial;
                private var matFloorBmp:BitmapMaterial;

                private var bmdEnvSphere:BitmapData;
                private var bmdFloor:BitmapData;
                private var matrixEnvSphere:Matrix;
                private var matrixFloor:Matrix;
               
                private var counter:int;
               
               
                public function Pv2Example()
                {
                        init();
                        init3d();
                }
               
                private function init():void
                {
                        this.stage.scaleMode = StageScaleMode.NO_SCALE;
                        sprScene = new Sprite();
                        this.addChild(sprScene);
                        this.addEventListener(Event.ENTER_FRAME, onEnterFrame, false,0,true);
                }
               
               
                private function init3d():void
                {
                        renderer = new BasicRenderEngine();
                       
                        scene = new Scene3D();

                        viewportMain = new Viewport3D(stage.stageWidth, stage.stageHeight, false, true); // interactive
                        viewportMain.opaqueBackground = 0;
                        this.addChild(viewportMain);
                       
                        ism = viewportMain.interactiveSceneManager;
                        Mouse3D.enabled = true;
                       
                        light = new PointLight3D(true);
                        lightSphereEnv = new PointLight3D(false);

                        cameraMain = new Camera3D();
                        cameraMain.zoom = 8;
                        cameraMain.y = 100;
                        cameraMain.z = -1000;
                       
                        matrixEnvSphere = new Matrix();
                        matrixEnvSphere.scale(0.5,-0.5);
                        matrixEnvSphere.translate(0, ENVSPHEREBMP_HEIGHT);

                        // Set up spheres
                       
                        for (var i:int = 0; i < NUMSPHERES; i++)
                        {
                                // [a] materials
                               
                                var m:MaterialObject3D;
                               
                                switch (i)
                                {
                                        case 0:
                                                m = new GouraudMaterial(light, 0xFF3300, 0x000000);
                                                break;
                                        case 1:
                                                m = new PhongMaterial(light, 0xFF3300, 0, 3);
                                                break;
                                        case 2:
                                                m = new CellMaterial(light, 0xFF3300, 0x000000, 4);
                                                break;
                                        case 3:
                                                m  = new FlatShadeMaterial(light, 0x000000, 0xFF3300);
                                                break;
                                        case 4:
                                                m = matSphereComposite = new CompositeMaterial();
                                                matSphereComposite.addMaterial( new ColorMaterial(0x0, 0.7) );
                                                matSphereComposite.addMaterial( new WireframeMaterial(0xFF3300, 100) );
                                                break;                                       
                                        case 5:
                                                // An environment map material whose lightmap is
                                                // updated with the BitmapData of the main scene
                                                bmdEnvSphere = new BitmapData(ENVSPHEREBMP_WIDTH,ENVSPHEREBMP_HEIGHT);
                                                m = matSphereEnv = new EnvMapMaterial(lightSphereEnv, bmdEnvSphere, null, 0);
                                                matSphereEnv.lightMap = bmdEnvSphere;
                                                break;
                                        case 6:
                                                // A ShadedMaterial using an environment map shader. Uses perlin noise generator
                                                // for the 'base' bitmap, the environment map bitmap, and the bumpmap.
                                                var bmdBase:BitmapData = new BitmapData(250,250,true,0x0);
                                                bmdBase.perlinNoise(75,75, 5, 0x000001, true, true, 1, true);
                                                var b:BitmapMaterial = new BitmapMaterial(bmdBase);
                                               
                                                var bmdEnv:BitmapData = new BitmapData(250,250,false,0x888888);
                                                bmdEnv.perlinNoise(150,150, 5, 0x000002, true, false, 1|2|4 , true);

                                                var bmdBump:BitmapData = new BitmapData(250,250,false,0x888888);
                                                bmdBump.perlinNoise(150,150, 5, 0x000003, true, false, 1|2|4 , true);

                                                var s:Shader = new EnvMapShader(light, bmdEnv, bmdEnv, 0x0, bmdBump, null);
                                                m = new ShadedMaterial(b, s, 0);
                                                break;
                                }
                                m.interactive = true;
                               
                                // [b] object properties
                               
                                var d:DisplayObject3D = new Sphere( m, 100, 8,6 );
                                d.x = 325;
                                d.y = 100;
                                d.z = 0;
                                var p:Number3D = new Number3D(d.x, d.y, d.z);
                                p = rotateY(p , i/NUMSPHERES * 360 * DEGREE );
                                applyNumber3D(p, d);

                                d.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onSphereClick);

                                scene.addChild(d, "s" + i.toString());
                        }
                       
                        // Set up floor:

                        // [a] viewport
                        viewportFloor = new Viewport3D(FLOORBMP_SIDE,FLOORBMP_SIDE, false);
                        viewportFloor.opaqueBackground = 0x222222;
                        viewportFloor.filters = [ new BlurFilter(15,15,1)];

                        // [b] material
                        bmdFloor = new BitmapData(FLOORBMP_SIDE,FLOORBMP_SIDE,true);
                        matFloorBmp = new BitmapMaterial(bmdFloor);
                        matFloor = new CompositeMaterial();
                        matFloor.addMaterial(matFloorBmp);
                        matFloor.addMaterial( new WireframeMaterial(0x444444,100) );
                       
                        // [c] matrix
                        matrixFloor = new Matrix();
                        matrixFloor.scale(1,-1);
                        matrixFloor.translate(0,FLOORBMP_SIDE);

                        // [d] camera (looks up at the spheres from below)
                        cameraFloor = new FreeCamera3D();
                        cameraFloor.zoom = 11.2; // bigger zoom in hopes of minimizing effects of perspective a little
                        cameraFloor.focus = 50;
                        cameraFloor.x = 0;
                        cameraFloor.y = -1000;
                        cameraFloor.z = 0;
                        cameraFloor.pitch(-90);

                        // [e] object setup
                        floor = new Plane(matFloor, 1000,1000, 10,10);
                        floor.x = floor.y = floor.z = 0;
                        floor.rotationX = -90;
                        scene.addChild(floor);
                }
               
                private function onSphereClick(e:InteractiveScene3DEvent):void
                {
                        // Make sphere bounce...
                        Tweener.addTween(e.target, { y:100, _bezier:{ y:600 }, time:3, transition:"easeoutbounce"} );
                }

                private function onEnterFrame(e:Event):void
                {
                        this.stage.focus = this;

                        // Move camera based on mouse position
                        var x:Number = (stage.mouseX - stage.stageWidth/2) / 4;
                        cameraMain.moveLeft(x);
                        var y:Number = (stage.mouseY - stage.stageHeight/2) / 6;
                        cameraMain.moveDown(y);
                        if (cameraMain.y > 1000 || cameraMain.y < -200) cameraMain.moveDown(-y);

                        // Rotate light source around camera
                        counter += 3;
                        var lightPos:Number3D = new Number3D(cameraMain.x, cameraMain.y, cameraMain.z);
                        var r:Number = Math.sin( counter*DEGREE ) * 180;
                        lightPos = rotateY( lightPos, r*DEGREE );
                        applyNumber3D(lightPos, light);
                       
                        // 'Render' and draw floor
                        // [* Alternate method: Use BitmapViewportMaterial + BitmapViewport3D] 
                        renderer.renderScene(scene, cameraFloor, viewportFloor);
                        bmdFloor.draw(viewportFloor, matrixFloor);
                        matFloorBmp.bitmap = bmdFloor;
                        matFloorBmp.updateBitmap();

                        // Update light source for the env. map sphere and then update its bitmap
                        applyNumber3D(lightPos, lightSphereEnv);
                        bmdEnvSphere.draw(viewportMain, matrixEnvSphere);

                        // Render scene
                        renderer.renderScene(scene, cameraMain, viewportMain);
                }

               
                // Helper functions:
               
                public function rotateY(p:Number3D, angleY:Number) : Number3D {
                        var x1:Number = Math.cos(angleY) * p.x - Math.sin(angleY) * p.z;
                        var z1:Number = Math.cos(angleY) * p.z + Math.sin(angleY) * p.x;
                        var y1:Number = p.y;
                        return new Number3D(x1, y1, z1);
                }
               
                public function applyNumber3D(p:Number3D, d:DisplayObject3D):void
                {
                        d.x = p.x;
                        d.y = p.y;
                        d.z = p.z;
                }
        }
}
分享到:
评论

相关推荐

    COM3D2.ModLoader:用于类似 GameData 的功能的 Sybaris 修补程序

    ModLoader 能够从 Mod 文件夹加载.ks和.ogg文件(.ks 支持在 1.5 版中添加;.ogg 自 1.7.2 起)。 对这些的处理有点特殊,那些好奇的人可以在上阅读它 修补程序还优先处理从 Mod 文件夹加载的文件,而不是从 .arc ...

    COM3D2.Toolkit:COM3D2 WARCWARP工具包

    - **脚本工具**:可能包括辅助脚本编写和调试的功能,帮助用户更高效地编写和测试游戏逻辑。 - **导出/导入工具**:可能支持将资源从WARCs导出到硬盘,便于在其他程序中编辑,然后再导入回游戏,进行资源的版本...

    com3d2.propmyitem.plugin:코루틴버전

    COM3D2.PropMyItem.Plugin 修复了由1.48+引起的问题。 在IMGUI文本框中键入内容可防止意外激活。 消除场景限制,因此随时随地激活PropMyItem。 所有功劳归原始开发者所有。

    COM3D2.Lilly.BepInExPlugin:重新创建了可以用.NET 3.5编译的项目

    使用特定场景或功能时自动应用也保存为配置文件:COM3D2 \ BepInEx \ config \ COM3D2.Lilly.Plugin.HarmonyUtill.cfg 基本补丁 收集要自动应用的事物 CharacterMgrPatchBase:消除了在加载预设时发生启动错误时不...

    导出COM3D2模型为MMD可用资源的插件

    在COM3D2中,模型通常包含复杂的物理模拟和动态效果,插件需要正确地处理这些信息,以便在MMD中保持尽可能接近原始表现的质量。 安装插件的过程相当简单。一旦下载并解压文件,将...

    RT-N56UB1-newif3D2-512M_20190923.zip

    标题中的"RT-N56UB1-newif3D2-512M_20190923.zip"表明这是一个针对特定型号路由器的固件升级包。RT-N56U是华硕(ASUS)生产的一款双频千兆无线路由器,B1可能是其某个特定版本或变种。"newif3D2"可能是固件的新功能...

    DN3D2.rar_DYNA3D_dyna3d.rar_侵彻_接触 有限元_有限元 动力

    洛斯阿拉莫斯实验室开发的显示动力有限元程序dyna3d,可处理碰撞,侵彻和接触等问题,有丰富的材料模型和状态方程,以及可扩展的二次开发能力。

    RT-N56UB1-newif3D2-512M_3.4.3.9-099.trx

    看新路由三固件老毛子固件没事下载下来看看吧。。。。。

    COM3D2.ExtendedPresetManagement:这是COM3D2的一个简单插件,它允许用户将预设组织到文件夹中并即时切换到它们,并允许将预设保存到任何名称的任何位置。

    强大的保存功能使您可以覆盖,重命名和替换预设到所需的位置(默认值可以在配置中更改)。 安装 这是一个BepinEx插件,因此在发行部分中找到的dll文件进入BepinEx/plugins 。 用法 在您的预设文件夹中新建文件夹(按...

    Gallery2.apk 照相机

    Gallery2.apk 这是一个相机应用

    3D-3D2commons.zip

    3D-3D2commons.zip,从硬盘上传和发布三维文件到wikimedia commons和sketchfab。进一步发展暂缓。,3D建模使用专门的软件来创建物理对象的数字模型。它是3D计算机图形的一个方面,用于视频游戏,3D打印和VR,以及其他...

    FLAC3D2Tecplot501_flac3D_FLAC3D2Tecplot501_

    标题中的"FLAC3D2Tecplot501_flac3D_FLAC3D2Tecplot501_"表明这是一个与FLAC3D软件和Tecplot数据转换相关的程序或工具。FLAC3D是一款广泛应用于地质力学、土木工程以及采矿领域的三维有限差分软件,它能够模拟地下...

    H大2021.6.19日版newifi3D2固件RT-N56UB1-newifi3D2-512M_3.4.3.9-099.trx

    H大2021.6.19日版newifi3D2固件RT-N56UB1-newifi3D2-512M_3.4.3.9-099.trx

    FLAC3D2Tecplot501_flac3D_tecplot_

    Tecplot是一款专业级的数据可视化和分析软件,能够处理大量数据并生成高质量的2D和3D图形,包括等值线图、矢量图、曲面图等。对于FLAC3D的使用者来说,Tecplot是一个理想的工具,可以帮助他们更直观地理解FLAC3D计算...

    com3d2_com3d2

    com3d2人物模型,有意者自取,不用谢

    Com3d2自整合插件包

    最后,"Mod"一词通常指的是游戏的修改或模组,这里可能是指包含的各种用户创建的游戏内容,如纹理、模型、脚本等。这些Mod可以让玩家个性化他们的游戏体验,增加新的挑战或故事线。 综上所述,《Com3d2自整合插件包...

    3D2rewq.tar

    这是ASC14三维弹性波的代码,有需要的下载。数据文件没有上传

    html6game幻灯片特效带有HTML5+CSS3和3D2D效果.zip

    结合“3D2D效果”,我们可以理解为这个项目可能同时利用了CSS3的2D和3D转换。2D转换包括旋转、缩放、平移等,3D转换则可以模拟深度,创建出更真实的视觉效果。这些效果可以应用于幻灯片的切换,使得过渡更加流畅且...

Global site tag (gtag.js) - Google Analytics