scriptmodel.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifdef GAME_TEMPLATE
  2. [EditorAttribute("box", "GameLib/Scripted", "Script model", "-0.25 -0.25 -0.25", "0.25 0.25 0.25", "255 0 0 255", "0 0 0 0", true, true, true)]
  3. class ScriptModelClass
  4. {
  5. }
  6. ScriptModelClass ScriptModelSource;
  7. class ScriptModel: GenericEntity
  8. {
  9. [Attribute("", "resourceNamePicker", "Model", "xob")]
  10. string Model;
  11. [Attribute("1", "combobox", "Physics", "", { ParamEnum("None", "2"), ParamEnum("Static", "1"), ParamEnum("Dynamic", "0") } )]
  12. int Type;
  13. void ScriptModel(IEntitySource src, IEntity parent)
  14. {
  15. if (Model== "")
  16. return;
  17. SetFlags(EntityFlags.ACTIVE | EntityFlags.SOLID | EntityFlags.VISIBLE, false);
  18. vobject vobj = GetObject(Model);
  19. SetObject(vobj, "");
  20. ReleaseObject(vobj, false);
  21. if (Type == 1)
  22. {
  23. dBodyCreateStatic(this, 0xffffffff); // todo - defines for layer mask
  24. }
  25. else if (Type == 0)
  26. {
  27. if(!dBodyCreateDynamic(this, 1.0, 0xffffffff))
  28. {
  29. //create implicit box
  30. vector mins, maxs;
  31. GetBounds(mins, maxs);
  32. vector center = (mins + maxs) * 0.5;
  33. vector size = maxs - mins;
  34. PhysicsGeomDef geoms[] = {PhysicsGeomDef("", dGeomCreateBox(size), "material/default", 0xffffffff)};
  35. dBodyCreateDynamicEx(this, center, 1, geoms);
  36. }
  37. if(dBodyIsSet(this))
  38. {
  39. dBodySetMass(this, 1.0);
  40. dBodyActive(this, ActiveState.ACTIVE);
  41. dBodyDynamic(this, true);
  42. }
  43. }
  44. }
  45. void ~ScriptModel()
  46. {
  47. if(dBodyIsSet(this))
  48. dBodyDestroy(this);
  49. }
  50. }
  51. #endif