Hard Light Productions Forums
Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: WMCoolmon on September 03, 2008, 05:28:41 am
-
Get the build from the release thread (http://www.hard-light.net/forums/index.php/topic,56192.0.html)
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:
#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
#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:
(http://fs2source.warpcore.org/temp/wmc/drawmodel01_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel01.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel02_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel02.jpg)
(http://fs2source.warpcore.org/temp/wmc/drawmodel03_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel03.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel04_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel04.jpg)
(http://fs2source.warpcore.org/temp/wmc/drawmodel05_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel05.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel06_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel06.jpg)
(http://fs2source.warpcore.org/temp/wmc/drawmodel07_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel07.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel08_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel08.jpg)
(http://fs2source.warpcore.org/temp/wmc/drawmodel09_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel09.jpg)(http://fs2source.warpcore.org/temp/wmc/drawmodel10_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel10.jpg)
(http://fs2source.warpcore.org/temp/wmc/drawmodel11_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/drawmodel11.jpg)
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
-
silly.
-
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?
-
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.
-
hell yea!
-
Almost as cool as the accidental fighter swarms that one guy made. "The sky full of Hercs"
-
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.
-
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.
-
Bohemian Rhapsody musc video effects. . . .
JAD4 addition mayhaps?
-
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.
-
...
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.
-
Great idea! This could be extremely useful for the obligatory trippy dream sequences that every good fan-made campaign requires.
-
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...
-
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.
-
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.
-
/me high-fives Wanderer
-
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 ).
-
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...
-
http://fs2source.warpcore.org/temp/wmc/drawmodel09.jpg
It's V'Ger!