Home   Help Search Login Register  

Author Topic: o2scripts  (Read 2393 times)

0 Members and 1 Guest are viewing this topic.

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
o2scripts
« on: 18 Dec 2008, 21:24:38 »
I want to share a few basic o2 scripts.
As there is very limited info out there, I thought it might be a good idea.

Single thread per script vs summary thread. Well unsure whats best here.
I do the summary thread for now. Please move if wrong category.  :good:



Unfortunately there are too many things on the list for perfect documentation.
So hope the basic summary is enough. Otherwise feel free to ask.  :)



1) Change model geometry LOD overall mass or remove all points

It was used for PROPER plants to make heavy tanks not stopped by mowing down trees (model mass = 200).
And to remove the geometry LOD completely by removing all points to be able to hide within it.

You can assign these two functions as action.
Quote
_action = _setMass; //_delete

Apply the script per model.

Code: [Select]
scopeName "mainScope";
#include "std\lodNames.inc"
console = openStandardIO;

#define TOTAL_OBJECT_MASS 100

_levels = (getResolutions this);

_delete =
{
private ["_selection", "_objectData", "_sel", "_level"];
_selection = _this select 0;
_objectData = _this select 1;
if (_objectData checkSelectionName _selection) then
{
_sel = _objectData loadSelection _selection;
//console << str(getPointWeights _sel) << eoln;
deleteSelected _sel;

_objectData deleteSelection _selection;
_level = _this select 2;
//console << (_level call lodNameGetName) + " - Deleting " + str(_selection) << eoln;
};
};

_setMass =
{
_found = this setActiveSpecial LOD_GEOMETRY;
if (_found) then
{
_mesh = getActiveObject this;
_NoOfPoints = countPoints _mesh;
_massPerPoint = 100/_NoOfPoints;
_mesh forEachPoint [{true},{_mesh setPointMass [_x,_massPerPoint];}];
};
};

_action = _setMass;

//Loop for each level of the model.
for "_i" from 0 to ((count _levels) - 1) do
{
_level = (_levels select _i);
_levelName = _level call lodNameGetName;
//console << str(_levelName) << eoln;
if (_levelName == "Geometry") then //Geometry
{
//Select new active level.
this setActive (this findLevel (_level));

//Determine selections in the current level.
_objectData = ((getObjects this) select (activeLevel this));

_selections = getSelections _objectData;

//Loop for each selection in the current level.
for "_k" from 0 to ((count _selections) - 1) do
{
[(_selections select _k), _objectData, (_level)] call _action;
};
};
};

That aside I used autoIt to focus the o2 instance of each model, apply the script, save and close the model.
Note that you have to open all models yourself beforehand.
Also this autoIt script file needs to be inside the folder of the p3d files.

Code: [Select]
#include<file.au3>

Dim $sourceFolder = @ScriptDir

$Array = _FileListToArray($sourceFolder, "*.p3d", 1)
For $i=1 To $Array[0]
    $name = $Array[$i]
MyUDFAcceptingArguments($name)

Next


Func MyUDFAcceptingArguments($arg1)
$name = $arg1 ;"banana_4.p3d - Oxygen 2 Personal Edition"

WinSetState($name, "", @SW_SHOW)

if (WinActivate($name, "")) then
;WinWaitActive($name, "")
Sleep(100)
Send("+2")
Sleep(100)
Send("^s")
Sleep(100)
Send("!f")
Sleep(100)
Send("x")
;Exit
EndIf

EndFunc   

Note that +2 means shift 2. I assign the o2script to that key.



2) Copy view LOD from one p3d to another by T_D

Thanks to T_D for the o2script again!

Just add all p3ds with path at the very end of the o2script and execute it in o2.

Code: [Select]
#include "std/SpecialLod.hpp"

console=openStandardIO;

/*******************************
/*copyViewLOD
/* Description: deletes the ViewGeo LOD of _dstModel and copies the ViewGeo LOD of _srcModel into it and save this new model as _newName
/* _srcModel: path to the source model file
/* _dstModel: path to the model file that will get the ViewGeo LOD of _srcModel
/*
/* Example: ["P:\Durg\tree.p3d","P:\PROPER Plants\tree.p3d"] call _copyViewLOD;
/*******************************/
_copyViewLOD =
{
private["_srcP3d","_srcModel","_srcViewLOD","_dstP3d","_dstModel","_dstViewLOD"];

_srcModel = _this select 0;
_dstModel = _this select 1;
//_newName = _this select 2;

_srcP3d = newLODObject;
if(!(_srcP3d loadP3D _srcModel))then{console<<"Couldn't load " + _srcModel};
_srcViewLOD = (getObjects _srcP3d) select (_srcP3d findLevelSpecial LOD_VIEWGEO);

_dstP3d = newLODObject;
if(!(_dstP3d loadP3D _dstModel))then{console<<"Couldn't load " + _dstModel};
_dstViewLOD = (getObjects _dstP3d) select (_dstP3d findLevelSpecial LOD_VIEWGEO);

_dstViewLOD := _srcViewLOD;

if(!(save (_dstP3d as _dstModel)))then{console<<"Couldn't save " + _dstModel};
};

//here the code that calls the function
//best would be an iteration through all the models in one folder I suggest, but I guess you can do that yourself ;)

["P:\plants_VB\Akat02S.p3d","P:\Plants\Akat02S.p3d"] call _copyViewLOD;
["P:\plants_VB\banana_2.p3d","P:\Plants\banana_2.p3d"] call _copyViewLOD;
...
« Last Edit: 18 Dec 2008, 21:28:46 by PROPER.Q »

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: o2scripts
« Reply #1 on: 03 Jan 2009, 11:01:38 »
The magic bouncing thread! Okay, this goes here now, since this is the O2 board. :D Now I just need to figure out how to put this (with instructions) into a nice little file for uploading. Hmm....maybe I should order one of my underlings to do that...  :cool2:

Thanks for the scripts Q!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"