00001 #include "lugre_prefix.h"
00002 #include "lugre_gfx3D.h"
00003 #include "lugre_camera.h"
00004 #include "lugre_scripting.h"
00005 #include "lugre_game.h"
00006 #include "lugre_ogrewrapper.h"
00007 #include "lugre_input.h"
00008 #include "lugre_robrenderable.h"
00009 #include "lugre_robstring.h"
00010 #include "lugre_luabind.h"
00011 #include "lugre_luabind_direct.h"
00012 #include "lugre_luabind_ogrehelper.h"
00013 #include "lugre_gfx2D.h"
00014 #include "lugre_beam.h"
00015 #include "lugre_fastbatch.h"
00016 #include "lugre_meshbuffer.h"
00017 #include <Ogre.h>
00018
00019 extern "C" {
00020 #include "lua.h"
00021 #include "lauxlib.h"
00022 #include "lualib.h"
00023 }
00024
00025 using namespace Ogre;
00026
00027 namespace Lugre {
00028
00029 class cGfx3D_L : public cLuaBind<cGfx3D> { public:
00031 virtual void RegisterMethods (lua_State *L) { PROFILE
00032
00033
00034
00035
00036 lua_register(L,"CreateGfx3D", &cGfx3D_L::CreateGfx3D);
00037 lua_register(L,"CreateRootGfx3D", &cGfx3D_L::CreateRootGfx3D);
00038 lua_register(L,"CreateCamPosGfx3D", &cGfx3D_L::CreateCamPosGfx3D);
00039 lua_register(L,"CreateCockpitGfx3D", &cGfx3D_L::CreateCockpitGfx3D);
00040 lua_register(L,"GetGfx3DCount", &cGfx3D_L::GetGfx3DCount);
00041
00042
00043 LUABIND_QUICKWRAP( GetEntity, { return cLuaBindDirectOgreHelper::PushEntity(L, checkudata_alive(L)->mpEntity ); });
00044 LUABIND_QUICKWRAP( GetSceneNode, { return cLuaBindDirectOgreHelper::PushSceneNode(L, checkudata_alive(L)->mpSceneNode ); });
00045 LUABIND_QUICKWRAP( GetSimpleRenderable, { return cLuaBindDirectOgreHelper::PushRenderable(L, checkudata_alive(L)->mpSimpleRenderable ); });
00046 LUABIND_QUICKWRAP( GetSimpleMovable, { return cLuaBindDirectOgreHelper::PushMovableObject(L, checkudata_alive(L)->mpSimpleRenderable ); });
00047 LUABIND_QUICKWRAP( GetRenderOp, {
00048 cRobSimpleRenderable* pSimple = checkudata_alive(L)->mpSimpleRenderable;
00049 if (pSimple) return cLuaBindDirectOgreHelper::PushRenderOperation(L,pSimple->mpRenderOp);
00050 });
00051
00052
00053
00054
00055 #define REGISTER_METHOD(methodname) mlMethod.push_back(make_luaL_reg(#methodname,&cGfx3D_L::methodname));
00056
00057 REGISTER_METHOD(Destroy);
00058 REGISTER_METHOD(CreateChild);
00059 REGISTER_METHOD(CreateTagPoint);
00060 REGISTER_METHOD(GetWorldAABB);
00061 REGISTER_METHOD(GetEntityBounds);
00062 REGISTER_METHOD(GetEntityBoundRad);
00063 REGISTER_METHOD(GetEntityIndexCount);
00064 REGISTER_METHOD(GetEntityVertex);
00065 REGISTER_METHOD(GetCustomBoundRad);
00066 REGISTER_METHOD(SetCustomBoundRad);
00067 REGISTER_METHOD(RayPick);
00068 REGISTER_METHOD(RayPickList);
00069 REGISTER_METHOD(SetParent);
00070 REGISTER_METHOD(SetRootAsParent);
00071 REGISTER_METHOD(SetRenderingDistance);
00072 REGISTER_METHOD(SetVisible);
00073 REGISTER_METHOD(SetDisplaySkeleton);
00074 REGISTER_METHOD(SetPrepareFrameStep);
00075 REGISTER_METHOD(SetMaterial);
00076 REGISTER_METHOD(GetScale);
00077 REGISTER_METHOD(GetPosition);
00078 REGISTER_METHOD(GetDerivedPosition);
00079 REGISTER_METHOD(GetOrientation);
00080 REGISTER_METHOD(GetDerivedOrientation);
00081 REGISTER_METHOD(SetPosition);
00082 REGISTER_METHOD(SetScale);
00083 REGISTER_METHOD(SetNormaliseNormals);
00084 REGISTER_METHOD(SetOrientation);
00085 REGISTER_METHOD(SetMesh);
00086 REGISTER_METHOD(GetMeshSubEntityCount);
00087 REGISTER_METHOD(GetMeshSubEntityMaterial);
00088 REGISTER_METHOD(SetMeshSubEntityMaterial);
00089 REGISTER_METHOD(SetMeshSubEntityCustomParameter);
00090 REGISTER_METHOD(SetAnim);
00091 REGISTER_METHOD(HasBone);
00092 REGISTER_METHOD(IsAnimLooped);
00093 REGISTER_METHOD(GetPathAnimTimePos);
00094 REGISTER_METHOD(SetPathAnimTimePos);
00095 REGISTER_METHOD(PathAnimAddTime);
00096 REGISTER_METHOD(GetAnimLength);
00097 REGISTER_METHOD(GetAnimTimePos);
00098 REGISTER_METHOD(SetAnimTimePos);
00099 REGISTER_METHOD(AnimAddTime);
00100 REGISTER_METHOD(GetSkeletonName);
00101 REGISTER_METHOD(HasSkeleton);
00102 REGISTER_METHOD(ShareSkeletonInstanceWith);
00103 REGISTER_METHOD(SetStarfield);
00104 REGISTER_METHOD(SetExplosion);
00105 REGISTER_METHOD(SetTargetTracker);
00106 REGISTER_METHOD(SetBillboard);
00107 REGISTER_METHOD(SetTrail);
00108 REGISTER_METHOD(SetRadar);
00109 REGISTER_METHOD(SetRadialGrid);
00110 REGISTER_METHOD(SetWireBoundingBoxGfx3D);
00111 REGISTER_METHOD(SetWireBoundingBoxMinMax);
00112
00113 REGISTER_METHOD(SetSimpleRenderable);
00114 REGISTER_METHOD(RenderableBegin);
00115 REGISTER_METHOD(RenderableVertex);
00116 REGISTER_METHOD(RenderableIndex);
00117 REGISTER_METHOD(RenderableIndex3);
00118 REGISTER_METHOD(RenderableIndex2);
00119 REGISTER_METHOD(RenderableEnd);
00120 REGISTER_METHOD(RenderableConvertToMesh);
00121 REGISTER_METHOD(RenderableAddToMesh);
00122 REGISTER_METHOD(RenderableSkipVertices);
00123 REGISTER_METHOD(RenderableSkipIndices);
00124 REGISTER_METHOD(SetFastBatch);
00125 REGISTER_METHOD(FastBatch_AddMeshBuffer);
00126 REGISTER_METHOD(FastBatch_Build);
00127 REGISTER_METHOD(FastBatch_SetDisplayRange);
00128 REGISTER_METHOD(SetTextFont);
00129 REGISTER_METHOD(SetText);
00130 REGISTER_METHOD(SetCastShadows);
00131
00132 REGISTER_METHOD(SetPath);
00133
00134 REGISTER_METHOD(CreateMergedMesh);
00135
00136 REGISTER_METHOD(SetParticleSystem);
00137 REGISTER_METHOD(SetParticleSystemBounds);
00138 REGISTER_METHOD(ParticleSystem_FastForward);
00139 REGISTER_METHOD(ParticleSystem_SetNonVisibleUpdateTimeout);
00140 REGISTER_METHOD(ParticleSystem_SetSpeedFactor);
00141 REGISTER_METHOD(ParticleSystem_GetNumParticles);
00142 REGISTER_METHOD(ParticleSystem_RemoveAllEmitters);
00143 REGISTER_METHOD(ParticleSystem_SetEmitterRate);
00144 REGISTER_METHOD(ParticleSystem_SetDefaultParticleSize);
00145 REGISTER_METHOD(ParticleSystem_SetEmitterVelocityMinMax);
00146
00147 REGISTER_METHOD(SetBeam);
00148 REGISTER_METHOD(BeamCountLines);
00149 REGISTER_METHOD(BeamClearLines);
00150 REGISTER_METHOD(BeamAddLine);
00151 REGISTER_METHOD(BeamClearLine);
00152 REGISTER_METHOD(BeamDeleteLine);
00153 REGISTER_METHOD(BeamAddPoint);
00154 REGISTER_METHOD(BeamSetPoint);
00155 REGISTER_METHOD(BeamPopFront);
00156 REGISTER_METHOD(BeamPopBack);
00157 REGISTER_METHOD(BeamUpdateBounds);
00158
00159 REGISTER_METHOD(SetForcePosCam);
00160 REGISTER_METHOD(SetForceRotCam);
00161 REGISTER_METHOD(SetForceLookat);
00162
00163
00164 #define RegisterClassConstant(name) cScripting::SetGlobal(L,#name,Ogre::RenderOperation::name)
00165 RegisterClassConstant(OT_POINT_LIST);
00166 RegisterClassConstant(OT_LINE_LIST);
00167 RegisterClassConstant(OT_LINE_STRIP);
00168 RegisterClassConstant(OT_TRIANGLE_LIST);
00169 RegisterClassConstant(OT_TRIANGLE_STRIP);
00170 RegisterClassConstant(OT_TRIANGLE_FAN);
00171 #undef RegisterClassConstant
00172 }
00173
00175
00176
00178 static int GetGfx3DCount (lua_State *L) { PROFILE
00179 lua_pushnumber(L,cGfx3D::miCount);
00180 return 1;
00181 }
00182
00183 static int CreateGfx3D (lua_State *L) { PROFILE
00184 std::string sSceneMgrName = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? luaL_checkstring(L,1) : "main";
00185 Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneMgrName.c_str());
00186 cGfx3D* target = pSceneMgr ? cGfx3D::NewFree(pSceneMgr) : 0;
00187 return CreateUData(L,target);
00188 }
00189
00191 static int CreateChild (lua_State *L) { PROFILE
00192 cGfx3D* target = cGfx3D::NewChildOfGfx3D(checkudata_alive(L));
00193 return CreateUData(L,target);
00194 }
00195
00197 static int CreateTagPoint (lua_State *L) { PROFILE
00198 std::string sBoneName = luaL_checkstring(L,2);
00199 Ogre::Vector3 vOffsetPosition = (lua_gettop(L) >= 5 && !lua_isnil(L,5)) ? Ogre::Vector3( luaL_checknumber(L,3),luaL_checknumber(L,4),luaL_checknumber(L,5)) : Ogre::Vector3::ZERO;
00200 Ogre::Quaternion qOffsetOrientation = (lua_gettop(L) >= 8 && !lua_isnil(L,8)) ? Ogre::Quaternion( luaL_checknumber(L,6),luaL_checknumber(L,7),luaL_checknumber(L,8),luaL_checknumber(L,9)) : Ogre::Quaternion::IDENTITY;
00201 cGfx3D* target = cGfx3D::NewTagPoint(checkudata_alive(L),sBoneName.c_str(),vOffsetPosition,qOffsetOrientation);
00202 return CreateUData(L,target);
00203 }
00204
00206 static int CreateRootGfx3D (lua_State *L) { PROFILE
00207 std::string sSceneMgrName = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? luaL_checkstring(L,1) : "main";
00208 Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneMgrName.c_str());
00209 cGfx3D* target = pSceneMgr ? cGfx3D::NewChildOfRoot(pSceneMgr) : 0;
00210 return CreateUData(L,target);
00211 }
00212
00213 static int CreateCamPosGfx3D (lua_State *L) { PROFILE
00214 cGfx3D* target = cGfx3D::NewChildOfSceneNode(cOgreWrapper::GetSingleton().mpCamPosSceneNode);
00215 return CreateUData(L,target);
00216 }
00217
00218 static int CreateCockpitGfx3D (lua_State *L) { PROFILE
00219 cGfx3D* target = cGfx3D::NewChildOfSceneNode(cOgreWrapper::GetSingleton().mpCamHolderSceneNode);
00220 return CreateUData(L,target);
00221 }
00222
00224 static int SetForcePosCam (lua_State *L) { PROFILE
00225 Ogre::Camera* cam = (lua_gettop(L) > 1 && !lua_isnil(L,2))?cLuaBind<cCamera>::checkudata_alive(L,2)->mpCam:0;
00226 checkudata_alive(L)->mpForcePosCam = cam;
00227 if (cam) checkudata_alive(L)->SetPrepareFrameStep(true);
00228 return 0;
00229 }
00230
00235 static int SetPath (lua_State *L) { PROFILE
00236 cGfx3D *gfx = checkudata_alive(L);
00237 if(lua_isnumber(L,2) && lua_istable(L,5)){
00238 Ogre::SceneManager *mgr = cOgreWrapper::GetSingleton().mSceneMgr;
00239
00240
00241 gfx->DestroyPath();
00242 gfx->mbHasPath = true;
00243
00244
00245 float totalt = luaL_checknumber(L,2);
00246 bool looped = luaL_checkbool(L,3);
00247 bool linear = luaL_checkbool(L,4);
00248 size_t count = lua_objlen(L,5);
00249
00250
00251 if(gfx->msPathAnimName.size() == 0){
00252 gfx->msPathAnimName = cOgreWrapper::GetSingleton().GetUniqueName();
00253 }
00254
00255 Ogre::Animation* anim = mgr->createAnimation(gfx->msPathAnimName, totalt);
00256 anim->setInterpolationMode(linear ? Ogre::Animation::IM_LINEAR : Ogre::Animation::IM_SPLINE);
00257 Ogre::NodeAnimationTrack* track = anim->createNodeTrack(0, gfx->mpSceneNode);
00258
00259 Ogre::TransformKeyFrame* key;
00260
00261 float t;
00262 float px,py,pz;
00263 float rw,rx,ry,rz;
00264 float sx,sy,sz;
00265
00266
00267 for(size_t i = 0; i < count; i += 2){
00268
00269 lua_rawgeti(L,5,i+1);
00270 t = lua_tonumber(L,-1);
00271 lua_pop(L,1);
00272
00273
00274
00275 key = track->createNodeKeyFrame(t);
00276
00277
00278 lua_rawgeti(L,5,i+2);
00279
00280
00281 lua_pushstring(L,"p");
00282 lua_gettable(L,-2);
00283
00284
00285 if(lua_istable(L,-1)){
00286 lua_rawgeti(L,-1,1); px = lua_tonumber(L,-1); lua_pop(L,1);
00287 lua_rawgeti(L,-1,2); py = lua_tonumber(L,-1); lua_pop(L,1);
00288 lua_rawgeti(L,-1,3); pz = lua_tonumber(L,-1); lua_pop(L,1);
00289
00290 key->setTranslate(Vector3(px,py,pz));
00291 }
00292 lua_pop(L,1);
00293
00294
00295 lua_pushstring(L,"s");
00296 lua_gettable(L,-2);
00297
00298
00299 if(lua_istable(L,-1)){
00300 lua_rawgeti(L,-1,1); sx = lua_tonumber(L,-1); lua_pop(L,1);
00301 lua_rawgeti(L,-1,2); sy = lua_tonumber(L,-1); lua_pop(L,1);
00302 lua_rawgeti(L,-1,3); sz = lua_tonumber(L,-1); lua_pop(L,1);
00303
00304 key->setScale(Vector3(sx,sy,sz));
00305 }
00306 lua_pop(L,1);
00307
00308
00309 lua_pushstring(L,"r");
00310 lua_gettable(L,-2);
00311
00312
00313 if(lua_istable(L,-1)){
00314 lua_rawgeti(L,-1,1); rw = lua_tonumber(L,-1); lua_pop(L,1);
00315 lua_rawgeti(L,-1,2); rx = lua_tonumber(L,-1); lua_pop(L,1);
00316 lua_rawgeti(L,-1,3); ry = lua_tonumber(L,-1); lua_pop(L,1);
00317 lua_rawgeti(L,-1,4); rz = lua_tonumber(L,-1); lua_pop(L,1);
00318
00319 key->setRotation(Quaternion(rw,rx,ry,rz));
00320 }
00321 lua_pop(L,1);
00322 }
00323
00324 gfx->mpPathAnimState = cOgreWrapper::GetSingleton().mSceneMgr->createAnimationState(gfx->msPathAnimName);
00325 gfx->mpPathAnimState->setEnabled(true);
00326 gfx->mpPathAnimState->setLoop(looped);
00327
00328 return 0;
00329 } else {
00330 return 0;
00331 }
00332 }
00333
00335 static int SetForceRotCam (lua_State *L) { PROFILE
00336 Ogre::Camera* cam = (lua_gettop(L) > 1 && !lua_isnil(L,2))?cLuaBind<cCamera>::checkudata_alive(L,2)->mpCam:0;
00337 checkudata_alive(L)->mpForceRotCam = cam;
00338 if (cam) checkudata_alive(L)->SetPrepareFrameStep(true);
00339 return 0;
00340 }
00341
00343 static int SetForceLookat (lua_State *L) { PROFILE
00344 cGfx3D* target = (lua_gettop(L) > 1 && !lua_isnil(L,2))?checkudata_alive(L,2):0;
00345 checkudata_alive(L)->mpForceLookatTarget = target;
00346 if (target) checkudata_alive(L)->SetPrepareFrameStep(true);
00347 return 0;
00348 }
00349
00351 static int Destroy (lua_State *L) { PROFILE
00352
00353 delete checkudata_alive(L);
00354
00355 return 0;
00356 }
00357
00358
00361 static int GetWorldAABB (lua_State *L) { PROFILE
00362 cGfx3D* mygfx = checkudata_alive(L);
00363 if (!mygfx->mpSceneNode) return 0;
00364 mygfx->mpSceneNode->_updateBounds();
00365 const Ogre::AxisAlignedBox& mybounds = mygfx->mpSceneNode->_getWorldAABB();
00366 lua_pushnumber(L,mybounds.getMinimum().x);
00367 lua_pushnumber(L,mybounds.getMinimum().y);
00368 lua_pushnumber(L,mybounds.getMinimum().z);
00369 lua_pushnumber(L,mybounds.getMaximum().x);
00370 lua_pushnumber(L,mybounds.getMaximum().y);
00371 lua_pushnumber(L,mybounds.getMaximum().z);
00372 return 6;
00373 }
00374
00376 static int GetEntityBounds (lua_State *L) { PROFILE
00377 cGfx3D* mygfx = checkudata_alive(L);
00378 if (!mygfx->mpEntity) return 0;
00379 Ogre::MeshPtr pMesh = mygfx->mpEntity->getMesh();
00380 if (pMesh.isNull()) return 0;
00381 const Ogre::AxisAlignedBox& mybounds = pMesh->getBounds();
00382 lua_pushnumber(L,mybounds.getMinimum().x);
00383 lua_pushnumber(L,mybounds.getMinimum().y);
00384 lua_pushnumber(L,mybounds.getMinimum().z);
00385 lua_pushnumber(L,mybounds.getMaximum().x);
00386 lua_pushnumber(L,mybounds.getMaximum().y);
00387 lua_pushnumber(L,mybounds.getMaximum().z);
00388 return 6;
00389 }
00390
00392 static int GetEntityBoundRad (lua_State *L) { PROFILE
00393 cGfx3D* mygfx = checkudata_alive(L);
00394 if (!mygfx->mpEntity) return 0;
00395 Ogre::MeshPtr pMesh = mygfx->mpEntity->getMesh();
00396 if (pMesh.isNull()) return 0;
00397 lua_pushnumber(L,pMesh->getBoundingSphereRadius());
00398 return 1;
00399 }
00400
00402 static int GetEntityIndexCount (lua_State *L) { PROFILE
00403 cGfx3D* mygfx = checkudata_alive(L);
00404 lua_pushnumber(L,cOgreWrapper::GetSingleton().GetEntityIndexCount(mygfx->mpEntity));
00405 return 1;
00406 }
00407
00409 static int GetEntityVertex (lua_State *L) { PROFILE
00410 cGfx3D* mygfx = checkudata_alive(L);
00411 Ogre::Vector3 p = cOgreWrapper::GetSingleton().GetEntityVertex(mygfx->mpEntity,luaL_checkint(L,2));
00412 lua_pushnumber(L,p.x);
00413 lua_pushnumber(L,p.y);
00414 lua_pushnumber(L,p.z);
00415 return 3;
00416 }
00417
00419 static int GetCustomBoundRad (lua_State *L) { PROFILE
00420 lua_pushnumber(L,checkudata_alive(L)->mfCustomBoundingRadius);
00421 return 1;
00422 }
00423
00425 static int SetCustomBoundRad (lua_State *L) { PROFILE
00426 checkudata_alive(L)->mfCustomBoundingRadius = luaL_checknumber(L,2);
00427 return 0;
00428 }
00429
00431 static int RayPick (lua_State *L) { PROFILE
00432 cGfx3D* mygfx = checkudata_alive(L);
00433 float fHitDist = 0.0;
00434 bool bHit = false;
00435 int iFaceNum = -1;
00436 int fAABBHitFaceNormalX = -1;
00437 int fAABBHitFaceNormalY = -1;
00438 int fAABBHitFaceNormalZ = -1;
00439
00440
00441 Ogre::Vector3 vRayPos(luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4));
00442 Ogre::Vector3 vRayDir(luaL_checknumber(L,5),luaL_checknumber(L,6),luaL_checknumber(L,7));
00443 if (mygfx->mpEntity) {
00444 iFaceNum = cOgreWrapper::GetSingleton().RayEntityQuery(vRayPos,vRayDir,mygfx->mpEntity,&fHitDist);
00445 bHit = iFaceNum != -1;
00446 }
00447 if (mygfx->mbHasAABB) {
00448 bHit = cOgreWrapper::GetSingleton().RayAABBQuery(vRayPos - mygfx->GetPosition(),vRayDir,mygfx->mAABB,&fHitDist,&fAABBHitFaceNormalX,&fAABBHitFaceNormalY,&fAABBHitFaceNormalZ);
00449 }
00450 lua_pushboolean(L,bHit);
00451 lua_pushnumber(L,fHitDist);
00452 lua_pushnumber(L,iFaceNum);
00453 lua_pushnumber(L,fAABBHitFaceNormalX);
00454 lua_pushnumber(L,fAABBHitFaceNormalY);
00455 lua_pushnumber(L,fAABBHitFaceNormalZ);
00456 return 6;
00457 }
00458
00461 static int RayPickList (lua_State *L) { PROFILE
00462 cGfx3D* mygfx = checkudata_alive(L);
00463 Ogre::Vector3 vRayPos(luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4));
00464 Ogre::Vector3 vRayDir(luaL_checknumber(L,5),luaL_checknumber(L,6),luaL_checknumber(L,7));
00465
00466 if (!mygfx->mpEntity) return 0;
00467
00468 std::vector<std::pair<float,int> > myHitList;
00469 cOgreWrapper::GetSingleton().RayEntityQuery(vRayPos,vRayDir,mygfx->mpEntity,myHitList);
00470
00471
00472 lua_newtable(L);
00473 for (unsigned int i=0;i<myHitList.size();++i) {
00474 lua_pushnumber( L, myHitList[i].first );
00475 lua_rawseti( L, -2, myHitList[i].second );
00476 }
00477 return 1;
00478 }
00479
00481 static int SetParent (lua_State *L) { PROFILE
00482 checkudata_alive(L)->SetParent((lua_gettop(L) > 1 && !lua_isnil(L,2))?checkudata(L,2):0);
00483 return 0;
00484 }
00485
00487 static int SetRootAsParent (lua_State *L) { PROFILE
00488 std::string sSceneMgrName = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkstring(L,2) : "main";
00489 Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneMgrName.c_str());
00490 checkudata_alive(L)->SetParent(pSceneMgr?pSceneMgr->getRootSceneNode():0);
00491 return 0;
00492 }
00493
00495 static int SetVisible (lua_State *L) { PROFILE
00496 bool bCascade = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ? lua_toboolean(L,3) : true;
00497 checkudata_alive(L)->SetVisible(lua_toboolean(L,2), bCascade);
00498 return 0;
00499 }
00500
00502 static int SetDisplaySkeleton (lua_State *L) { PROFILE
00503 Ogre::Entity* myentity = checkudata_alive(L)->mpEntity;
00504 if (myentity) myentity->setDisplaySkeleton(lua_toboolean(L,2));
00505 return 0;
00506 }
00507
00509 static int SetRenderingDistance (lua_State *L) { PROFILE
00510 Ogre::Entity* myentity = checkudata_alive(L)->mpEntity;
00511 if (myentity) myentity->setRenderingDistance(luaL_checknumber(L,2));
00512 return 0;
00513 }
00514
00517 static int SetPrepareFrameStep (lua_State *L) { PROFILE
00518 checkudata_alive(L)->SetPrepareFrameStep(lua_toboolean(L,2));
00519 return 0;
00520 }
00521
00523 static int SetMaterial (lua_State *L) { PROFILE
00524 checkudata_alive(L)->SetMaterial(luaL_checkstring(L, 2));
00525 return 0;
00526 }
00527
00529 static int GetScale (lua_State *L) { PROFILE
00530 Ogre::Vector3 p = checkudata_alive(L)->GetScale();
00531 lua_pushnumber(L,p.x);
00532 lua_pushnumber(L,p.y);
00533 lua_pushnumber(L,p.z);
00534 return 3;
00535 }
00536
00538 static int GetPosition (lua_State *L) { PROFILE
00539 Ogre::Vector3 p = checkudata_alive(L)->GetPosition();
00540 lua_pushnumber(L,p.x);
00541 lua_pushnumber(L,p.y);
00542 lua_pushnumber(L,p.z);
00543 return 3;
00544 }
00545
00547 static int GetDerivedPosition (lua_State *L) { PROFILE
00548 Ogre::Vector3 p = checkudata_alive(L)->GetDerivedPosition();
00549 lua_pushnumber(L,p.x);
00550 lua_pushnumber(L,p.y);
00551 lua_pushnumber(L,p.z);
00552 return 3;
00553 }
00554
00556 static int GetOrientation (lua_State *L) { PROFILE
00557 Ogre::Quaternion q = checkudata_alive(L)->GetOrientation();
00558 lua_pushnumber(L,q.w);
00559 lua_pushnumber(L,q.x);
00560 lua_pushnumber(L,q.y);
00561 lua_pushnumber(L,q.z);
00562 return 4;
00563 }
00564
00566 static int GetDerivedOrientation (lua_State *L) { PROFILE
00567 Ogre::Quaternion q = checkudata_alive(L)->GetDerivedOrientation();
00568 lua_pushnumber(L,q.w);
00569 lua_pushnumber(L,q.x);
00570 lua_pushnumber(L,q.y);
00571 lua_pushnumber(L,q.z);
00572 return 4;
00573 }
00574
00576 static int SetPosition (lua_State *L) { PROFILE
00577 checkudata_alive(L)->SetPosition(Ogre::Vector3(luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4)));
00578 return 0;
00579 }
00580
00582 static int SetScale (lua_State *L) { PROFILE
00583 checkudata_alive(L)->SetScale(Ogre::Vector3(luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4)));
00584 return 0;
00585 }
00586
00587
00589 static int SetNormaliseNormals (lua_State *L) { PROFILE
00590 bool bOn = (lua_isboolean(L,2) ? lua_toboolean(L,2) : luaL_checkint(L,2));
00591 checkudata_alive(L)->SetNormaliseNormals(bOn);
00592 return 0;
00593 }
00594
00595
00596
00598 static int SetOrientation (lua_State *L) { PROFILE
00599 checkudata_alive(L)->SetOrientation(Ogre::Quaternion(luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4),luaL_checknumber(L,5)));
00600 return 0;
00601 }
00602
00604 static int SetBillboard (lua_State *L) { PROFILE
00605 checkudata_alive(L)->SetBillboard(
00606 luaSFZ_checkVector3(L,2),
00607 luaL_checknumber(L,5),
00608 luaL_checkstring(L,6)
00609 );
00610 return 0;
00611 }
00612
00614 static int SetRadar (lua_State *L) { PROFILE
00615 checkudata_alive(L)->SetRadar();
00616 return 0;
00617 }
00618
00620 static int SetRadialGrid (lua_State *L) { PROFILE
00621 checkudata_alive(L)->SetRadialGrid();
00622 return 0;
00623 }
00624
00626 static int SetWireBoundingBoxGfx3D (lua_State *L) { PROFILE
00627 checkudata_alive(L)->SetWireBoundingBox(*checkudata_alive(L,2));
00628 return 0;
00629 }
00631 static int SetWireBoundingBoxMinMax (lua_State *L) { PROFILE
00632 checkudata_alive(L)->SetWireBoundingBox(luaSFZ_checkVector3(L,2),luaSFZ_checkVector3(L,5));
00633 return 0;
00634 }
00635
00636
00637
00638
00639
00640
00641
00643 static int SetTrail (lua_State *L) { PROFILE
00644 checkudata_alive(L)->SetTrail(
00645 luaSFZ_checkVector3(L,2),
00646 luaL_checknumber(L,5),
00647 luaL_checkint(L,6),
00648 luaL_checkstring(L,7),
00649 luaL_checknumber(L,8),
00650 luaL_checknumber(L,9),
00651 luaL_checknumber(L,10),
00652 luaL_checknumber(L,11),
00653 luaL_checknumber(L,12),
00654 luaL_checknumber(L,13),
00655 luaL_checknumber(L,14),
00656 luaL_checknumber(L,15),
00657 luaL_checknumber(L,16),
00658 luaL_checknumber(L,17)
00659 );
00660 return 0;
00661 }
00662
00664 static int SetExplosion (lua_State *L) { PROFILE
00665 checkudata_alive(L)->SetExplosion(luaL_checknumber(L,2),luaL_checkstring(L,3));
00666 return 0;
00667 }
00668
00671 static int SetTargetTracker (lua_State *L) { PROFILE
00672 size_t index = 4;
00673 checkudata_alive(L)->SetTargetTracker(
00674 luaL_checknumber(L,2),
00675 luaL_checknumber(L,3),
00676 luaSFZ_checkColour3(L,index),
00677 luaL_checkstring(L,7)
00678 );
00679 return 0;
00680 }
00681
00682
00683
00685 static int SetBeam (lua_State *L) { PROFILE
00686 checkudata_alive(L)->SetBeam(lua_isboolean(L,2) ? lua_toboolean(L,2) : luaL_checkint(L,2));
00687 return 0;
00688 }
00689
00691 static int BeamCountLines (lua_State *L) { PROFILE lua_pushnumber(L,checkudata_alive(L)->mpBeam->CountLines()); return 1; }
00692
00695 static int BeamClearLines (lua_State *L) { PROFILE checkudata_alive(L)->mpBeam->ClearLines(); return 0; }
00696
00698 static int BeamAddLine (lua_State *L) { PROFILE lua_pushnumber(L,checkudata_alive(L)->mpBeam->AddLine()); return 1; }
00699
00701 static int BeamDeleteLine (lua_State *L) { PROFILE checkudata_alive(L)->mpBeam->DeleteLine(luaL_checkint(L,2)); return 0; }
00702
00705 static int BeamClearLine (lua_State *L) { PROFILE checkudata_alive(L)->mpBeam->ClearLine(luaL_checkint(L,2)); return 0; }
00706
00708 static int BeamPopFront (lua_State *L) { PROFILE checkudata_alive(L)->mpBeam->PopFront(luaL_checkint(L,2)); return 0; }
00709
00711 static int BeamPopBack (lua_State *L) { PROFILE checkudata_alive(L)->mpBeam->PopBack(luaL_checkint(L,2)); return 0; }
00712
00714 static int BeamAddPoint (lua_State *L) { PROFILE
00715 int i=3;
00716 checkudata_alive(L)->mpBeam->AddPoint(luaL_checkint(L,2),cBeamPoint(
00717 Ogre::Vector3(luaL_checknumber(L,i+0),luaL_checknumber(L,i+1),luaL_checknumber(L,i+2)),
00718 luaL_checknumber(L,i+3),luaL_checknumber(L,i+4),
00719 luaL_checknumber(L,i+5),luaL_checknumber(L,i+6),
00720 luaL_checknumber(L,i+7),luaL_checknumber(L,i+8),
00721 lua_gettop(L) >= i+12 ? Ogre::ColourValue(luaL_checknumber(L,i+ 9),luaL_checknumber(L,i+10),luaL_checknumber(L,i+11),luaL_checknumber(L,i+12)) : Ogre::ColourValue::White,
00722 lua_gettop(L) >= i+16 ? Ogre::ColourValue(luaL_checknumber(L,i+13),luaL_checknumber(L,i+14),luaL_checknumber(L,i+15),luaL_checknumber(L,i+16)) : Ogre::ColourValue::White
00723 ));
00724 return 0;
00725 }
00726
00728 static int BeamSetPoint (lua_State *L) { PROFILE
00729 cBeamPoint* p = checkudata_alive(L)->mpBeam->GetPoint(luaL_checkint(L,2),luaL_checkint(L,3));
00730 int i=4;
00731 if (p) *p = cBeamPoint(
00732 Ogre::Vector3(luaL_checknumber(L,i+0),luaL_checknumber(L,i+1),luaL_checknumber(L,i+2)),
00733 luaL_checknumber(L,i+3),luaL_checknumber(L,i+4),
00734 luaL_checknumber(L,i+5),luaL_checknumber(L,i+6),
00735 luaL_checknumber(L,i+7),luaL_checknumber(L,i+8),
00736 lua_gettop(L) >= i+12 ? Ogre::ColourValue(luaL_checknumber(L,i+ 9),luaL_checknumber(L,i+10),luaL_checknumber(L,i+11),luaL_checknumber(L,i+12)) : Ogre::ColourValue::White,
00737 lua_gettop(L) >= i+16 ? Ogre::ColourValue(luaL_checknumber(L,i+13),luaL_checknumber(L,i+14),luaL_checknumber(L,i+15),luaL_checknumber(L,i+16)) : Ogre::ColourValue::White
00738 );
00739 return 0;
00740 }
00741
00744 static int BeamUpdateBounds (lua_State *L) { PROFILE checkudata_alive(L)->mpBeam->UpdateBounds(); return 0; }
00745
00746
00747
00749 static int SetParticleSystem (lua_State *L) { PROFILE
00750 checkudata_alive(L)->SetParticleSystem(luaL_checkstring(L, 2));
00751 return 0;
00752 }
00753
00755 static int SetParticleSystemBounds (lua_State *L) { PROFILE
00756 Ogre::ParticleSystem* pParticleSystem = checkudata_alive(L)->mpParticleSystem;
00757 float minx = luaL_checknumber(L,2);
00758 float miny = luaL_checknumber(L,3);
00759 float minz = luaL_checknumber(L,4);
00760 float maxx = luaL_checknumber(L,5);
00761 float maxy = luaL_checknumber(L,6);
00762 float maxz = luaL_checknumber(L,7);
00763 Ogre::Vector3 vMin(minx,miny,minz);
00764 Ogre::Vector3 vMax(maxx,maxy,maxz);
00765 if (pParticleSystem) pParticleSystem->setBounds(Ogre::AxisAlignedBox(vMin,vMax));
00766 return 0;
00767 }
00768
00770 static int ParticleSystem_FastForward (lua_State *L) { PROFILE
00771 Ogre::ParticleSystem* target = checkudata_alive(L)->mpParticleSystem;
00772 if (target) target->fastForward(luaL_checknumber(L, 2),luaL_checknumber(L, 3));
00773 return 0;
00774 }
00776 static int ParticleSystem_SetNonVisibleUpdateTimeout (lua_State *L) { PROFILE
00777 Ogre::ParticleSystem* target = checkudata_alive(L)->mpParticleSystem;
00778 if (target) target->setNonVisibleUpdateTimeout(luaL_checknumber(L, 2));
00779 return 0;
00780 }
00782 static int ParticleSystem_SetSpeedFactor (lua_State *L) { PROFILE
00783 Ogre::ParticleSystem* target = checkudata_alive(L)->mpParticleSystem;
00784 if (target) target->setSpeedFactor(luaL_checknumber(L, 2));
00785 return 0;
00786 }
00787
00789 static int ParticleSystem_GetNumParticles (lua_State *L) { PROFILE
00790 lua_pushnumber(L,checkudata_alive(L)->GetNumParticles());
00791 return 1;
00792 }
00794 static int ParticleSystem_RemoveAllEmitters (lua_State *L) { PROFILE
00795 Ogre::ParticleSystem* target = checkudata_alive(L)->mpParticleSystem;
00796 if (target) target->removeAllEmitters();
00797 return 0;
00798 }
00800 static int ParticleSystem_SetEmitterRate (lua_State *L) { PROFILE
00801 Ogre::ParticleSystem* target = checkudata_alive(L)->mpParticleSystem;
00802 if (!target) return 0;
00803 Ogre::ParticleEmitter* emitter = target->getEmitter(luaL_checkint(L, 2));
00804 if (emitter) emitter->setEmissionRate(luaL_checknumber(L,3));
00805 return 0;
00806 }
00808 static int ParticleSystem_SetDefaultParticleSize (lua_State *L) { PROFILE
00809 Ogre::ParticleSystem* target = checkudata_alive(L)->mpParticleSystem;
00810 if (target) target->setDefaultDimensions(luaL_checknumber(L,2),luaL_checknumber(L,3));
00811 return 0;
00812 }
00814 static int ParticleSystem_SetEmitterVelocityMinMax (lua_State *L) { PROFILE
00815 Ogre::ParticleSystem* target = checkudata_alive(L)->mpParticleSystem;
00816 if (!target) return 0;
00817 Ogre::ParticleEmitter* emitter = target->getEmitter(luaL_checkint(L, 2));
00818 if (emitter) emitter->setParticleVelocity(luaL_checknumber(L,3),luaL_checknumber(L,4));
00819 return 0;
00820 }
00821
00822
00823
00825 static int SetMesh (lua_State *L) { PROFILE
00826 checkudata_alive(L)->SetMesh(luaL_checkstring(L, 2));
00827 return 0;
00828 }
00829
00831 static int CreateMergedMesh (lua_State *L) { PROFILE
00832 checkudata_alive(L)->CreateMergedMesh(luaL_checkstring(L, 2));
00833 return 0;
00834 }
00835
00837 static int GetMeshSubEntityCount (lua_State *L) { PROFILE
00838 cGfx3D* mygfx = checkudata_alive(L);
00839 if (!mygfx->mpEntity) return 0;
00840 lua_pushnumber(L,mygfx->mpEntity->getNumSubEntities());
00841 return 1;
00842 }
00843
00844
00846 static int GetMeshSubEntityMaterial (lua_State *L) { PROFILE
00847 cGfx3D* mygfx = checkudata_alive(L);
00848 if (!mygfx->mpEntity) return 0;
00849 Ogre::SubEntity* pSub = mygfx->mpEntity->getSubEntity(luaL_checkint(L,2));
00850 if (!pSub) return 0;
00851 lua_pushstring(L,pSub->getMaterialName().c_str());
00852 return 1;
00853 }
00854
00856 static int SetMeshSubEntityMaterial (lua_State *L) { PROFILE
00857 cGfx3D* mygfx = checkudata_alive(L);
00858 if (!mygfx->mpEntity) return 0;
00859 Ogre::SubEntity* pSub = mygfx->mpEntity->getSubEntity(luaL_checkint(L,2));
00860 if (pSub) pSub->setMaterialName(luaL_checkstring(L,3));
00861 return 0;
00862 }
00863
00865 static int SetMeshSubEntityCustomParameter (lua_State *L) { PROFILE
00866 cGfx3D* mygfx = checkudata_alive(L);
00867 if (!mygfx->mpEntity) return 0;
00868 Ogre::SubEntity* pSub = mygfx->mpEntity->getSubEntity(luaL_checkint(L,2));
00869 int iParam = luaL_checkint(L,3);
00870 float x = luaL_checknumber(L,4);
00871 float y = luaL_checknumber(L,5);
00872 float z = luaL_checknumber(L,6);
00873 float w = luaL_checknumber(L,7);
00874 if (pSub) pSub->setCustomParameter(iParam,Ogre::Vector4(x,y,z,w));
00875 return 0;
00876 }
00877
00879 static int SetAnim (lua_State *L) { PROFILE
00880 checkudata_alive(L)->SetAnim(luaL_checkstring(L, 2),lua_isboolean(L,3) ? lua_toboolean(L,3) : luaL_checkint(L,3));
00881 return 0;
00882 }
00883
00885 static int GetAnimLength (lua_State *L) { PROFILE
00886 lua_pushnumber(L,checkudata_alive(L)->GetAnimLength(luaL_checkstring(L, 2)));
00887 return 1;
00888 }
00889
00891 static int GetPathAnimTimePos (lua_State *L) { PROFILE
00892 lua_pushnumber(L,checkudata_alive(L)->GetPathAnimTimePos());
00893 return 1;
00894 }
00895
00897 static int SetPathAnimTimePos (lua_State *L) { PROFILE
00898 checkudata_alive(L)->SetPathAnimTimePos(luaL_checknumber(L,2));
00899 return 0;
00900 }
00901
00903 static int PathAnimAddTime (lua_State *L) { PROFILE
00904 Ogre::AnimationState* pPathAnimState = checkudata_alive(L)->mpPathAnimState;
00905 if (pPathAnimState) pPathAnimState->addTime(luaL_checknumber(L,2));
00906 return 0;
00907 }
00908
00910 static int IsPathAnimLooped (lua_State *L) { PROFILE
00911 lua_pushboolean(L,checkudata_alive(L)->IsPathAnimLooped());
00912 return 1;
00913 }
00914
00916 static int GetAnimTimePos (lua_State *L) { PROFILE
00917 lua_pushnumber(L,checkudata_alive(L)->GetAnimTimePos());
00918 return 1;
00919 }
00920
00922 static int SetAnimTimePos (lua_State *L) { PROFILE
00923 checkudata_alive(L)->SetAnimTimePos(luaL_checknumber(L,2));
00924 return 0;
00925 }
00926
00928 static int AnimAddTime (lua_State *L) { PROFILE
00929 Ogre::AnimationState* pAnimState = checkudata_alive(L)->mpAnimState;
00930 if (pAnimState) pAnimState->addTime(luaL_checknumber(L,2));
00931 return 0;
00932 }
00933
00935 static int IsAnimLooped (lua_State *L) { PROFILE
00936 lua_pushboolean(L,checkudata_alive(L)->IsAnimLooped());
00937 return 1;
00938 }
00939
00941 static int HasBone (lua_State *L) { PROFILE
00942 lua_pushboolean(L,checkudata_alive(L)->HasBone(luaL_checkstring(L, 2)));
00943 return 1;
00944 }
00945
00947 static int HasSkeleton (lua_State *L) { PROFILE
00948 cGfx3D* mygfx = checkudata_alive(L);
00949 if (!mygfx->mpEntity) return 0;
00950 lua_pushboolean(L,mygfx->mpEntity->hasSkeleton());
00951 return 1;
00952 }
00953
00955 static int GetSkeletonName (lua_State *L) { PROFILE
00956 cGfx3D* mygfx = checkudata_alive(L);
00957 if (!mygfx->mpEntity) return 0;
00958 lua_pushstring(L,mygfx->mpEntity->getSkeleton()->getName().c_str());
00959 return 1;
00960 }
00961
00963 static int ShareSkeletonInstanceWith (lua_State *L) { PROFILE
00964 cGfx3D* mygfx = checkudata_alive(L);
00965 cGfx3D* other = (lua_gettop(L) > 1 && !lua_isnil(L,2))?cLuaBind<cGfx3D>::checkudata_alive(L,2):0;
00966 if (!mygfx->mpEntity || !other || !other->mpEntity) return 0;
00967 mygfx->mpEntity->shareSkeletonInstanceWith(other->mpEntity);
00968 return 0;
00969 }
00970
00972 static int StopSharingSkeletonInstance (lua_State *L) { PROFILE
00973 cGfx3D* mygfx = checkudata_alive(L);
00974 if (!mygfx->mpEntity) return 0;
00975 mygfx->mpEntity->stopSharingSkeletonInstance();
00976 return 0;
00977 }
00978
00979
00980
00982 static int SetSimpleRenderable (lua_State *L) { PROFILE
00983 checkudata_alive(L)->SetSimpleRenderable();
00984 return 0;
00985 }
00986
00987
00988
00991 static int RenderableBegin (lua_State *L) { PROFILE
00992 cRobRenderOp* pRobRenderOp = checkudata_alive(L)->mpSimpleRenderable;
00993 if (!pRobRenderOp) return 0;
00994
00995 pRobRenderOp->Begin(
00996 luaL_checkint(L,2),
00997 luaL_checkint(L,3),
00998 lua_isboolean(L,4) ? lua_toboolean(L,4) : luaL_checkint(L,4),
00999 lua_isboolean(L,5) ? lua_toboolean(L,5) : luaL_checkint(L,5),
01000 (Ogre::RenderOperation::OperationType)luaL_checkint(L,6)
01001 );
01002 return 0;
01003 }
01004
01005
01006
01007
01008
01009
01010
01011
01013 static int RenderableVertex (lua_State *L) { PROFILE
01014 cRobRenderOp* pRobRenderOp = checkudata_alive(L)->mpSimpleRenderable;
01015 if (!pRobRenderOp) return 0;
01016 #define F(i) luaL_checknumber(L,i)
01017 #define V(i) Vector3(F(i+0),F(i+1),F(i+2))
01018 #define C(i) ColourValue(F(i+0),F(i+1),F(i+2),F(i+3))
01019 Ogre::Vector3 p(F(2),F(3),F(4));
01020 int argc = lua_gettop(L) - 1;
01021 switch (argc) {
01022 case 3: pRobRenderOp->Vertex(p);
01023 break;case 5: pRobRenderOp->Vertex(p,F(5),F(6));
01024 break;case 6: pRobRenderOp->Vertex(p,V(5));
01025 break;case 8: pRobRenderOp->Vertex(p,V(5),F(8),F(9));
01026
01027 break;case 7: pRobRenderOp->Vertex(p,C(5));
01028 break;case 9: pRobRenderOp->Vertex(p,F(5),F(6),C(7));
01029 break;case 10: pRobRenderOp->Vertex(p,V(5),C(8));
01030 break;case 12: pRobRenderOp->Vertex(p,V(5),F(8),F(9),C(10));
01031 break;default: printf("WARNING ! cGfx3D_L::RenderableVertex : strange argument count : %d\n",argc);
01032 }
01033 #undef F
01034 #undef V
01035 #undef C
01036 return 0;
01037 }
01038
01041 static int RenderableIndex (lua_State *L) { PROFILE
01042 cRobRenderOp* pRobRenderOp = checkudata_alive(L)->mpSimpleRenderable;
01043 if (!pRobRenderOp) return 0;
01044 pRobRenderOp->Index(luaL_checkint(L,2));
01045 return 0;
01046 }
01047
01050 static int RenderableIndex3 (lua_State *L) { PROFILE
01051 cRobRenderOp* pRobRenderOp = checkudata_alive(L)->mpSimpleRenderable;
01052 if (!pRobRenderOp) return 0;
01053 pRobRenderOp->Index(luaL_checkint(L,2),luaL_checkint(L,3),luaL_checkint(L,4));
01054 return 0;
01055 }
01056
01059 static int RenderableIndex2 (lua_State *L) { PROFILE
01060 cRobRenderOp* pRobRenderOp = checkudata_alive(L)->mpSimpleRenderable;
01061 if (!pRobRenderOp) return 0;
01062 pRobRenderOp->Index(luaL_checkint(L,2));
01063 pRobRenderOp->Index(luaL_checkint(L,3));
01064 return 0;
01065 }
01066
01068 static int RenderableSkipVertices (lua_State *L) { PROFILE
01069 cRobRenderOp* pRobRenderOp = checkudata_alive(L)->mpSimpleRenderable;
01070 if (!pRobRenderOp) return 0;
01071 pRobRenderOp->SkipVertices(luaL_checkint(L,2));
01072 return 0;
01073 }
01074
01076 static int RenderableSkipIndices (lua_State *L) { PROFILE
01077 cRobRenderOp* pRobRenderOp = checkudata_alive(L)->mpSimpleRenderable;
01078 if (!pRobRenderOp) return 0;
01079 pRobRenderOp->SkipIndices(luaL_checkint(L,2));
01080 return 0;
01081 }
01082
01084 static int RenderableEnd (lua_State *L) { PROFILE
01085 cRobRenderOp* pRobRenderOp = checkudata_alive(L)->mpSimpleRenderable;
01086 if (!pRobRenderOp) return 0;
01087 pRobRenderOp->End();
01088 return 0;
01089 }
01090
01092 static int RenderableConvertToMesh (lua_State *L) { PROFILE
01093 cRobSimpleRenderable* pRobSimpleRenderable = checkudata_alive(L)->mpSimpleRenderable;
01094 if (!pRobSimpleRenderable) return 0;
01095 std::string sMeshName = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkstring(L,2) : cOgreWrapper::GetSingleton().GetUniqueName();
01096 pRobSimpleRenderable->ConvertToMesh(sMeshName);
01097 lua_pushstring(L,sMeshName.c_str());
01098 return 1;
01099 }
01100
01102 static int RenderableAddToMesh (lua_State *L) { PROFILE
01103 cRobSimpleRenderable* pRobSimpleRenderable = checkudata_alive(L)->mpSimpleRenderable;
01104 if (!pRobSimpleRenderable) return 0;
01105 std::string sMeshName = luaL_checkstring(L,2);
01106 pRobSimpleRenderable->AddToMesh(sMeshName);
01107 return 0;
01108 }
01109
01110
01111
01114 static int SetFastBatch (lua_State *L) { PROFILE
01115 checkudata_alive(L)->SetFastBatch();
01116 return 0;
01117 }
01118
01120 static int FastBatch_Build (lua_State *L) { PROFILE
01121 bool generateEdgeList = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkbool(L,2) : false;
01122
01123 cFastBatch* pFastBatch = checkudata_alive(L)->mpFastBatch;
01124 if (pFastBatch) pFastBatch->Build();
01125
01126 return 0;
01127 }
01128
01131 static int FastBatch_AddMeshBuffer (lua_State *L) { PROFILE
01132 cFastBatch* pFastBatch = checkudata_alive(L)->mpFastBatch;
01133 if (pFastBatch) {
01134 cBufferedMesh* pMeshBuffer = cLuaBind<cBufferedMesh>::checkudata_alive(L,2);
01135
01136 #define F(i) luaL_checknumber(L,i)
01137 #define V(i) Vector3( F(i+0),F(i+1),F(i+2))
01138 #define Q(i) Quaternion( F(i+0),F(i+1),F(i+2),F(i+3))
01139 #define C(i) ColourValue( F(i+0),F(i+1),F(i+2),F(i+3))
01140 #define V1 Ogre::Vector3::UNIT_SCALE
01141 #define Q1 Ogre::Quaternion::IDENTITY
01142 #define C1 Ogre::ColourValue::White
01143 float fOrderVal = luaL_checknumber(L,3);
01144 int argc = lua_gettop(L) - 3;
01145 int a0 = 4;
01146 switch (argc) {
01147 case 3: pFastBatch->AddMesh(*pMeshBuffer,V(a0) ,Q1 ,V1 ,C1 ,false ,fOrderVal);
01148 break;case 7: pFastBatch->AddMesh(*pMeshBuffer,V(a0) ,Q(a0+3) ,V1 ,C1 ,false ,fOrderVal);
01149 break;case 8: pFastBatch->AddMesh(*pMeshBuffer,V(a0) ,Q1 ,V1 ,C(a0+3) ,true ,fOrderVal);
01150 break;case 10: pFastBatch->AddMesh(*pMeshBuffer,V(a0) ,Q(a0+3) ,V(a0+7),C1 ,false ,fOrderVal);
01151 break;case 13: pFastBatch->AddMesh(*pMeshBuffer,V(a0) ,Q(a0+3) ,V1 ,C(a0+7) ,true ,fOrderVal);
01152 break;case 14: pFastBatch->AddMesh(*pMeshBuffer,V(a0) ,Q(a0+3) ,V(a0+7),C(a0+10) ,true ,fOrderVal);
01153 break;default: printf("WARNING ! cGfx3D_L::FastBatch_AddMesh : strange argument count : %d\n",argc);
01154 }
01155 #undef F
01156 #undef V
01157 #undef Q
01158 #undef C
01159 #undef V1
01160 #undef Q1
01161 #undef C1
01162 }
01163 return 0;
01164 }
01165
01168 static int FastBatch_SetDisplayRange (lua_State *L) { PROFILE
01169 float fMin = luaL_checknumber(L,2);
01170 float fMax = luaL_checknumber(L,3);
01171 cFastBatch* pFastBatch = checkudata_alive(L)->mpFastBatch;
01172 if (pFastBatch) pFastBatch->SetDisplayRange(fMin,fMax);
01173 return 0;
01174 }
01175
01176
01177
01179 static int SetStarfield (lua_State *L) { PROFILE
01180 checkudata_alive(L)->SetStarfield(luaL_checkint(L, 2),luaL_checknumber(L,3),luaL_checknumber(L,4),luaL_checkstring(L,5));
01181 return 0;
01182 }
01183
01185 static int SetTextFont (lua_State *L) { PROFILE
01186 checkudata_alive(L)->SetTextFont(luaL_checkstring(L,2));
01187 return 0;
01188 }
01189
01191 static int SetCastShadows (lua_State *L) { PROFILE
01192 checkudata_alive(L)->SetCastShadows(lua_toboolean(L,2));
01193 return 0;
01194 }
01195
01198 static int SetText (lua_State *L) { PROFILE
01199
01200 float fWrapMaxW = (lua_gettop(L) >= 7 && !lua_isnil(L,7)) ? luaL_checknumber(L,7) : 0;
01201 int iTextAlign = (lua_gettop(L) >= 8 && !lua_isnil(L,8)) ? luaL_checkint(L,8) : cGfx2D::kGfx2DAlign_Left;
01202 Ogre::GuiHorizontalAlignment ogrealign = Ogre::GHA_LEFT;
01203 switch (iTextAlign) {
01204 case cGfx2D::kGfx2DAlign_Left: ogrealign = Ogre::GHA_LEFT; break;
01205 case cGfx2D::kGfx2DAlign_Center: ogrealign = Ogre::GHA_CENTER; break;
01206 case cGfx2D::kGfx2DAlign_Right: ogrealign = Ogre::GHA_RIGHT; break;
01207 default : printf("cGfx3D::SetText : unknown iTextAlign %d\n",iTextAlign);
01208 }
01209
01210 checkudata_alive(L)->SetText(
01211 luaL_checkstring(L,2),
01212 luaL_checknumber(L,3),
01213 Ogre::ColourValue(
01214 luaL_checknumber(L,4),
01215 luaL_checknumber(L,5),
01216 luaL_checknumber(L,6)),
01217 fWrapMaxW,
01218 ogrealign);
01219 return 0;
01220 }
01221
01222 virtual const char* GetLuaTypeName () { return "lugre.gfx"; }
01223 };
01224
01226 void cGfx3D::LuaRegister (lua_State *L) { PROFILE
01227 cLuaBind<cGfx3D>::GetSingletonPtr(new cGfx3D_L())->LuaRegister(L);
01228 }
01229
01230 };