Author Topic: Script for C09032008 (Many pics)  (Read 5113 times)

0 Members and 1 Guest are viewing this topic.

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Script for C09032008 (Many pics)
Get the build from the release thread

There's pretty much only one interesting function in the new build - gr.drawModel(model, position, orientation). You have to call it from $On Object Render, so a barebone script would look like this:

Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$State: GS_STATE_GAME_PLAY
$On Object Render: [
if not g_Rendered then
gr.drawModel("fighter01")
g_Rendered = true
end
]
$On Frame: [
g_Rendered = nil
]
#End

This basically makes sure that the drawModel calls only get called once per frame.

I spent an hour or two playing around with this to make sure it worked. I've attached the script that I used to play around with this - just change "if false then" to "if true then" to switch on one of the following 'tests'.

I'll let the pictures speak for themselves. :)

drawmodel_test-sct.tbm
Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$On Mission Start: [
--Ship field
if false then
g_ShipFieldModel = tb.ShipClasses['GTF Ulysses'].Model
end

--Tic tac toe
if false then
g_TicTacToeModels = {
K=tb.ShipClasses['Knossos'].Model,
N=tb.ShipClasses['GTNB Pharos'].Model,
S=tb.ShipClasses['SF Mara'].Model,
T=tb.ShipClasses['GTF Ulysses'].Model,
V=tb.ShipClasses['GVF Seth'].Model,
}
local K='K'
local N='N'
local S='S'
local T='T'
local V='V'
g_TicTacToeArray =
{
{0,0,0,0,0,N,0,0,0,0,0,N,0,0,0,0,0},
{0,S,0,S,0,N,0,0,0,0,0,N,0,T,T,T,0},
{0,0,S,0,0,N,0,0,0,0,0,N,0,T,0,T,0},
{0,S,0,S,0,N,0,0,0,0,0,N,0,T,T,T,0},
{0,0,0,0,0,N,0,0,0,0,0,N,0,0,0,0,0},
{N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N},
{0,0,0,0,0,N,0,0,0,0,0,N,0,0,0,0,0},
{0,0,0,0,0,N,0,S,0,S,0,N,0,T,T,T,0},
{0,0,0,0,0,N,0,0,S,0,0,N,0,T,0,T,0},
{0,0,0,0,0,N,0,S,0,S,0,N,0,T,T,T,0},
{0,0,0,0,0,N,0,0,0,0,0,N,0,0,0,0,0},
{N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N},
{0,V,0,V,0,N,0,0,0,0,0,N,0,0,0,0,0},
{0,V,0,V,0,N,0,0,0,0,0,N,0,T,T,T,0},
{0,0,V,0,0,N,0,0,0,0,0,N,0,T,0,T,0},
{V,0,0,0,V,N,0,0,0,0,0,N,0,T,T,T,0},
{0,V,V,V,0,N,0,0,0,0,0,N,0,0,0,0,0},
}
end

--Shivan Knossos
if false then
g_CircleModel = tb.ShipClasses['SF Mara'].Model
g_CircleMarkerModel = tb.ShipClasses['ST Azrael'].Model
g_CircleSpeed = math.pi/4 --rad/s
g_CirclePosition = 0
end

--Oscillator
if false then
g_OscillatorModel = tb.ShipClasses['GTNB Pharos'].Model
g_OscillatorSpeed = math.pi/4 --rad/s
g_OscillatorPosition = 0
end
]

$Application: Freespace 2
$State: GS_STATE_GAME_PLAY
$On Object Render: [
if not g_Rendered then
local pos = ba.newVector(0, 0, 1000)
local ori = ba.newOrientation(0, 0, math.pi)
if g_ShipFieldModel then
local shipRadius = g_ShipFieldModel.Radius
for i=1,50 do
for j=1,50 do
pos.X = i*shipRadius
pos.Y = j*shipRadius
gr.drawModel(g_ShipFieldModel, pos, ori)
end
end
end
if g_TicTacToeArray then
local shipRadius = 15
local width = 0
local height = #g_TicTacToeArray
for y=1,height do
row = g_TicTacToeArray[y]
width = #row
for x=1,width do
pos.X = x*shipRadius
pos.Y = (height-y)*shipRadius
local model = g_TicTacToeModels[row[x]]
if model then
gr.drawModel(model, pos, ori)
end
end
end
end
if g_CircleModel then
ori.H = -math.pi/2
--local ori = ba.newOrientation(0, 0, 0)
local resolution = 250
local radius = 500
for i=1,resolution do
local fraction = (i/resolution)*2*math.pi - g_CirclePosition
pos.X = radius*math.cos(fraction)
pos.Y = radius*math.sin(fraction)
ori.p = math.pi/2 + fraction
if (i%(resolution/10)) == 0 then
gr.drawModel(g_CircleMarkerModel, pos, ori)
else
gr.drawModel(g_CircleModel, pos, ori)
end
end
g_CirclePosition = g_CirclePosition + ba.getFrametime()*g_CircleSpeed
while g_CirclePosition >= 2*math.pi do
g_CirclePosition = g_CirclePosition - 2*math.pi
end
end
if g_OscillatorModel then
local width = 1000
local xStart = -500
local zStart = 1000
local amplitude = 100
local numWide = 40
local numWideWaves = 4
local numDeep = 20
local shipRadius = g_OscillatorModel.Radius
for i=1,numWide do
local wideFraction = numWideWaves*(i/numWide)*2*math.pi - g_OscillatorPosition
pos.X = xStart + width*(i/numWide)
for j=1,numDeep do
local deepFraction = (j/numDeep)*2*math.pi - g_OscillatorPosition
pos.Y = amplitude*math.sin((wideFraction + deepFraction)/2)
pos.Z = zStart + j*shipRadius
gr.drawModel(g_OscillatorModel, pos, ori)
end
end
g_OscillatorPosition = g_OscillatorPosition + ba.getFrametime()*g_OscillatorSpeed
while g_OscillatorPosition >= 2*math.pi do
g_OscillatorPosition = g_OscillatorPosition - 2*math.pi
end
end
g_Rendered = true
end
]
$On Frame: [
g_Rendered = nil
]
#End

Screenshots:







NOTE: If you take a careful look at the script, you'll notice that both the Shivan Knossos and the Oscillator are both animated. :D
« Last Edit: September 03, 2008, 05:51:34 am by WMCoolmon »
-C

 

Offline Galemp

  • Actual father of Samus
  • 212
  • Ask me about GORT!
    • Steam
    • User page on the FreeSpace Wiki
Re: Script for C09032008 (Many pics)
silly.
"Anyone can do any amount of work, provided it isn't the work he's supposed to be doing at that moment." -- Robert Benchley

Members I've personally met: RedStreblo, Goober5000, Sandwich, Splinter, Su-tehp, Hippo, CP5670, Terran Emperor, Karajorma, Dekker, McCall, Admiral Wolf, mxlm, RedSniper, Stealth, Black Wolf...

 

Offline Vasudan Admiral

  • Member
  • 211
    • Twisted Infinities
Re: Script for C09032008 (Many pics)
lol, well that's one of the whackier things I've seen in FS. :D

By the looks of it though, this draws a model without creating a ship right? Ie, they'd have no collision mesh and essentially be just a ghost? If so I think there'd be quite a few interesting applications of that then.

Also, out of curiosity, what would you estimate the efficiency gain would be of a bunch of drawn models vs an identical number of ships?
Get the 2014 Media VPs and report any bugs you find in them to the FSU Mantis so that we may squish them. || Blender to POF model conversion guide
Twisted Infinities

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Script for C09032008 (Many pics)
Yes and yes.

I don't have any meaningful estimate of how much faster it would be to use models as opposed to ships. However, they don't require AI, physics, or anything else of the like, and they also don't take up time to check collisions for anything else. I'd guess there'd be a noticeable gain with large numbers. If you notice, the Shivan Knossos was 250 fighters and the Oscillator was 800 nav buoys - the latter is something that's not even possible with conventional Freespace, much less at 6 FPS.

Image 6, with the Shivan Knossos, is running with MediaVPs enabled, too.
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Script for C09032008 (Many pics)
hell yea!
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline redsniper

  • 211
  • Aim for the Top!
Re: Script for C09032008 (Many pics)
Almost as cool as the accidental fighter swarms that one guy made. "The sky full of Hercs"
"Think about nice things not unhappy things.
The future makes happy, if you make it yourself.
No war; think about happy things."   -WouterSmitssm

Hard Light Productions:
"...this conversation is pointlessly confrontational."

 

Offline Kobrar44

  • On Suspended Sentence
  • 29
  • Let me tilerape it for you!
    • Steam
Re: Script for C09032008 (Many pics)
Well... After few modifications w can use it as wing drawer. You set posision of 'Alpha1', type in number of wings, specify ship types and weaponry... 1 wing has usually got 1 ship type and 1 weapon type, so it'd be usefull. Wings.tbl would contain wings names for specified side of the conflict or nation, it can be also specified in the same tbl. Just wondering and don't kill me if somebody thought of that earlier. Just haven't seen it.
Oh guys, use that [ url ][ img ][ /img ][ /url ] :/

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Script for C09032008 (Many pics)
Ummm. Not sure I understand what you said there. The problem with this script is that it only draws the models. There is no AI, or collision detection processing for them. In other words, you can't use it to place objects into the mission that a player interacts with.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Colonol Dekker

  • HLP is my mistress
  • 213
  • Aken Tigh Dekker- you've probably heard me
    • My old squad sub-domain
Re: Script for C09032008 (Many pics)
Bohemian Rhapsody musc video effects. . . .
 
JAD4 addition mayhaps?
Campaigns I've added my distinctiveness to-
- Blue Planet: Battle Captains
-Battle of Neptune
-Between the Ashes 2
-Blue planet: Age of Aquarius
-FOTG?
-Inferno R1
-Ribos: The aftermath / -Retreat from Deneb
-Sol: A History
-TBP EACW teaser
-Earth Brakiri war
-TBP Fortune Hunters (I think?)
-TBP Relic
-Trancsend (Possibly?)
-Uncharted Territory
-Vassagos Dirge
-War Machine
(Others lost to the mists of time and no discernible audit trail)

Your friendly Orestes tactical controller.

Secret bomb God.
That one time I got permabanned and got to read who was being bitxhy about me :p....
GO GO DEKKER RANGERSSSS!!!!!!!!!!!!!!!!!
President of the Scooby Doo Model Appreciation Society
The only good Zod is a dead Zod
NEWGROUNDS COMEDY GOLD, UPDATED DAILY
http://badges.steamprofile.com/profile/default/steam/76561198011784807.png

 

Offline Kobrar44

  • On Suspended Sentence
  • 29
  • Let me tilerape it for you!
    • Steam
Re: Script for C09032008 (Many pics)
I'm talking about ships with AI and everything, just placed in nice formations by script in FRED. Grouped into wings and all that stuff.
Oh guys, use that [ url ][ img ][ /img ][ /url ] :/

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Script for C09032008 (Many pics)
...

You have no idea what this is, do you?

What you are asking for is a modification of the AI behaviour, namely one that allows it to fly in formation. This script (and note that "script" and "mission" are two different things here) just generates a bunch of models at predefined coordinates.
The objects created with this have no AI and no collision detection. You can use it to do some funky cutscene stuff, but not the kind of behaviour you want to do.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: Script for C09032008 (Many pics)
Great idea! This could be extremely useful for the obligatory trippy dream sequences that every good fan-made campaign requires.
If I could remember the names of all these particles, I'd be a botanist. --Enrico Fermi

 

Offline Angelus

  • 210
  • The Angriest Angel
Re: Script for C09032008 (Many pics)
Judging from the pics, the number of models drawn exeeds the max-model-in-mission limit.
Would that work with the latest nightly? If yes, that would solve one big problem for me...

 

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
Re: Script for C09032008 (Many pics)
Well, WMC's code for it was never committed (afaik)... I wrote my own to replace it, which used the same syntax.

I've heard mention of this recently though, and I'm not entirely sure what the status of it is. Wanderer might know.

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Script for C09032008 (Many pics)
It works.. though your function was made for totally different circumstance than what WMC function was.

There is now drawModelOOR function for drawing models in On Object Render hook and in that hook alone. It allows you to draw objects just like other objects are. If you use Aardwolf's function (valid in other hooks) then you draw objects on top of other objects. Both have their uses.
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
Re: Script for C09032008 (Many pics)
* Aardwolf high-fives Wanderer

 

Offline Angelus

  • 210
  • The Angriest Angel
Re: Script for C09032008 (Many pics)
Does this has a significant impact on performance?
I mean, i need at least 300+ drawn models permanently in mission together with around 50-80 normal models ( normal = with collision detection and 30 something are AI ships ).

 

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
Re: Script for C09032008 (Many pics)
Does this has a significant impact on performance?

If you use it, it could potentially offer some improvement. Needless to say, having 300 models is not possible otherwise, so...

 

Offline Cobra

  • 212
  • Snake on a Cain
    • Minecraft
    • Skype
    • Steam
    • Twitter
To consider the Earth as the only populated world in infinite space is as absurd as to assert that in an entire field of millet, only one grain will grow. - Metrodorus of Chios
I wept. Mysterious forces beyond my ken had reached into my beautiful mission and energized its pilots with inhuman bomb-firing abilities. I could only imagine the GTVA warriors giving a mighty KIAAIIIIIII shout as they worked their triggers, their biceps bulging with sinew after years of Ivan Drago-esque steroid therapy and weight training. - General Battuta