"Test scripts for Genesis3D Engine.
Evaluate the expressions to see how to use GenesisAPI.

Smalltalk sendersOf: #notFullyImplemented.
"

"Open a window for engine testing.
 WARNING: Select window mode for testing."
test := GenesisWorkbench open.

test engine drivers collect: [:each|each name ].
test engine drivers collect: [:each|each type ].

"Prompt & Open a level file.
test openFile. 
"
test openFile: 'levels\Boids.bsp'.

"Move the world and cammera to (0,0,0) and no rotations"
test xForm
    rotation: 0 y: 0 z: 0;
    x: 0 y: 0 z: 0;
    yourself.
test update.

"moving in X direction (right-left)"
1 to: 30 do: [:i| test xForm x: i*8 y: 0 z: 0. test update ].test home.
1 to: 30 do: [:i| test xForm x: i*8 negated y: 0 z: 0. test update ].test home.
"moving in Y direction(down-up)"
1 to: 30 do: [:i| test xForm x: 0 y: i*8 z: 0. test update ].test home.
1 to: 30 do: [:i| test xForm x: 0 y: i*8 negated z: 0. test update ].test home.
"moving in Z direction(back-fore)"
1 to: 30 do: [:i| test xForm x: 0 y: 0 z: i*8. test update ].test home.
1 to: 30 do: [:i| test xForm x: 0 y: 0 z: i*8 negated. test update ].test home.
 
test home.

"X axis rotation "
7 timesRepeat: [
    test xForm rotate: 0.1 y: 0 z: 0. test update
 ].
7 timesRepeat: [
    test xForm rotate: -0.1 y: 0 z: 0. test update
 ].

"Y axis rotation "
7 timesRepeat: [
    test xForm rotate: 0 y: 0.1 z: 0. test update
 ].
7 timesRepeat: [
    test xForm rotate: 0 y: -0.1 z: 0. test update
 ].

"Z axis rotation "
7 timesRepeat: [
    test xForm rotate: 0 y: 0 z: 0.1. test update
 ].
7 timesRepeat: [
    test xForm rotate: 0 y: 0 z: -0.1. test update
 ].
 
test home.

"Display a bitmap (obtained from aFile) as a background bitmap."
engine := test engine.
bitmap := GenesisBitmap fromPathName: 'test.bmp'. " 'test64.bmp'. "
bitmap isValid ifTrue: [ 
    bitmap setColorKey: 250. 
    engine addBitmap: bitmap.
    test view when: #endFrame: do: [
        box := bitmap boundingBox.
        [ box top < test pane height ] whileTrue: [
            bitmap displayAt: box origin in: engine.
            box moveBy: box width @ 0.
            box left > test pane width ifTrue: [ box moveBy: box left negated @ box height ].
        ].
    ].
].
[ test update. MessageBox confirm: 'Redraw ?'] whileTrue.
test view removeActionsForEvent: #endFrame: .

"Set light system to default lightin"
test world setDefaultLightTables.

"Change the current gamma"
temp := test engine gamma.
0 to: 3 by: 1/4 do: [:each|
    test engine gamma: each.
    test update.
].
test engine gamma: temp.
test update.

"Search for an entitySet of an specified name."
(test world getEntitySet: 'CameraStart') inspect.

"get all the names in the entiry set."
(test world getEntitySet: 'CameraStart') collect: [:each| each name ].

"Get first entity in the set (the default camera) and its user data"
(CameraStart allFromWorld: test world) first.

"Try to find an edited player start position."
test world getEntitySet: 'PlayerStart' ifAbsent: [].

"All ActorStart instances defined in the world.
    test world entitiesInSet: 'ActorStart' as: ActorStart.
you can use also this (recommended) expression..."
ActorStart allFromWorld: test world.

"Collect actor names"
(ActorStart allFromWorld: test world) collect: [:each| each name ].

"get an actor from a file at specified pathName"
actor := GenesisActor
    fromPathName: test world fileNamePath,'\..\actors\anemone.act'.

"Get all actor from a directory"
directory := Directory pathName: test world fileNamePath,'\..\actors\'.
(directory filesNamed: '*.act') collect: [:each|
    GenesisActor fromPathName: directory drivePathName ,'\',each 
].

"list materials in an actor"
actor body materialInfos.

"get actor dynamic bounding box."
actor dynamicExtBox.
actor extBox.

"Get all the Doors"
(test world
    getEntitySet: 'Door' ifAbsent: [^'no doors'])
    collect: [:each| each name ].

"Get all the ModelControllers"
(test world
    getEntitySet: 'ModelController' ifAbsent: [^'no ModelControllers'])
    collect: [:each| each name ]. 

"add teh actor to current world"
test world addActor: actor.
actor scale: 1/2.
test update.

"Get the first motion of the actor."
actor motions first.

"adjust actor scale."
actor scale: 2.
test update.

"adjust actor scale."
actor scale: 1/4.
test update.

"Adjust actor orientation and position."
start := location := GenesisXForm identity
    rotateX: (Float pi / 2) negated; "face to us"
    translation: test xForm translation;
    translate: 10    "to right    x>0=right    x<0=left"
    y: 50 negated  "down        y>0=up    y<0=down"
    z: 250 negated  "bottom    z>0=front    z<0=bottom"
    ;yourself.
motion := actor motionNamed: 'Idle' ifAbsent: [ actor motions first ].
actor setPoseTo: motion time: 0 transform: location.
test update. 

"block to move actor acording to location."
move := [ "block for actor updating"
    actor setPoseTo: motion time: 0 transform: location. test update.     
].
steps := 50.

"Rotate the actor"
location := start copy.
steps timesRepeat: [
    location rotateZ: Float pi / steps * 2.
    move value.
].

"Rotate the actor"
location := start copy.
steps timesRepeat: [
    location rotateX: Float pi / steps * 2.
    move value.
].

"Rotate the actor"
location := start copy.
steps timesRepeat: [
    location rotateY: Float pi / steps * 2.
    move value.
].

"Translate the actor"
location := start copy.
steps timesRepeat: [
    location translateX: 100 / steps * 2.
    move value.
].

"Translate the actor"
location := start copy.
steps timesRepeat: [
    location translateY: 100 / steps * 2.
    move value.
].

"Translate the actor"
location := start copy.
steps timesRepeat: [
    location translateZ: 100 / steps * 2.
    move value.
].

"Rotate the actor in place"
location := start copy.
steps timesRepeat: [
    location
        rotateY: Float pi / steps * 2;
        translation: start translation.
    move value.
].

"Rotate the actor in place"
location := start copy.
steps timesRepeat: [
    location
        rotateX: Float pi / steps * 2;
        translation: start translation.
    move value.
].

"Rotate the actor in place"
location := start copy.
steps timesRepeat: [
    location
        rotateZ: Float pi / steps * 2;
        translation: start translation.
    move value.
].

"Returns all the names of the actor motions"
actor motions collect: [:each| each name ].

"Show the actor motions"
actor motions do: [:each|
    location := start copy.
    time := 0.
    20 timesRepeat: [
        time := time + 0.1.
        time > 5 ifTrue: [ time := 0 ].
        actor
            setPoseTo: each
            time: time
            transform: location.
        test update.
        test pane pen
            centerText: each name
            at: test pane boundingBox center. 
        location translate: 10 negated y: 0 z: 0.
     ].
 ].

test update.
