Jiglib Soccer Field Part 1 and 2

Intro Jiglib Soccer Field

In these two videos I demonstrate how to hack Jiglib to create a soccer field in PV3d. This goes along with Chapter 2, and now that you are a hacker. It’s time to charge on with the rest of the chapter.

Videos

Flash Jiglib Soccer Field Part 1

Flash Jiglib Soccer Field Part 2

Notes (Summary)

  1. Download Jiglib
    http://www.jiglibflash.com/blog/source/
  2. Prepare your PV3D ActionScript Project (in Flash Builder)
  3. Prepare your Jiglib base code
    http://as3.miguelmoraleda.com/page/2/
  4. Hack Jiglib
  5. Add your field
  6. A little touch of photoshop
    www.lynda.com

Click the link below to see all notes and code for this video.

Flash Builder Jiglib Soccer Field

  1. Download Jiglib
    http://www.jiglibflash.com/blog/source/
  2. Prepare your PV3D ActionScript Project (in Flash Builder)
  3. Prepare your Jiglib base code
    http://as3.miguelmoraleda.com/page/2/
  4. Hack Jiglib
  5. Add your field
  6. A little touch of photoshop
    www.lynda.com

Jiblib Base Code

package
{
        import flash.events.Event;
        import jiglib.plugin.papervision3d.Papervision3DPhysics;
        import org.papervision3d.view.BasicView;

        public class Main extends BasicView
        {

                private var _physics:Papervision3DPhysics;

                public function Main()
                {
                        super(0, 0, true);

                        initPhysics();
                        startRendering();
                }

                private function initPhysics():void
                {
                         //need the scene instance (Scene3D) and the speed for the engine
                        _physics = new Papervision3DPhysics(scene, 7);
                }

                override protected function onRenderTick(event:Event = null):void
                {
                        //update the engine in each frame
                        _physics.step();
                        super.onRenderTick(event);
                }
        }
}

Create Ground

private function createGround():void
{
        var mat:WireframeMaterial = new WireframeMaterial(0xCCCCCC);
        var ground:RigidBody = _physics.createGround(mat, 1000, 0);
}

Finished (Hacked) Code

Main Package

package

{

import flash.display.Sprite;

import flash.events.Event;

import jiglib.cof.JConfig;

import jiglib.geometry.*;

import jiglib.math.*;

import jiglib.physics.RigidBody;

[SWF(width=“1200”, height=“600”, backgroundColor=“#000000”, frameRate=“30”)]

import jiglib.plugin.papervision3d.Papervision3DPhysics;

import org.papervision3d.view.BasicView;

import org.papervision3d.materials.*;

import flash.display.Bitmap;

public class JiglibSoccerField extends BasicView

{

private var _physics:Papervision3DPhysics;

public function JiglibSoccerField()

{

super(0, 0, true);

initPhysics();

startRendering();

createSoccerGround();

}

private function initPhysics():void

{

//need the scene instance (Scene3D) and the speed for the engine

_physics = new Papervision3DPhysics(scene, 7);

}

override protected function onRenderTick(event:Event = null):void

{

//update the engine in each frame

_physics.step();

super.onRenderTick(event);

}

////////////////////////////////////////

// Field

////////////////////////////////////////

private function createSoccerGround():void

{

var mat:BitmapFileMaterial = new BitmapFileMaterial(“assets/images/soccerFieldLeaves.jpg”);

var ground:RigidBody = _physics.createSoccerGround(mat, 500, 1000, 16, 16, 0);

ground.rotationX=30;

}

}

}

Jiglib Hacked Method

package jiglib.plugin.papervision3d {

import flash.display.BitmapData;

import jiglib.geometry.JBox;

import jiglib.geometry.JPlane;

import jiglib.geometry.JSphere;

import jiglib.geometry.JTerrain;

import jiglib.math.JMatrix3D;

import jiglib.physics.RigidBody;

import jiglib.plugin.AbstractPhysics;

import jiglib.plugin.papervision3d.pv3dTerrain;

import org.papervision3d.core.proto.DisplayObjectContainer3D;

import org.papervision3d.core.proto.MaterialObject3D;

import org.papervision3d.materials.utils.MaterialsList;

import org.papervision3d.objects.DisplayObject3D;

import org.papervision3d.objects.primitives.Cube;

import org.papervision3d.objects.primitives.Plane;

import org.papervision3d.objects.primitives.Sphere;

/**

* @author bartekd

*/

public class Papervision3DPhysics extends AbstractPhysics {

private var scene:DisplayObjectContainer3D;

public function Papervision3DPhysics(scene:DisplayObjectContainer3D, speed:Number = 1) {

super(speed);

this.scene = scene;

}

public function getMesh(body:RigidBody):DisplayObject3D {

if(body.skin!=null){

return Pv3dMesh(body.skin).mesh;

}else {

return null;

}

}

public function createSphere(material:MaterialObject3D, radius:Number=100, segmentsW:int=8, segmentsH:int = 6):RigidBody {

var sphere:Sphere = new Sphere(material, radius, segmentsW, segmentsH);

scene.addChild(sphere);

var jsphere:JSphere = new JSphere(new Pv3dMesh(sphere), radius);

addBody(jsphere);

return jsphere;

}

public function createCube(materials:MaterialsList, width:Number=500, depth:Number=500, height:Number=500, segmentsS:int=1, segmentsT:int=1, segmentsH:int=1, insideFaces:int=0, excludeFaces:int=0):RigidBody {

var cube:Cube = new Cube(materials, width, depth, height, segmentsS, segmentsT, segmentsH, insideFaces, excludeFaces);

scene.addChild(cube);

var jbox:JBox = new JBox(new Pv3dMesh(cube), width, depth, height);

addBody(jbox);

return jbox;

}

public function createGround(material:MaterialObject3D, size:Number, level:Number):RigidBody {

var ground:Plane = new Plane(material, size, size);

scene.addChild(ground);

var jGround:JPlane = new JPlane(new Pv3dMesh(ground));

jGround.setOrientation(JMatrix3D.getRotationMatrixAxis(90));

jGround.y = level;

addBody(jGround);

return jGround;

}

public function createSoccerGround(material:MaterialObject3D, width:Number, height:Number, seg1:Number, seg2:Number, level:Number):RigidBody {

var ground:Plane = new Plane(material, width, height, seg1, seg2);

scene.addChild(ground);

var jGround:JPlane = new JPlane(new Pv3dMesh(ground));

jGround.setOrientation(JMatrix3D.getRotationMatrixAxis(90));

jGround.y = level;

addBody(jGround);

return jGround;

}

public function createTerrain(terrainHeightMap:BitmapData, material:MaterialObject3D = null, width:Number = 100, depth:Number = 100, maxHeight:Number = 0, segmentsW:int = 1, segmentsH:int = 1):JTerrain {

var terrainMap:pv3dTerrain = new pv3dTerrain(terrainHeightMap, material, width, depth, maxHeight, segmentsW, segmentsH);

scene.addChild(terrainMap);

var terrain:JTerrain = new JTerrain(terrainMap);

addBody(terrain);

return terrain;

}

}

}

2 Responses to Jiglib Soccer Field Part 1 and 2

  1. Dave says:

    Great tutorial, very well written and published. I have a question, is there a way to add custom terrain to the floor, terrain and sky using a heightmap file with Jiglib and Papervision? I seem to be having issues with that, and would I probably resort to just using the ground and plane’s?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: