/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct PlugItems = [ ITEMS_inst : PInstance, ITEMS_instName : S, ITEMS_ref : SO3_OBJECT, ITEMS_parent : SO3_OBJECT, ITEMS_bSons : I, ITEMS_player : SO3_OBJECT, ITEMS_iPlayerType : I, ITEMS_iIndex : I, ITEMS_lItems : [[S [SO3_OBJECT [F F F] [F F F F] [F F F]]] r1], ITEMS_bLoaded : I, ITEMS_bHide : I, ITEMS_iRandomCnt : I, ITEMS_fRandomSize : F, ITEMS_iRandomVecType : I, ITEMS_iRandomAngType : I, ITEMS_iCollectType : I, ITEMS_iEffectType : I, ITEMS_fEffectSpeed : F, ITEMS_iTickUpdate : I, ITEMS_bItemEvent : I, ITEMS_bContact : I, ITEMS_bRayIn : I, ITEMS_bRayOut : I, ITEMS_bOverlapStart : I, ITEMS_bOverlapStop : I, ITEMS_bGrabed : I, ITEMS_bUngrabed : I ]mkPlugItems;; fun setPhysicBodyStateGraph(l, state)= if (l == nil) then nil else let hd l -> ref in ( let SO3SceneNodeGetBody ref -> refbody in if (refbody == nil) then nil else ( SO3BodySetIgnoreCollision refbody !state; SO3BodySetVelocity refbody [0.0 0.0 0.0]; SO3BodySetOmega refbody [0.0 0.0 0.0]; SO3BodySetFreeze refbody !state; SO3BodySetSimulation refbody state; ); setPhysicBodyStateGraph (SO3ObjectGetChildren ref) state; setPhysicBodyStateGraph (tl l) state; ); 0;; fun deleteOb(inst, obstr)= //let c3dXsession -> sessionstr in while (obstr.ITEMS_lItems != nil) do ( let hd obstr.ITEMS_lItems -> [name [obj _ _ _]] in ( //V3DshowObjectHelper sessionstr.V3D_sessionView sessionstr obj 16 0; SO3ObjectDestroy obj; ); set obstr.ITEMS_lItems = tl obstr.ITEMS_lItems; ); set obstr.ITEMS_iIndex = 0; setPluginInstanceCbScenePostRender inst nil; setPluginInstanceCbInputClick inst nil; SO3ObjectSetVisible obstr.ITEMS_ref 1 1; setPhysicBodyStateGraph obstr.ITEMS_ref::nil 1; 0;; fun fRandomValue()= (itof (mod rand 4096)) /. 4096.0;; fun randomCircleVec(origin, radius)= let origin -> [ox oy oz] in let 2.0 *. PIf *. fRandomValue -> t in let fRandomValue +. fRandomValue -> u in let (if u >. 1.0 then 2.0 -. u else u) *. radius -> r in let [(r *. cos t) (r *. sin t)] -> [x y] in let origin -> [ox oy oz] in [ox +. x oy oz +. y];; fun crbt(x)= if (x >=. 0.0) then pow x 1.0 /. 3.0 else -.pow (-.x) 1.0 /. 3.0;; fun randomSphereVec(radius, mvec)= let mvec -> [mx my mz] in let fRandomValue -> u in let fRandomValue -> v in let u *. 2.0 *. PIf -> theta in let acos (2.0 *. v -. 1.0) -> phi in let crbt fRandomValue *. radius -> r in let sin theta -> sinTheta in let cos theta -> cosTheta in let sin phi -> sinPhi in let cos phi -> cosPhi in let r *. sinPhi *. cosTheta -> x in let r *. sinPhi *. sinTheta -> y in let r *. cosPhi -> z in [x *. mx y *. my z *. mz];; fun randomVec(x1, y1, z1, x2, y2, z2)= let rand -> xr in let rand -> yr in let rand -> zr in let absf if (x2 >. x1) then (x1 -. x2) else (x2 -. x1) -> mx in let if (mx >. 100.0) then 10.0 else if (mx >. 10.0) then 100.0 else 1000.0 -> div in let x1 +. (absf ((itof (mod xr (ftoi (mx *. div)) + 1)) /. div)) -> x in let absf if (y2 >. y1) then (y1 -. y2) else (y2 -. y1) -> my in let if (my >. 100.0) then 10.0 else if (my >. 10.0) then 100.0 else 1000.0 -> div in let y1 +. (absf ((itof (mod yr (ftoi (my *. div)) + 1)) /. div)) -> y in let absf if (z2 >. z1) then (z1 -. z2) else (z2 -. z1) -> mz in let if (mz >. 100.0) then 10.0 else if (mz >. 10.0) then 100.0 else 1000.0 -> div in let z1 +. (absf ((itof (mod zr (ftoi (mz *. div)) + 1)) /. div)) -> z in [x y z];; fun getRandomPR(obstr, origin)= let obstr.ITEMS_fRandomSize *. 0.5 -> halfsize in let 180.0 -> angle in let if (obstr.ITEMS_iRandomVecType == 0) then // cube randomVec (-.halfsize) (-.halfsize) (-.halfsize) halfsize halfsize halfsize else if (obstr.ITEMS_iRandomVecType == 1) then // square XZ randomVec (-.halfsize) 0.0 (-.halfsize) halfsize 0.0 halfsize else if (obstr.ITEMS_iRandomVecType == 2) then // square ZY randomVec 0.0 (-.halfsize) (-.halfsize) 0.0 halfsize halfsize else if (obstr.ITEMS_iRandomVecType == 3) then // square XY randomVec (-.halfsize) (-.halfsize) 0.0 halfsize halfsize 0.0 else if (obstr.ITEMS_iRandomVecType == 4) then // sphere randomSphereVec halfsize [1.0 1.0 1.0] else if (obstr.ITEMS_iRandomVecType == 5) then // circle XZ randomSphereVec halfsize [1.0 0.0 1.0] else if (obstr.ITEMS_iRandomVecType == 6) then // circle ZY randomSphereVec halfsize [0.0 1.0 1.0] else //if (obstr.ITEMS_iRandomVecType == 7) then // circle XY randomSphereVec halfsize [1.0 1.0 0.0] -> [x y z] in let if (obstr.ITEMS_iRandomAngType == 0) then //Origin [0.0 0.0 0.0] else if (obstr.ITEMS_iRandomAngType == 1) then // XYZ randomVec (-.angle) (-.angle) (-.angle) angle angle angle else if (obstr.ITEMS_iRandomAngType == 2) then // X randomVec (-.angle) 0.0 0.0 angle 0.0 0.0 else if (obstr.ITEMS_iRandomAngType == 3) then // Y randomVec 0.0 (-.angle) 0.0 0.0 angle 0.0 else if (obstr.ITEMS_iRandomAngType == 4) then // Z randomVec 0.0 0.0 (-.angle) 0.0 0.0 angle else if (obstr.ITEMS_iRandomAngType == 5) then // XZ randomVec (-.angle) 0.0 (-.angle) angle 0.0 angle else if (obstr.ITEMS_iRandomAngType == 6) then // ZY randomVec 0.0 (-.angle) (-.angle) 0.0 angle angle else //if (obstr.ITEMS_iRandomAngType == 7) then // XY randomVec (-.angle) (-.angle) 0.0 angle angle 0.0 -> [ax ay az] in let SO3MathsEulerYXZToQuat [SO3MathsDegreeToRadian ax SO3MathsDegreeToRadian ay SO3MathsDegreeToRadian az] -> quat in let origin -> [ox oy oz] in [[ox +. x oy +. y oz +. z] quat];; fun clonePhysicBody(ref, obj)= let SO3SceneNodeGetBody ref -> refbody in if (refbody == nil) then nil else ( let SO3BodyGetShapeDefinition refbody -> [btype tolerance [radius height] size offset offsetquat] in let if (btype == SO3_TYPE_BODY_TREE) then SO3BodyCreateCollisionTree obj 1 else if (btype == SO3_TYPE_BODY_ELLIPSOID) then SO3BodyCreateEllipsoidExt obj size offset offsetquat else if (btype == SO3_TYPE_BODY_BOX) then SO3BodyCreateBoxExt obj size offset offsetquat else if (btype == SO3_TYPE_BODY_SHAPE) then SO3BodyCreateShape obj tolerance else if (btype == SO3_TYPE_BODY_CONCAVE) then SO3BodyCreateConcaveShape obj tolerance else if (btype == SO3_TYPE_BODY_CYLINDER) then SO3BodyCreateCylinderExt obj radius height offset offsetquat else if (btype == SO3_TYPE_BODY_CHAMFERCYLINDRE) then SO3BodyCreateChamferCylinderExt obj radius height offset offsetquat else if (btype == SO3_TYPE_BODY_CAPSULE) then SO3BodyCreateCapsuleExt obj radius height offset offsetquat else if (btype == SO3_TYPE_BODY_CONE) then SO3BodyCreateConeExt obj radius height offset offsetquat else if (btype == SO3_TYPE_BODY_PYRAMID) then SO3BodyCreatePyramidExt obj size offset offsetquat else nil -> body in if body == nil then nil else ( SO3BodySetType body (SO3BodyGetType refbody); SO3BodySetMaterial body (SO3BodyGetMaterial refbody); let SO3BodyGetMassMatrix refbody -> [m mx] in SO3BodySetMassMatrix body m mx; SO3BodySetGravityEnable body SO3BodyGetGravityEnable refbody; SO3BodySetIgnoreCollision body SO3BodyGetIgnoreCollision refbody; SO3BodySetContiniousCollisionMode body (SO3BodyGetContiniousCollisionMode refbody); SO3BodySetAutoSleep body (SO3BodyGetAutoSleep refbody); SO3BodySetCenterOfMass body (SO3BodyGetCenterOfMass refbody); SO3BodySetFluid body (SO3BodyGetFluid refbody); SO3BodySetFluidVolumeRatio body SO3BodyGetFluidVolumeRatio refbody; SO3BodySetLinearDamping body (SO3BodyGetLinearDamping refbody); SO3BodySetAngularDamping body (SO3BodyGetAngularDamping refbody); SO3BodySetFreeze body (SO3BodyGetFreeze refbody); ); ); 0;; fun cloneNodeHierarchy(obstr, l, parent)= if (l == nil) then nil else let hd l -> ref in ( let strcatn (SO3ObjectGetName ref)::"_item_"::obstr.ITEMS_instName::"_"::(itoa obstr.ITEMS_iIndex)::nil -> name in let if ((SO3ObjectGetType ref) == SO3_TYPE_ENTITY) then SO3SceneCloneEntity (V3DgetSession c3dXsession) name ref else SO3SceneNodeCreate (V3DgetSession c3dXsession) name -> obj in ( SO3ObjectSetPosition obj SO3ObjectGetPosition ref; SO3ObjectSetOrientation obj SO3ObjectGetOrientation ref; SO3ObjectSetScale obj SO3ObjectGetScale ref; SO3ObjectLink obj parent; SO3ObjectSetFlags obj (SO3ObjectGetFlags obj)|2048; //Physics clonePhysicBody ref obj; //Anims let SO3ObjectGetAnimations ref -> lanim in while (lanim != nil) do ( let hd lanim -> anim in if (!SO3AnimationGetEnable anim) then nil else ( let SO3AnimationGetLoop anim -> loop in let SO3AnimationGetWeight anim -> weight in let SO3ObjectGetAnimation obj SO3AnimationGetName anim -> nanim in ( SO3AnimationSetLoop nanim loop; SO3AnimationSetWeight nanim weight; SO3AnimationSetEnable nanim 1; ); ); set lanim = tl lanim; ); cloneNodeHierarchy obstr (SO3ObjectGetChildren ref) obj; cloneNodeHierarchy obstr (tl l) parent; obj; ); );; fun cloneNode(obstr)= cloneNodeHierarchy obstr obstr.ITEMS_ref::nil (SO3ObjectGetParent obstr.ITEMS_ref);; fun addRandomItems(obstr, cnt, origin, scale, parent)= let 0 -> i in while (i < cnt) do ( let getRandomPR obstr origin -> [rvec quat] in let cloneNode obstr -> obj in ( SO3ObjectSetPosition obj rvec; SO3ObjectSetOrientation obj quat; if (scale == nil) then nil else SO3ObjectSetScale obj scale; if (parent == nil) then nil else SO3ObjectLink obj parent; SO3ObjectSetVisible obj !obstr.ITEMS_bHide 1; setPhysicBodyStateGraph obj::nil !obstr.ITEMS_bHide; set obstr.ITEMS_lItems = [(SO3ObjectGetName obj) [obj rvec quat (SO3ObjectGetScale obj)]]::obstr.ITEMS_lItems; set obstr.ITEMS_iIndex = obstr.ITEMS_iIndex + 1; if (!obstr.ITEMS_bItemEvent) then nil else SendPluginEvent obstr.ITEMS_inst "Item loaded" (SO3ObjectGetName obj) nil; set i = i + 1; ); ); 0;; fun addItem(inst, from, action, param, rep, obstr)= if (obstr.ITEMS_ref == nil) then nil else let strextr param -> lp in let if (atof (nth_list (hd lp) 0)) == nil then 0.0 else (atof (nth_list (hd lp) 0)) -> px in let if (atof (nth_list (hd lp) 1)) == nil then 0.0 else (atof (nth_list (hd lp) 1)) -> py in let if (atof (nth_list (hd lp) 2)) == nil then 0.0 else (atof (nth_list (hd lp) 2)) -> pz in let if (atof (nth_list (hd tl lp) 0)) == nil then 0.0 else (atof (nth_list (hd tl lp) 0)) -> ax in let if (atof (nth_list (hd tl lp) 1)) == nil then 0.0 else (atof (nth_list (hd tl lp) 1)) -> ay in let if (atof (nth_list (hd tl lp) 2)) == nil then 0.0 else (atof (nth_list (hd tl lp) 2)) -> az in let if (atof (nth_list (hd tl tl lp) 0)) == nil then 1.0 else (atof (nth_list (hd tl tl lp) 0)) -> sx in let if (atof (nth_list (hd tl tl lp) 1)) == nil then 1.0 else (atof (nth_list (hd tl tl lp) 1)) -> sy in let if (atof (nth_list (hd tl tl lp) 2)) == nil then 1.0 else (atof (nth_list (hd tl tl lp) 2)) -> sz in let SO3MathsEulerYXZToQuat [(SO3MathsDegreeToRadian ax) (SO3MathsDegreeToRadian ay) (SO3MathsDegreeToRadian az)] -> quat in let if (atoi (nth_list (hd tl tl tl lp) 0)) == nil then 1 else (atoi (nth_list (hd tl tl tl lp) 0)) -> nb in if (nb > 1) then ( addRandomItems obstr nb [px py pz] [sx sy sz] nil; 0; ) else let cloneNode obstr -> obj in ( SO3ObjectSetPosition obj [px py pz]; SO3ObjectSetOrientation obj quat; SO3ObjectSetScale obj [sx sy sz]; SO3ObjectSetVisible obj !obstr.ITEMS_bHide 1; setPhysicBodyStateGraph obj::nil !obstr.ITEMS_bHide; set obstr.ITEMS_lItems = [(SO3ObjectGetName obj) [obj [px py pz] quat [sx sy sz]]]::obstr.ITEMS_lItems; set obstr.ITEMS_iIndex = obstr.ITEMS_iIndex + 1; if (!obstr.ITEMS_bItemEvent) then nil else SendPluginEvent inst "Item loaded" (SO3ObjectGetName obj) nil; 0; ); 0;; fun cbInputClick(inst, viewstr, id, x, y, btn, pdata, obstr)= let pdata -> [obj mat _ [dx dy dz] _ _] in if ((strfind obstr.ITEMS_instName (SO3ObjectGetName obj) 0) == nil) then nil else ( while ((strfind obstr.ITEMS_instName (SO3ObjectGetName SO3ObjectGetParent obj) 0) != nil) do ( set obj = SO3ObjectGetParent obj; ); SO3ObjectSetVisible obj 0 1; setPhysicBodyStateGraph obj::nil 0; SendPluginEvent inst "Collected" (SO3ObjectGetName obj) nil; ); 0;; fun cbItemsPostRender(inst, sessionstr, etime, obstr)= let if (obstr.ITEMS_iCollectType != 1) then nil else if (obstr.ITEMS_iPlayerType != 0) then let V3DgetDefaultCamera c3dXsession -> curcamera in V3DgetCameraByType c3dXsession curcamera obstr.ITEMS_iPlayerType else obstr.ITEMS_player -> player in let _tickcount -> curtick in let if (obstr.ITEMS_iEffectType < 8) then nil else if (obstr.ITEMS_iTickUpdate == nil || (curtick - obstr.ITEMS_iTickUpdate) >= (1000 / 60)) then ( let 2000.0 /. obstr.ITEMS_fEffectSpeed -> period in let 0.5 -> amplitude in let 1.0 -> offset in let (itof (mod curtick ftoi(period))) /. period -> periodratio in let sin ((2.0 *. PIf) *. periodratio) -> value in ( set obstr.ITEMS_iTickUpdate = curtick; (value *. amplitude) +. offset; ); ) else nil -> sinuzoid in let obstr.ITEMS_lItems -> l in let c3dXsession -> sessionstr in while (l != nil) do ( let hd l -> [name [obj objvec objquat objs]] in if (!SO3ObjectGetVisible obj) then nil else ( if (player == nil) then nil else ( let SO3ObjectGetWorldBoundingBoxInfo obj 1 -> [[bsx bsy bsz] [cx cy cz] bquat] in let SO3ObjectGetBoundingBoxInfo player 1 -> [psize _ _] in let if (psize == nil) || ((SO3ObjectGetType player) == SO3_TYPE_CAMERA) || ((vectorAverageF psize) >. 10.0) then [0.20 0.20 0.20] else psize -> [psx psy psz] in let (maxf maxf psx psy psz) *. 0.5 -> pradius in let if pradius == 0.0 then 0.1 else pradius -> pradius in let pradius +. (maxf maxf bsx bsy bsz) -> radius in let SO3ObjectGetGlobalPosition player -> [ox oy oz] in let SO3ObjectGetGlobalPosition obj -> [cx cy cz] in let sqrt ((sqr(cx -. ox)) +. (sqr(cy -. oy)) +. (sqr(cz -. oz))) -> cdist in //let ( // V3DshowObjectHelper sessionstr.V3D_sessionView sessionstr obj 16 1; // let (switch sessionstr.V3D_lHelper obj) -> hp in // set hp.V3D_fHelperRadius = radius; // 0 // ) -> _ in if (cdist <. radius) then ( SO3ObjectSetVisible obj 0 1; setPhysicBodyStateGraph obj::nil 0; SendPluginEvent inst "Collected" name nil; 0; ); ); if (obstr.ITEMS_iEffectType == 0) then nil else ( if (obstr.ITEMS_iEffectType < 8) then ( let if (obstr.ITEMS_iEffectType == 1) then // XYZ [0.01 0.01 0.01] else if (obstr.ITEMS_iEffectType == 2) then // X [0.01 0.0 0.0] else if (obstr.ITEMS_iEffectType == 3) then // Y [0.0 0.01 0.0] else if (obstr.ITEMS_iEffectType == 4) then // Z [0.0 0.0 0.01] else if (obstr.ITEMS_iEffectType == 5) then // XZ [0.01 0.0 0.01] else if (obstr.ITEMS_iEffectType == 5) then // ZY [0.0 0.01 0.01] else // if (obstr.ITEMS_iEffectType == 6) then // XY [0.01 0.01 0.0] -> [pitch yaw roll] in let (itof etime) /. 1000000.0 -> ftime in let ftime *. 90.0 *. obstr.ITEMS_fEffectSpeed -> nbframe in ( SO3ObjectRotateYaw obj (yaw *. nbframe) SO3_LOCAL_TS; SO3ObjectRotatePitch obj (pitch *. nbframe) SO3_LOCAL_TS; SO3ObjectRotateRoll obj (roll *. nbframe) SO3_LOCAL_TS; ); ) else if (sinuzoid == nil) then nil else ( let objs -> [ox oy oz] in let if (obstr.ITEMS_iEffectType == 8) then // XYZ [ox *. sinuzoid oy *. sinuzoid oz *. sinuzoid] else if (obstr.ITEMS_iEffectType == 9) then // X [ox *. sinuzoid oy oz] else if (obstr.ITEMS_iEffectType == 10) then // Y [ox oy *. sinuzoid oz] else if (obstr.ITEMS_iEffectType == 11) then // Z [ox oy oz *. sinuzoid] else if (obstr.ITEMS_iEffectType == 12) then // XZ [ox *. sinuzoid oy oz *. sinuzoid] else if (obstr.ITEMS_iEffectType == 13) then // ZY [ox oy *. sinuzoid oz *. sinuzoid] else // if (obstr.ITEMS_iEffectType == 14) then // XY [ox *. sinuzoid oy *. sinuzoid oz] -> scvec in SO3ObjectSetScale obj scvec; ); ); ); set l = tl l; ); 0;; fun removeLastItem(inst, from, action, param, rep, obstr)= let if ((atoi param) != nil) then atoi param else 0 -> pos in if (pos == 0) then ( let hd obstr.ITEMS_lItems -> [_ [obj _ _ _]] in SO3ObjectDestroy obj; set obstr.ITEMS_lItems = tl obstr.ITEMS_lItems; ) else ( let nth_list obstr.ITEMS_lItems pos -> [_ [obj _ _ _]] in SO3ObjectDestroy obj; set obstr.ITEMS_lItems = remove_nth_from_list obstr.ITEMS_lItems pos; ); 0;; fun unloadItems(inst, from, action, param, rep, obstr)= deleteOb inst obstr; set obstr.ITEMS_bLoaded = 0; SendPluginEvent inst "Unloaded" nil nil; 0;; fun setItemsVisibility(obstr, state)= let obstr.ITEMS_lItems -> l in while (l != nil) do ( let hd l -> [_ [obj _ _ _]] in ( SO3ObjectSetVisible obj state 1; setPhysicBodyStateGraph obj::nil state; ); set l = tl l; ); 0;; fun hideAllItems(inst, from, action, param, rep, obstr)= setItemsVisibility obstr 0; set obstr.ITEMS_bHide = 1; setPluginInstanceCbScenePostRender inst nil; setPluginInstanceCbInputClick inst nil; 0;; fun removeAllItems(inst, from, action, param, rep, obstr)= while (obstr.ITEMS_lItems != nil) do ( let hd obstr.ITEMS_lItems -> [name [obj _ _ _]] in ( SO3ObjectDestroy obj; set obstr.ITEMS_lItems = tl obstr.ITEMS_lItems; ); ); set obstr.ITEMS_lItems = nil; set obstr.ITEMS_iIndex = 0; 0;; fun showAllItems(inst, from, action, param, rep, obstr)= setItemsVisibility obstr 1; set obstr.ITEMS_bHide = 0; //if effect none && !distance nil if (obstr.ITEMS_iEffectType == 0 && obstr.ITEMS_iCollectType != 1) then nil else setPluginInstanceCbScenePostRender inst mkfun4 @cbItemsPostRender obstr; if (obstr.ITEMS_iCollectType != 2) then nil else setPluginInstanceCbInputClick inst mkfun8 @cbInputClick obstr; 0;; fun loadChildren(parent, obstr)= let SO3ObjectGetChildren parent -> lchild in while (lchild != nil) do ( let hd lchild -> child in ( if ((SO3ObjectGetFlags child) & 2048) then nil else ( loadChildren child obstr; if (obstr.ITEMS_iRandomCnt > 1) then ( addRandomItems obstr obstr.ITEMS_iRandomCnt [0.0 0.0 0.0] nil child; 0; ) else ( let cloneNode obstr -> obj in ( SO3ObjectLink obj child; //override position SO3ObjectSetPosition obj [0.0 0.0 0.0]; SO3ObjectSetVisible obj !obstr.ITEMS_bHide 1; setPhysicBodyStateGraph obj::nil !obstr.ITEMS_bHide; set obstr.ITEMS_lItems = [(SO3ObjectGetName obj) [obj [0.0 0.0 0.0] [0.0 0.0 0.0 1.0] [1.0 1.0 1.0]]]::obstr.ITEMS_lItems; set obstr.ITEMS_iIndex = obstr.ITEMS_iIndex + 1; if (!obstr.ITEMS_bItemEvent) then nil else SendPluginEvent obstr.ITEMS_inst "Item loaded" (SO3ObjectGetName obj) nil; ); ); ); ); set lchild = tl lchild; ); 0;; fun loadItems(inst, from, action, param, rep, obstr)= if ((obstr.ITEMS_ref == nil) || (obstr.ITEMS_bLoaded)) then nil else ( if (obstr.ITEMS_bSons && (obstr.ITEMS_parent != nil)) then ( loadChildren obstr.ITEMS_parent obstr; 0; ) else if (obstr.ITEMS_iRandomCnt > 1) then ( addRandomItems obstr obstr.ITEMS_iRandomCnt [0.0 0.0 0.0] nil obstr.ITEMS_parent; 0; ) else ( let cloneNode obstr -> obj in ( //override position SO3ObjectSetPosition obj [0.0 0.0 0.0]; SO3ObjectSetVisible obj !obstr.ITEMS_bHide 1; setPhysicBodyStateGraph obj::nil !obstr.ITEMS_bHide; if (obstr.ITEMS_parent == nil) then nil else SO3ObjectLink obj obstr.ITEMS_parent; set obstr.ITEMS_lItems = [(SO3ObjectGetName obj) [obj [0.0 0.0 0.0] [0.0 0.0 0.0 1.0] [1.0 1.0 1.0]]]::obstr.ITEMS_lItems; set obstr.ITEMS_iIndex = obstr.ITEMS_iIndex + 1; if (!obstr.ITEMS_bItemEvent) then nil else SendPluginEvent inst "Item loaded" (SO3ObjectGetName obj) nil; ); 0; ); set obstr.ITEMS_bLoaded = 1; //if effect none && !distance nil if (obstr.ITEMS_bHide) then nil else ( if (obstr.ITEMS_iEffectType == 0 && obstr.ITEMS_iCollectType != 1) then nil else setPluginInstanceCbScenePostRender inst mkfun4 @cbItemsPostRender obstr; if (obstr.ITEMS_iCollectType != 2) then nil else setPluginInstanceCbInputClick inst mkfun8 @cbInputClick obstr; ); SendPluginEvent inst "Loaded" nil nil; ); 0;; fun applyOnItems(inst, from, action, param, rep, obstr)= let obstr.ITEMS_lItems -> l in while (l != nil) do ( let hd l -> [name [obj _ _ _]] in SendPluginEvent inst "Apply on item" name nil; set l = tl l; ); 0;; fun collectItem(inst, from, action, param, rep, obstr)= let hd hd strextr param -> name in let switchstr obstr.ITEMS_lItems name -> [obj vec quat scale] in if (obj == nil) then nil else ( SO3ObjectSetVisible obj 0 1; setPhysicBodyStateGraph obj::nil 0; SendPluginEvent inst "Collected" name nil; ); 0;; fun resetItem(inst, from, action, param, rep, obstr)= let hd hd strextr param -> name in let switchstr obstr.ITEMS_lItems name -> [obj vec quat scale] in if (obj == nil) then nil else ( SO3ObjectSetPosition obj vec; SO3ObjectSetOrientation obj quat; SO3ObjectSetScale obj scale; SO3ObjectSetVisible obj !obstr.ITEMS_bHide 1; setPhysicBodyStateGraph obj::nil !obstr.ITEMS_bHide; ); 0;; fun setItemPosition(inst, from, action, param, rep, obstr)= let strextr param -> lp in let hd hd lp -> name in let hd tl lp -> p in let if (atof (nth_list p 0)) == nil then 0.0 else (atof (nth_list p 0)) -> px in let if (atof (nth_list p 1)) == nil then 0.0 else (atof (nth_list p 1)) -> py in let if (atof (nth_list p 2)) == nil then 0.0 else (atof (nth_list p 2)) -> pz in let switchstr obstr.ITEMS_lItems name -> [obj vec quat scale] in ( SO3ObjectSetGlobalPosition obj [px py pz]; SO3ObjectSetVisible obj !obstr.ITEMS_bHide 1; setPhysicBodyStateGraph obj::nil !obstr.ITEMS_bHide; ); 0;; fun cbGeneric(inst, type, value, param, obstr)= let switchstr obstr.ITEMS_lItems value -> [obj _ _ _] in if (obj == nil) then nil else ( if (type == 16) then if (!obstr.ITEMS_bRayIn) then nil else SendPluginEvent obstr.ITEMS_inst "Ray intersect in" strcat strcat value " " param nil else if (type == 17) then if (!obstr.ITEMS_bRayOut) then nil else SendPluginEvent obstr.ITEMS_inst "Ray intersect out" strcat strcat value " " param nil else if (type == 18) then if (!obstr.ITEMS_bContact) then nil else SendPluginEvent obstr.ITEMS_inst "Contact" strcat strcat value " " param nil else if (type == 19) then if (!obstr.ITEMS_bOverlapStart) then nil else SendPluginEvent obstr.ITEMS_inst "Overlap started" strcat strcat value " " param nil else if (type == 20) then if (!obstr.ITEMS_bOverlapStop) then nil else SendPluginEvent obstr.ITEMS_inst "Overlap stopped" strcat strcat value " " param nil else if (type == 21) then if (!obstr.ITEMS_bGrabed) then nil else SendPluginEvent obstr.ITEMS_inst "Grabed" strcat strcat value " " param nil else if (type == 22) then if (!obstr.ITEMS_bUngrabed) then nil else SendPluginEvent obstr.ITEMS_inst "Ungrabed" strcat strcat value " " param nil else nil; ); 0;; fun cbLoaded(inst, obstr)= loadItems inst nil nil nil nil obstr; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "ref") -> refname in let (getPluginInstanceParam inst "object") -> objname in let atoi (getPluginInstanceParam inst "sons") -> sons in let if sons == nil then 0 else sons -> sons in let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 0 else init -> init in let atoi (getPluginInstanceParam inst "hide") -> hide in let if hide == nil then 0 else hide -> hide in let atoi (getPluginInstanceParam inst "randomcnt") -> randomcnt in let if randomcnt == nil then 1 else randomcnt -> randomcnt in let atof (getPluginInstanceParam inst "randomsize") -> randomsize in let if randomsize == nil then 5.0 else randomsize -> randomsize in let atoi (getPluginInstanceParam inst "randomvectype") -> randomvectype in let if randomvectype == nil then 0 else randomvectype -> randomvectype in let atoi (getPluginInstanceParam inst "randomangtype") -> randomangtype in let if randomangtype == nil then 0 else randomangtype -> randomangtype in let atoi (getPluginInstanceParam inst "effectmode") -> effectmode in let if effectmode == nil then 0 else effectmode -> effectmode in let atof (getPluginInstanceParam inst "effectspeed") -> effectspeed in let if effectspeed == nil then 1.0 else effectspeed -> effectspeed in let atoi (getPluginInstanceParam inst "collectmode") -> collectmode in let if collectmode == nil then 0 else collectmode -> collectmode in let (getPluginInstanceParam inst "player") -> pobjname in let V3DgetObjectByName c3dXsession refname -> refobj in let V3DgetObjectByName c3dXsession objname -> parent in let V3DgetObjectByName c3dXsession pobjname -> playerobj in let V3DgetObjectTypeByName pobjname -> playermode in let (IsInEditor inst) || IsEventLinked inst "Item loaded" -> itemevent in let (IsInEditor inst) || IsEventLinked inst "Contact" -> bContact in let (IsInEditor inst) || IsEventLinked inst "Ray intersect in" -> bRayIn in let (IsInEditor inst) || IsEventLinked inst "Ray intersect out" -> bRayOut in let (IsInEditor inst) || IsEventLinked inst "Overlap started" -> bOverlapStart in let (IsInEditor inst) || IsEventLinked inst "Overlap stopped" -> bOverlapStop in let (IsInEditor inst) || IsEventLinked inst "Grabed" -> bGrabed in let (IsInEditor inst) || IsEventLinked inst "Ungrabed" -> bUngrabed in let mkPlugItems [inst (getShortName getPluginInstanceFullname inst) refobj parent sons playerobj playermode 0 nil 0 hide randomcnt randomsize randomvectype randomangtype collectmode effectmode effectspeed nil itemevent bContact bRayIn bRayOut bOverlapStart bOverlapStop bGrabed bUngrabed] -> obstr in ( //disable ref obj SO3ObjectSetVisible obstr.ITEMS_ref 0 1; setPhysicBodyStateGraph obstr.ITEMS_ref::nil 0; PluginRegisterAction inst "Add item" mkfun6 @addItem obstr; PluginRegisterAction inst "Remove last item" mkfun6 @removeLastItem obstr; PluginRegisterAction inst "Hide all items" mkfun6 @hideAllItems obstr; PluginRegisterAction inst "Show all items" mkfun6 @showAllItems obstr; PluginRegisterAction inst "Load" mkfun6 @loadItems obstr; PluginRegisterAction inst "Unload" mkfun6 @unloadItems obstr; PluginRegisterAction inst "Apply on items list" mkfun6 @applyOnItems obstr; PluginRegisterAction inst "Collect item" mkfun6 @collectItem obstr; PluginRegisterAction inst "Reset item" mkfun6 @resetItem obstr; PluginRegisterAction inst "Set item position" mkfun6 @setItemPosition obstr; PluginRegisterAction inst "Remove all items" mkfun6 @removeAllItems obstr; setPluginInstanceCbGeneric inst mkfun5 @cbGeneric obstr; if (!init) then nil else ( if inst.INST_groupstr.GRP_project.PRJ_bPluginsLoaded then ( loadItems inst nil nil nil nil obstr; 0; ) else ( setPluginInstanceCbAllPluginsLoaded inst mkfun2 @cbLoaded obstr; 0; ); ); //let c3dXsession -> sessionstr in // V3DenableHelpers (V3DgetDefaultViewport sessionstr.V3D_sessionView) sessionstr 1; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= srand time; PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;