/* ----------------------------------------------------------------------------- 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 LvGenPlug = [ LVG_instance : PInstance, LVG_shell : SO3_OBJECT, LVG_sGroupName : S, LVG_sMeshPath : S, LVG_sMatPath : S, LVG_sGenBitmap : S, LVG_iNbLoaded : I ]mkLvGenPlug;; // delete all instance resources fun deleteOb(inst, obstr)= SO3ObjectDestroy obstr.LVG_shell; // delete material and texture //SO3MaterialDestroy obstr.LVG_material; //SO3TextureDestroy obstr.LVG_texture; SO3GroupDelete (V3DgetSession c3dXsession) obstr.LVG_sGroupName; 0;; fun cbCubeLoaded(cube, p)= let p -> [obstr bmp24 bmp8 iw ih w h lv] in ( //let _GETpixel24 bmp24 iw ih -> color in let SO3ObjectGetBoundingBoxInfo cube 0 -> [[tx ty tz] [px py pz] _] in let [px +. 0.04 py +. 0.04 pz +. 0.04] -> [px py pz] in let (itof lv) +. 1.0 -> flv in let [((tx -. px) *. (itof iw)) (ty *. flv) ((tz -. pz) *. (itof ih))] -> [nx ny nz] in let [(nx -. ((itof w) /. 2.0 *. tx)) 0.0 (nz -. ((itof h) /. 2.0 *. tz))] -> pos in ( SO3ObjectSetPosition cube pos; SO3ObjectSetScale cube [1.0 ny 1.0]; set obstr.LVG_iNbLoaded = obstr.LVG_iNbLoaded + 1; SO3BodySetType (SO3BodyCreateCollisionTree cube 1) 4; if (obstr.LVG_iNbLoaded != (w * h)) then nil else ( SO3ObjectSetAsStaticGeometry obstr.LVG_shell 1; //SO3BodySetType (SO3BodyCreateCollisionTree obstr.LVG_shell 1) 4; SendPluginEvent obstr.LVG_instance "Loaded" nil nil; ); ); ); 0;; fun loadLevel(bmp24, bmp8, obstr)= SendPluginEvent obstr.LVG_instance "Generating" nil nil; let _GETbitmapSize bmp24 -> [w h] in let 0 -> ih in while (ih < h) do ( let 0 -> iw in while (iw < w) do ( let (_GETpixel8 bmp8 iw ih) &255 -> lv in let strcatn (itoa iw)::"_"::(itoa ih)::"_"::(itoa lv)::nil -> id in let SO3SceneLoadEntityInBackground (V3DgetSession c3dXsession) obstr.LVG_sGroupName (strcatn id::"_lv_mesh_"::(getPluginInstanceName obstr.LVG_instance)::nil) (_checkpack obstr.LVG_sMeshPath) @cbCubeLoaded [obstr bmp24 bmp8 iw ih w h lv] -> ent in SO3ObjectLink ent obstr.LVG_shell; set iw = iw + 1; ); set ih = ih + 1; ); 0;; fun cbLoadLevel(inst, from, action, param, rep, obstr)= if (obstr.LVG_shell != nil) then nil else ( let G2DloadAlphaBmp _channel obstr.LVG_sGenBitmap -> bmp in let V3DaddShell c3dXsession strcatn "lv_shell_"::(getPluginInstanceName inst)::nil nil nil [0.0 0.0 0.0] nil -> shell in ( set obstr.LVG_shell = shell; if (bmp == nil) then nil else let _GETalphaBitmaps bmp -> [bmp24 bmp8] in ( loadLevel bmp24 bmp8 obstr; _DSalphaBitmap bmp; ); ); ); 0;; fun cbUnloadLevel(inst, from, action, param, rep, obstr)= SO3ObjectDestroy obstr.LVG_shell; set obstr.LVG_shell = nil; set obstr.LVG_iNbLoaded = 0; 0;; fun newOb(inst)= let strcat (getPluginInstanceName inst) "_Group" -> grpname in let strcatn (getPluginDirectory (getInstancePlugin inst))::"/res/"::"cube.mesh"::nil -> meshpath in let strcatn (getPluginDirectory (getInstancePlugin inst))::"/res/"::"cube.material"::nil -> matpath in let strcatn (getPluginDirectory (getInstancePlugin inst))::"/res/"::"level.png"::nil -> bmppath in let mkLvGenPlug [inst nil grpname meshpath matpath bmppath 0] -> obstr in ( SO3GroupCreate (V3DgetSession c3dXsession) grpname; V3DaddResource c3dXsession matpath grpname SO3_RESOURCE_MATERIAL; V3DaddResource c3dXsession meshpath grpname SO3_RESOURCE_MESH; PluginRegisterAction inst "Load" mkfun6 @cbLoadLevel obstr; PluginRegisterAction inst "Unload" mkfun6 @cbUnloadLevel obstr; //TODO on init option cbLoadLevel inst nil nil nil nil obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;