SO3Engine
SCOLScene.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25
34// Assimp loader
37
39#include "SCOLPack/SO3SCOL.h"
40
41// Animation includes
46
47// Material includes
51
52// Renderer includes
53#include "SO3Renderer/SO3Root.h"
56
57// Scene Graph includes
63
64// Utils includes
66
68extern int SCENE_PRE_RENDER_EVENT;
72extern int OBJECT_LOADED_EVENT;
73
74extern SRoot * scolRoot;
75
76
77int createEntinyAnimationsScol(mmachine m, SEntity* entity)
78{
79 if (entity == NULL)
80 return 1;
81
82 const SAnimMap animations = entity->GetAnimations();
83 if (animations.empty())
84 return 0;
85
86 SAnimMap::const_iterator iAnimation = animations.begin();
87 while (iAnimation != animations.end())
88 {
89 SAnim* newAnimation = iAnimation->second;
90 assert(newAnimation != 0);
91 if ((newAnimation->GetType() != SAnim::SO3_SCENENODE_ANIM) && (newAnimation->GetType() != SAnim::SO3_SEQUENCE_ANIM))
92 {
93 createAnim(m, newAnimation, entity);
94 //restore the stak state
95 MMpull(m);
96
97 const SAnimTrackList animationsTracksListCopy = newAnimation->GetAnimationsTracks();
98 SAnimTrackList::const_iterator iAnimationTrack = animationsTracksListCopy.begin();
99 while (iAnimationTrack != animationsTracksListCopy.end())
100 {
101 SAnimTrack* newAnimationTrack = (*iAnimationTrack);
102 assert(newAnimationTrack != 0);
103 createAnimTrack(m, newAnimationTrack, newAnimation);
104
105 //restore the stak state
106 MMpull(m);
107
108 iAnimationTrack++;
109 }
110 }
111 iAnimation++;
112 }
113 return 0;
114}
115
116
128int SO3SceneLoadEntity(mmachine m)
129{
130#ifdef SO3_DEBUG
131 MMechostr(MSKDEBUG, "SO3SceneLoadEntity\n");
132#endif
133
134 int p = MMpull(m);
135 int name = MMpull(m);
136 int group = MMpull(m);
137 int s = MMpull(m);
138
139 if ((p == NIL) || (s == NIL) || (name == NIL))
140 {
141 MMpush(m, NIL);
142 return 0;
143 }
144
145 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
146 if (scene == NULL)
147 {
148 MMpush(m, NIL);
149 return 0;
150 }
151
152 std::string tmpEntityName = MMstartstr(m, MTOP(name));
153 std::string tmpMeshName = MMstartstr(m, MTOP(p));
154
155 for (unsigned int i = 0; i < tmpMeshName.length(); i++)
156 {
157 if (tmpMeshName.substr(i, 1) == "\\")
158 tmpMeshName.replace(i, 1, "/");
159 }
160
161 std::string groupResource(Ogre::RGN_DEFAULT);
162 if (group != NIL)
163 groupResource = MMstartstr(m, MTOP(group));
164
165 groupResource = scene->GetName() + groupResource;
166
167 SEntity* newEntity = 0;
168 int k = 0;
169 try
170 {
171 newEntity = scene->CreateEntity(groupResource, tmpEntityName, tmpMeshName);
172 k = createObject(m, newEntity, scene);
173
174 // Create Scol Animations Object from entity SAnim.
175 createEntinyAnimationsScol(m, newEntity);
176 }
177 catch (SO3::SException &e)
178 {
179 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
180 MMpush(m, NIL);
181 return 0;
182 }
183 catch (Ogre::Exception &e)
184 {
185 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
186 MMpush(m, NIL);
187 return 0;
188 }
189
190 return k;
191}
192
207{
208#ifdef SO3_DEBUG
209 MMechostr(MSKDEBUG, "SO3SceneLoadEntityInBackground\n");
210#endif
211
212 int pUser = MMpull(m);
213 int pCbk = MMpull(m);
214 int p = MMpull(m);
215 int name = MMpull(m);
216 int group = MMpull(m);
217 int s = MMpull(m);
218
219 if ((p == NIL) || (s == NIL) || (name == NIL))
220 {
221 MMpush(m, NIL);
222 return 0;
223 }
224
225 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
226 if (scene == NULL)
227 {
228 MMpush(m, NIL);
229 return 0;
230 }
231
232 std::string tmpEntityName = MMstartstr(m, MTOP(name));
233 std::string tmpMeshName = MMstartstr(m, MTOP(p));
234
235 for (unsigned int i = 0; i < tmpMeshName.length(); i++)
236 {
237 if (tmpMeshName.substr(i, 1) == "\\")
238 tmpMeshName.replace(i, 1, "/");
239 }
240
241 std::string groupResource(Ogre::RGN_DEFAULT);
242 if (group != NIL)
243 groupResource = MMstartstr(m, MTOP(group));
244
245 groupResource = scene->GetName() + groupResource;
246
247 SEntity* newEntity = 0;
248 int k = 0;
249 try
250 {
251 newEntity = scene->CreateEntity(groupResource, tmpEntityName, tmpMeshName, true);
252 k = createObject(m, newEntity, scene);
253 }
254 catch (SO3::SException &e)
255 {
256 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
257 MMpush(m, NIL);
258 return 0;
259 }
260 catch (Ogre::Exception &e)
261 {
262 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
263 MMpush(m, NIL);
264 return 0;
265 }
266
267 /*2 : object
268 1 : cbfun
269 0 : argument u0
270 */
271 MMpush(m, pCbk);
272 MMpush(m, pUser);
273
274 k = OBJaddreflex(m, SO3OBJTYPE, SO3_OBJECT_LOADED_EVENT);
275
276 newEntity->LoadAsync();
277
278 return k;
279}
280
293{
294#ifdef SO3_DEBUG
295 MMechostr(MSKDEBUG, "SO3SceneLoadEntityByResourceName\n");
296#endif
297
298 int p = MMpull(m);
299 int name = MMpull(m);
300 int group = MMpull(m);
301 int s = MMpull(m);
302
303 if ((p == NIL) || (s == NIL) || (name == NIL))
304 {
305 MMpush(m, NIL);
306 return 0;
307 }
308
309 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
310 if (scene == NULL)
311 {
312 MMpush(m, NIL);
313 return 0;
314 }
315
316 std::string tmpEntityName = MMstartstr(m, MTOP(name));
317 std::string tmpMeshName = MMstartstr(m, MTOP(p));
318
319 for (unsigned int i = 0; i < tmpMeshName.length(); i++)
320 {
321 if (tmpMeshName.substr(i, 1) == "\\")
322 tmpMeshName.replace(i, 1, "/");
323 }
324
325 std::string groupResource(Ogre::RGN_DEFAULT);
326 if (group != NIL)
327 groupResource = MMstartstr(m, MTOP(group));
328
329 groupResource = scene->GetName() + groupResource;
330
331 SEntity* newEntity = 0;
332 int k = 0;
333 try
334 {
335 newEntity = scene->CreateEntity(groupResource, tmpEntityName, tmpMeshName);
336 k = createObject(m, newEntity, scene);
337
338 // Create Scol Animations Object from entity SAnim.
339 createEntinyAnimationsScol(m, newEntity);
340 }
341 catch (SO3::SException &e)
342 {
343 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
344 MMpush(m, NIL);
345 return 0;
346 }
347 catch (Ogre::Exception &e)
348 {
349 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
350 MMpush(m, NIL);
351 return 0;
352 }
353
354 return k;
355}
356
367int SO3SceneCloneEntity(mmachine m)
368{
369#ifdef SO3_DEBUG
370 MMechostr(MSKDEBUG, "SO3SceneCloneEntity\n");
371#endif
372
373 int obj = MMpull(m);
374 int name = MMpull(m);
375 int s = MMpull(m);
376
377 if ((obj == NIL) || (s == NIL) || (name == NIL))
378 {
379 MMpush(m, NIL);
380 return 0;
381 }
382
383 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
384 if (scene == NULL)
385 {
386 MMpush(m, NIL);
387 return 0;
388 }
389
390 std::string entityName = MMstartstr(m, MTOP(name));
391 SNode* node = MMgetPointer<SNode*>(m, MTOP(obj));
392 if (node == NULL)
393 {
394 MMpush(m, NIL);
395 return 0;
396 }
397
398 if (node->GetNodeType() != SNode::ENTITY_TYPE_ID)
399 {
400 MMpush(m, NIL);
401 return 0;
402 }
403
404 SEntity* entity = static_cast <SEntity*> (node);
405 if (!entity)
406 {
407 MMpush(m, NIL);
408 return 0;
409 }
410
411 SEntity* newEntity = 0;
412 int k = 0;
413 try
414 {
415 newEntity = scene->CloneEntity(entityName, entity);
416 k = createObject(m, newEntity, scene);
417
418 // Create Scol Animations Object from entity SAnim.
419 createEntinyAnimationsScol(m, newEntity);
420 }
421 catch (SO3::SException &e)
422 {
423 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
424 MMpush(m, NIL);
425 return 0;
426 }
427 catch (Ogre::Exception &e)
428 {
429 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
430 MMpush(m, NIL);
431 return 0;
432 }
433
434 return k;
435}
436
447int SO3SceneConvertFile(mmachine m)
448{
449#ifdef SO3_DEBUG
450 MMechostr(MSKDEBUG, "SO3SceneConvertFile\n");
451#endif
452
453 int flags = MMpull(m);
454 int expPath = MMpull(m);
455 int p = MMpull(m);
456
457 if (p == NIL)
458 {
459 MMpush(m, NIL);
460 return 0;
461 }
462
463 packdir mypack = (packdir)SCgetExtra("FirstPack");
464 boost::filesystem::path partitionPath(mypack->path);
465 partitionPath = partitionPath.generic_string();
466
467 std::string dir(MMstartstr(m, MTOP(expPath)));
468 boost::filesystem::path exportDirectory(dir);
469 exportDirectory = exportDirectory.generic_string();
470 partitionPath /= exportDirectory;
471
472 /*
473 if(exportDirectory.is_relative() && partitionPath.is_absolute())
474 partitionPath = boost::filesystem::canonical(exportDirectory, partitionPath);
475 */
476
477 std::string fPath = MMstartstr(m, MTOP(p));
478
479 for (unsigned int i = 0; i < fPath.length(); i++)
480 {
481 if (fPath.substr(i, 1) == "\\")
482 fPath.replace(i, 1, "/");
483 }
484
485 std::string sceneName = boost::filesystem::path(fPath).stem().generic_string();
486 for (unsigned int i = 0; i < sceneName.length(); i++)
487 {
488 if (sceneName.substr(i, 1) == " ")
489 sceneName.replace(i, 1, "_");
490 }
491
492 // add a sub directory with filename
493 partitionPath /= sceneName;
494
495 boost::filesystem::path filePath = partitionPath;
496 filePath /= sceneName + ".scene";
497
498 if (flags == NIL)
499 flags = 0;
500 else
501 flags = MTOI(flags);
502
503 std::string resgroup = "SO3CONVERTER/" + sceneName;
504 bool success = false;
505
506 try
507 {
508 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(resgroup, false);
509 }
510 catch (Ogre::Exception &e)
511 {
512 MMechostr(MSKDEBUG, "Resource group already exist?: %s\n", e.what());
513 MMpush(m, NIL);
514 return 0;
515 }
516
517 try
518 {
519 ALSceneLoader alLoader(fPath, resgroup, flags);
520 success = alLoader.convertFile(partitionPath, sceneName);
521 }
522 catch (std::exception &e)
523 {
524 try
525 {
526 Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup(resgroup);
527 }
528 catch (Ogre::Exception &)
529 {
530 }
531 MMechostr(MSKDEBUG, "SO3SceneConvertFile : An exception has occurred: %s\n", e.what());
532 MMpush(m, NIL);
533 return 0;
534 }
535
536 try
537 {
538 Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup(resgroup);
539 }
540 catch (Ogre::Exception &e)
541 {
542 MMechostr(MSKDEBUG, "Resource group already deleted?: %s\n", e.what());
543 MMpush(m, NIL);
544 return 0;
545 }
546
547 if (success)
548 Mpushstrbloc(m, (char*)filePath.generic_string().c_str());
549 else
550 MMpush(m, NIL);
551
552 return 0;
553}
554
567int SO3SceneLoadFile(mmachine m)
568{
569#ifdef SO3_DEBUG
570 MMechostr(MSKDEBUG, "SO3SceneLoadFile\n");
571#endif
572
573 int flags = MMpull(m);
574 int n = MMpull(m);
575 int p = MMpull(m);
576 int group = MMpull(m);
577 int s = MMpull(m);
578
579 if ((p == NIL) || (s == NIL) || (n == NIL))
580 {
581 MMpush(m, NIL);
582 return 0;
583 }
584
585 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
586 if (scene == NULL)
587 {
588 MMpush(m, NIL);
589 return 0;
590 }
591
592 SNode* node = 0;
593 node = MMgetPointer<SNode*>(m, MTOP(n));
594 if (node == NULL)
595 {
596 MMpush(m, NIL);
597 return 0;
598 }
599
600 std::string fPath = MMstartstr(m, MTOP(p));
601
602 for (unsigned int i = 0; i < fPath.length(); i++)
603 {
604 if (fPath.substr(i, 1) == "\\")
605 fPath.replace(i, 1, "/");
606 }
607
608 std::string groupResource(Ogre::RGN_DEFAULT);
609 if (group != NIL)
610 groupResource = MMstartstr(m, MTOP(group));
611
612 groupResource = scene->GetName() + groupResource;
613 std::string sceneName = "";
614
615 if ((fPath.find("content://") != std::string::npos) || (fPath.find("file://") != std::string::npos))
616 sceneName = boost::filesystem::path(fPath.substr(fPath.find_last_of(":") + 1)).stem().generic_string();
617 else
618 sceneName = boost::filesystem::path(fPath).stem().generic_string();
619
620 if (flags == NIL)
621 flags = 0;
622 else
623 flags = MTOI(flags);
624
625 int k = 0;
626 std::vector<SNode*> objectToLoad;
627 std::vector<SMaterial*> matsToLoad;
628 try
629 {
630 ALSceneLoader alLoader(scene, fPath, groupResource, flags);
631
632 if (!alLoader.loadFile(sceneName, node, objectToLoad, matsToLoad))
633 {
634 MMechostr(MSKRUNTIME, "SO3SceneLoadFile : File not valid: %s\n", fPath.c_str());
635 MMpush(m, NIL);
636 return 0;
637 }
638
639 //materials are created on demand
640
641 for (unsigned int n = 0; n < objectToLoad.size(); ++n)
642 {
643 //ignore root node
644 if ((scene->GetRootNode() != objectToLoad[n]) && (node != objectToLoad[n]))
645 {
646 k = createObject(m, objectToLoad[n], scene);
647 MMpull(m);
648
649 if ((objectToLoad[n]->GetNodeType() == SNode::ENTITY_TYPE_ID))
650 {
651 SEntity* entity = static_cast<SEntity*>(objectToLoad[n]);
652
653 //check skeleton
654 if (entity && entity->getOgreEntityPointer() && entity->getOgreEntityPointer()->getSkeleton())
655 {
656 string tmpSkeletonName = entity->GetName() + "." + entity->getOgreEntityPointer()->getSkeleton()->getName();
657 SSkeleton* newSkeleton = 0;
658 try
659 {
660 newSkeleton = scene->CreateSkeleton(tmpSkeletonName, entity);
661
662 // Create Scol Bones Object from skeleton SBone.
663 SBoneMap bonesListCopy = newSkeleton->GetBones();
664 SBoneMap::iterator iBone = bonesListCopy.begin();
665 while (iBone != bonesListCopy.end())
666 {
667 SBone* newBone = iBone->second;
668 assert(newBone != 0);
669 createBone(m, (SNode*)newBone, scene, entity);
670 //restore the stak state
671 MMpull(m);
672
673 iBone++;
674 }
675
676 // Create Scol Animations Object from skeleton SAnim.
677 const SAnimMap animations = newSkeleton->GetAnimations();
678 SAnimMap::const_iterator iAnimation = animations.begin();
679 while (iAnimation != animations.end())
680 {
681 SAnim* newAnimation = iAnimation->second;
682 assert(newAnimation != 0);
683 createAnim(m, newAnimation, entity);
684 //restore the stak state
685 MMpull(m);
686
687 const SAnimTrackList animationsTracksListCopy = newAnimation->GetAnimationsTracks();
688 SAnimTrackList::const_iterator iAnimationTrack = animationsTracksListCopy.begin();
689 while (iAnimationTrack != animationsTracksListCopy.end())
690 {
691 SAnimTrack* newAnimationTrack = (*iAnimationTrack);
692 assert(newAnimationTrack != 0);
693 createAnimTrack(m, newAnimationTrack, newAnimation);
694 //restore the stak state
695 MMpull(m);
696
697 iAnimationTrack++;
698 }
699 newAnimation->SetLoop(true);
700 newAnimation->SetEnable(true);
701 iAnimation++;
702 }
703 }
704 catch (SO3::SException &)
705 {
706 }
707 catch (Ogre::Exception &)
708 {
709 }
710 }
711 }
712
713 //create node animations
714 for (unsigned int a = 0; a < objectToLoad[n]->GetNumAnimations(); ++a)
715 {
716 SAnim* animation = objectToLoad[n]->GetAnimation(a);
717 createAnim(m, animation, objectToLoad[n]);
718 MMpull(m);
719
720 animation->SetLoop(true);
721 animation->SetEnable(true);
722
723 for (unsigned int t = 0; t < animation->GetNumAnimationsTracks(); ++t)
724 {
725 createAnimTrack(m, animation->GetAnimationTrack(t), animation);
726 MMpull(m);
727 }
728 }
729 }
730 }
731 }
732 catch (Ogre::Exception &e)
733 {
734 //TODO should cleanup all the loaded contents ?
735 MMechostr(MSKDEBUG, "SO3SceneLoadFile : An exception has occurred: %s\n", e.what());
736 MMpush(m, NIL);
737 return 0;
738 }
739
740 if (objectToLoad.size() == 0)
741 {
742 MMechostr(MSKDEBUG, "SO3SceneLoadFile : Unsupported format or nothing to load\n");
743 MMpush(m, NIL);
744 }
745 else
746 {
747 MMpush(m, ITOM(1));
748 }
749
750 return k;
751}
752
765{
766#ifdef SO3_DEBUG
767 MMechostr(MSKDEBUG, "SO3SceneConvertFileEx\n");
768#endif
769
770 int scale = MMpull(m);
771 int flags = MMpull(m);
772 int expPath = MMpull(m);
773 int p = MMpull(m);
774
775 if (p == NIL)
776 {
777 MMpush(m, NIL);
778 return 0;
779 }
780
781 packdir mypack = (packdir)SCgetExtra("FirstPack");
782 boost::filesystem::path partitionPath(mypack->path);
783 partitionPath = partitionPath.generic_string();
784
785 std::string dir(MMstartstr(m, MTOP(expPath)));
786 boost::filesystem::path exportDirectory(dir);
787 exportDirectory = exportDirectory.generic_string();
788 partitionPath /= exportDirectory;
789
790 /*
791 if(exportDirectory.is_relative() && partitionPath.is_absolute())
792 partitionPath = boost::filesystem::canonical(exportDirectory, partitionPath);
793 */
794
795 std::string fPath = MMstartstr(m, MTOP(p));
796
797 for (unsigned int i = 0; i < fPath.length(); i++)
798 {
799 if (fPath.substr(i, 1) == "\\")
800 fPath.replace(i, 1, "/");
801 }
802
803 std::string sceneName = ALStringCleaner::cleanString(boost::filesystem::path(fPath).stem().generic_string(), true, true, true, false);
804
805 // add a sub directory with filename
806 partitionPath /= sceneName;
807
808 boost::filesystem::path filePath = partitionPath;
809 filePath /= sceneName + ".scene";
810
811 if (flags == NIL)
812 flags = 0;
813 else
814 flags = MTOI(flags);
815
816 float fscale = 1.0f;
817 if (scale != NIL)
818 fscale = MTOF(scale);
819
820 std::string resgroup = "SO3CONVERTER/" + sceneName;
821 bool success = false;
822
823 try
824 {
825 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(resgroup, false);
826 }
827 catch (Ogre::Exception &e)
828 {
829 MMechostr(MSKDEBUG, "Resource group already exist?: %s\n", e.what());
830 MMpush(m, NIL);
831 return 0;
832 }
833
834 try
835 {
836 ALSceneLoader alLoader(fPath, resgroup, flags, fscale);
837 success = alLoader.convertFile(partitionPath, sceneName);
838 }
839 catch (std::exception &e)
840 {
841 try
842 {
843 Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup(resgroup);
844 }
845 catch (Ogre::Exception &)
846 {
847 }
848
849 MMechostr(MSKDEBUG, "SO3SceneConvertFile : An exception has occurred: %s\n", e.what());
850 MMpush(m, NIL);
851 return 0;
852 }
853
854 try
855 {
856 Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup(resgroup);
857 }
858 catch (Ogre::Exception &e)
859 {
860 MMechostr(MSKDEBUG, "Resource group already deleted?: %s\n", e.what());
861 MMpush(m, NIL);
862 return 0;
863 }
864
865 if (success)
866 Mpushstrbloc(m, (char*)filePath.generic_string().c_str());
867 else
868 MMpush(m, NIL);
869
870 return 0;
871}
872
886int SO3SceneLoadFileEx(mmachine m)
887{
888#ifdef SO3_DEBUG
889 MMechostr(MSKDEBUG, "SO3SceneLoadFileEx\n");
890#endif
891
892 int scale = MMpull(m);
893 int flags = MMpull(m);
894 int n = MMpull(m);
895 int p = MMpull(m);
896 int group = MMpull(m);
897 int s = MMpull(m);
898
899 if ((p == NIL) || (s == NIL) || (n == NIL))
900 {
901 MMpush(m, NIL);
902 return 0;
903 }
904
905 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
906 if (scene == NULL)
907 {
908 MMpush(m, NIL);
909 return 0;
910 }
911
912 SNode* node = 0;
913 node = MMgetPointer<SNode*>(m, MTOP(n));
914 if (node == NULL)
915 {
916 MMpush(m, NIL);
917 return 0;
918 }
919
920 std::string fPath = MMstartstr(m, MTOP(p));
921
922 for (unsigned int i = 0; i < fPath.length(); i++)
923 {
924 if (fPath.substr(i, 1) == "\\")
925 fPath.replace(i, 1, "/");
926 }
927
928 std::string groupResource(Ogre::RGN_DEFAULT);
929 if (group != NIL)
930 groupResource = MMstartstr(m, MTOP(group));
931
932 groupResource = scene->GetName() + groupResource;
933
934 std::string sceneName = boost::filesystem::path(fPath).stem().generic_string();
935
936 if (flags == NIL)
937 flags = 0;
938 else
939 flags = MTOI(flags);
940
941 float fscale = 1.0f;
942 if (scale != NIL)
943 fscale = MTOF(scale);
944
945 int k = 0;
946 std::vector<SNode*> objectToLoad;
947 std::vector<SMaterial*> matsToLoad;
948 try
949 {
950 ALSceneLoader alLoader(scene, fPath, groupResource, flags, fscale);
951
952 if (!alLoader.loadFile(sceneName, node, objectToLoad, matsToLoad))
953 {
954 MMechostr(MSKRUNTIME, "SO3SceneLoadFileEx : File not valid: %s\n", fPath.c_str());
955 MMpush(m, NIL);
956 return 0;
957 }
958
959 //materials are created on demand
960
961 for (unsigned int n = 0; n < objectToLoad.size(); ++n)
962 {
963 //ignore root node
964 if ((scene->GetRootNode() != objectToLoad[n]) && (node != objectToLoad[n]))
965 {
966 k = createObject(m, objectToLoad[n], scene);
967 MMpull(m);
968
969 if ((objectToLoad[n]->GetNodeType() == SNode::ENTITY_TYPE_ID))
970 {
971 SEntity* entity = static_cast<SEntity*>(objectToLoad[n]);
972
973 //check skeleton
974 if (entity && entity->getOgreEntityPointer() && entity->getOgreEntityPointer()->getSkeleton())
975 {
976 string tmpSkeletonName = entity->GetName() + "." + entity->getOgreEntityPointer()->getSkeleton()->getName();
977 SSkeleton* newSkeleton = 0;
978 try
979 {
980 newSkeleton = scene->CreateSkeleton(tmpSkeletonName, entity);
981
982 // Create Scol Bones Object from skeleton SBone.
983 SBoneMap bonesListCopy = newSkeleton->GetBones();
984 SBoneMap::iterator iBone = bonesListCopy.begin();
985 while (iBone != bonesListCopy.end())
986 {
987 SBone* newBone = iBone->second;
988 assert(newBone != 0);
989 createBone(m, (SNode*)newBone, scene, entity);
990 //restore the stak state
991 MMpull(m);
992
993 iBone++;
994 }
995
996 // Create Scol Animations Object from skeleton SAnim.
997 const SAnimMap animations = newSkeleton->GetAnimations();
998 SAnimMap::const_iterator iAnimation = animations.begin();
999 while (iAnimation != animations.end())
1000 {
1001 SAnim* newAnimation = iAnimation->second;
1002 assert(newAnimation != 0);
1003 createAnim(m, newAnimation, entity);
1004 //restore the stak state
1005 MMpull(m);
1006
1007 const SAnimTrackList animationsTracksListCopy = newAnimation->GetAnimationsTracks();
1008 SAnimTrackList::const_iterator iAnimationTrack = animationsTracksListCopy.begin();
1009 while (iAnimationTrack != animationsTracksListCopy.end())
1010 {
1011 SAnimTrack* newAnimationTrack = (*iAnimationTrack);
1012 assert(newAnimationTrack != 0);
1013 createAnimTrack(m, newAnimationTrack, newAnimation);
1014 //restore the stak state
1015 MMpull(m);
1016
1017 iAnimationTrack++;
1018 }
1019 newAnimation->SetLoop(true);
1020 newAnimation->SetEnable(true);
1021 iAnimation++;
1022 }
1023 }
1024 catch (SO3::SException &)
1025 {
1026 }
1027 catch (Ogre::Exception &)
1028 {
1029 }
1030 }
1031 }
1032
1033 //create node animations
1034 for (unsigned int a = 0; a < objectToLoad[n]->GetNumAnimations(); ++a)
1035 {
1036 SAnim* animation = objectToLoad[n]->GetAnimation(a);
1037 createAnim(m, animation, objectToLoad[n]);
1038 MMpull(m);
1039
1040 animation->SetLoop(true);
1041 animation->SetEnable(true);
1042
1043 for (unsigned int t = 0; t < animation->GetNumAnimationsTracks(); ++t)
1044 {
1045 createAnimTrack(m, animation->GetAnimationTrack(t), animation);
1046 MMpull(m);
1047 }
1048 }
1049 }
1050 }
1051 }
1052 catch (Ogre::Exception &e)
1053 {
1054 //TODO should cleanup all the loaded contents ?
1055 MMechostr(MSKDEBUG, "SO3SceneLoadFileEx : An exception has occurred: %s\n", e.what());
1056 MMpush(m, NIL);
1057 return 0;
1058 }
1059
1060 if (objectToLoad.size() == 0)
1061 {
1062 MMechostr(MSKDEBUG, "SO3SceneLoadFileEx : Unsupported format or nothing to load\n");
1063 MMpush(m, NIL);
1064 }
1065 else
1066 {
1067 MMpush(m, ITOM(1));
1068 }
1069
1070 return k;
1071}
1072
1084{
1085#ifdef SO3_DEBUG
1086 MMechostr(MSKDEBUG, "SO3SceneUnloadResource\n");
1087#endif
1088
1089 int type = MTOI(MMpull(m));
1090 int p = MMpull(m);
1091 int s = MMget(m, 0);
1092
1093 if ((p == NIL) || (s == NIL))
1094 {
1095 MMset(m, 0, NIL);
1096 return 0;
1097 }
1098
1099 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
1100 if (scene == NULL)
1101 {
1102 MMset(m, 0, NIL);
1103 return 0;
1104 }
1105
1106 /*
1107 string pathStd = MMstartstr(m, MTOP(p));
1108
1109 try
1110 {
1111 Ogre::ResourcePtr res;
1112 if(type == SO3_RESOURCE_MESH)
1113 {
1114 if(!scene->O3MeshManager->getByName(pathStd).isNull())
1115 {
1116 scene->O3MeshManager->unload(pathStd);
1117 scene->O3MeshManager->remove(pathStd);
1118 }
1119 }
1120 else if(type == SO3_RESOURCE_MATERIAL)
1121 {
1122 if(!scene->O3MaterialManager->getByName(pathStd).isNull())
1123 {
1124 scene->O3MaterialManager->unload(pathStd);
1125 scene->O3MaterialManager->remove(pathStd);
1126 }
1127 }
1128 else if(type == SO3_RESOURCE_TEXTURE)
1129 {
1130 if(!scene->O3TextureManager->getByName(pathStd).isNull())
1131 {
1132 scene->O3TextureManager->unload(pathStd);
1133 scene->O3TextureManager->remove(pathStd);
1134 }
1135 }
1136 else if(type == SO3_RESOURCE_SKELETON)
1137 {
1138 if(!scene->O3SkeletonManager->getByName(pathStd).isNull())
1139 {
1140 scene->O3SkeletonManager->unload(pathStd);
1141 scene->O3SkeletonManager->remove(pathStd);
1142 }
1143 }
1144 else if(type == SO3_RESOURCE_GPUPROGRAM)
1145 {
1146 if(!scene->O3GpuProgramManager->getByName(pathStd).isNull())
1147 {
1148 scene->O3GpuProgramManager->unload(pathStd);
1149 scene->O3GpuProgramManager->remove(pathStd);
1150 }
1151 }
1152 else if(type == SO3_RESOURCE_HIGHLEVELGPUPROGRAM)
1153 {
1154 if(!scene->O3HighLevelGpuProgramManager->getByName(pathStd).isNull())
1155 {
1156 scene->O3HighLevelGpuProgramManager->unload(pathStd);
1157 scene->O3HighLevelGpuProgramManager->remove(pathStd);
1158 }
1159 }
1160
1161 MMset(m, 0, ITOM(1));
1162 return 0;
1163 }
1164 catch( Exception &e )
1165 {
1166 MMechostr(MSKDEBUG,"An exception has occurred: %s\n",e.what());
1167 MMset(m,0,NIL);
1168 return 0;
1169 }
1170 */
1171 MMset(m, 0, ITOM(1));
1172 return 0;
1173}
1174
1175
1198{
1199#ifdef SO3_DEBUG
1200 MMechostr(MSKDEBUG, "SO3SceneLoadResource\n");
1201#endif
1202
1203 int type = MTOI(MMpull(m));
1204 int p = MMpull(m);
1205 int group = MMpull(m);
1206 int s = MMpull(m);
1207
1208 if ((p == NIL) || (s == NIL))
1209 {
1210 MMpush(m, NIL);
1211 return 0;
1212 }
1213
1214 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
1215 if (scene == NULL)
1216 {
1217 MMpush(m, NIL);
1218 return 0;
1219 }
1220
1221 string pathStd = MMstartstr(m, MTOP(p));
1222 for (unsigned int i = 0; i < pathStd.length(); i++)
1223 {
1224 if (pathStd.substr(i, 1) == "\\")
1225 pathStd.replace(i, 1, "/");
1226 }
1227
1228 std::string groupResource(Ogre::RGN_DEFAULT);
1229 if (group != NIL)
1230 groupResource = MMstartstr(m, MTOP(group));
1231
1232 groupResource = scene->GetName() + groupResource;
1233
1234 if (scene->ParseResourceScript(groupResource, pathStd, static_cast<SResource::ResourceType>(type)))
1235 {
1236 MMpush(m, ITOM(1));
1237 }
1238 else
1239 {
1240 MMechostr(MSKDEBUG, "Error when loading %s in group %s\n", pathStd.c_str(), groupResource.c_str());
1241 MMpush(m, NIL);
1242 }
1243 return 0;
1244}
1245
1246
1258{
1259#ifdef SO3_DEBUG
1260 MMechostr(MSKDEBUG, "SO3SceneCloneAnimation\n");
1261#endif
1262
1263 // $MS : TODO pass the node of the scene on which we defines newAnimation!!
1264 // return createAnim(m,animation,node);
1265 /*
1266 int p = MMpull(m);
1267 int anim = MMpull(m);
1268 int s = MMget(m,0);
1269 if((p==NIL)||(s==NIL))
1270 {
1271 MMset(m,0,NIL);
1272 return 0;
1273 }
1274 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
1275 if(scene==NULL)
1276 {
1277 MMset(m,0,NIL);
1278 return 0;
1279 }
1280 if(p == NIL)
1281 {
1282 MMset(m,0,NIL);
1283 return 0;
1284 }
1285 SAnim* animation = (SAnim*) MMfetch(m,MTOP(anim),0);
1286 if(animation==NULL)
1287 {
1288 MMset(m,0,NIL);
1289 return 0;
1290 }
1291
1292 try
1293 {
1294 // Creation of the animation clone
1295 Ogre::Animation* newAnim = animation->getOgreAnimationPointer()->clone(MMstartstr(m, MTOP(p)));
1296 // Declaration of the animation in the scene Manager
1297 newAnim = scene->O3SceneManager->createAnimation(MMstartstr(m, MTOP(p)),animation->getOgreAnimationPointer()->getLength());
1298 SAnim* newAnimation = new SAnim();
1299 newAnimation->type = animation->type;
1300 newAnimation->setOgreAnimationPointer(newAnim);
1301 scene->listOfAnim.Add(newAnimation);
1302 return createAnim(m,animation, NULL);
1303 }
1304 catch( Exception &e )
1305 {
1306 MMechostr(MSKDEBUG,"An exception has occurred: %s\n",e.what());
1307 MMset(m,0,NIL);
1308 return 0;
1309 }
1310 */
1311 return 0;
1312}
1313
1314
1327{
1328#ifdef SO3_DEBUG
1329 MMechostr(MSKDEBUG, "SO3SceneCloneAnimTrack\n");
1330#endif
1331 MMechostr(MSKRUNTIME, "DEPRECATED FUNCTION Call: SO3SceneCloneAnimTrack\n");
1332
1333 int at = MMpull(m);
1334 int anim = MMpull(m);
1335 int n = MMpull(m);
1336 int s = MMget(m, 0);
1337
1338 MMset(m, 0, NIL);
1339 return 0;
1340}
1341
1342
1354//TODO REMOVE ?
1356{
1357#ifdef SO3_DEBUG
1358 MMechostr(MSKDEBUG, "SO3SceneLoadResourceMaterial\n");
1359#endif
1360
1361 int p = MMpull(m);
1362 int group = MMpull(m);
1363 int s = MMget(m, 0);
1364
1365 if ((p == NIL) || (s == NIL))
1366 {
1367 MMset(m, 0, NIL);
1368 return 0;
1369 }
1370
1371 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
1372 if (scene == NULL)
1373 {
1374 MMset(m, 0, NIL);
1375 return 0;
1376 }
1377
1378 string pathStd = MMstartstr(m, MTOP(p));
1379 string::size_type pos = pathStd.rfind("/");
1380 string resourceLocation = pathStd.substr(0, pos + 1);
1381 string resource = pathStd.substr(pos + 1, pathStd.length() - 1);
1382
1383 std::string groupResource(Ogre::RGN_DEFAULT);
1384 if (group != NIL)
1385 groupResource = MMstartstr(m, MTOP(group));
1386
1387 groupResource = scene->GetName() + groupResource;
1388
1389 try
1390 {
1391 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(resourceLocation, "ScolFileSystem", groupResource);
1392 Ogre::DataStreamPtr ds = Ogre::ResourceGroupManager::getSingleton().openResource(pathStd, groupResource);
1393 if (!ds)
1394 ds = Ogre::ResourceGroupManager::getSingleton().openResource(pathStd, Ogre::RGN_AUTODETECT);
1395
1396 scene->O3MaterialManager->parseScript(ds, groupResource);
1397 MMset(m, 0, ITOM(1));
1398 return 0;
1399 }
1400 catch (Ogre::Exception &e)
1401 {
1402 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
1403 MMset(m, 0, NIL);
1404 return 0;
1405 }
1406}
1407
1408
1419{
1420#ifdef SO3_DEBUG
1421 MMechostr(MSKDEBUG, "SO3SceneCreateAnimationSequence\n");
1422#endif
1423
1424 int name = MMpull(m);
1425 int s = MMpull(m);
1426 if ((name == NIL) || (s == NIL))
1427 {
1428 MMpush(m, NIL);
1429 return 0;
1430 }
1431
1432 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
1433 if (scene == NULL)
1434 {
1435 MMpush(m, NIL);
1436 return 0;
1437 }
1438
1439 try
1440 {
1441 std::string animationName(MMstartstr(m, MTOP(name)));
1442 SAnim* animation = scene->CreateAnimationSequence(animationName);
1443
1444 //get scene scol object
1445 int p = OBJfindTH(m, SO3SCENETYPE, SCOL_PTR scene);
1446 // push channel
1447 MMpush(m, MMfetch(m, p, OFFOBJCHN));
1448
1449 if ((MMpushPointer(m, animation) != 0))
1450 {
1451 return MERRMEM;
1452 }
1453
1454 return OBJcreate(m, SO3ANIM, SCOL_PTR animation, SO3SCENETYPE, SCOL_PTR scene);
1455 }
1456 catch (SO3::SException &e)
1457 {
1458 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
1459 MMpush(m, NIL);
1460 return 0;
1461 }
1462 catch (Ogre::Exception &e)
1463 {
1464 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
1465 MMpush(m, NIL);
1466 return 0;
1467 }
1468}
1469
1470
1480int SO3SceneCreate(mmachine m)
1481{
1482#ifdef SO3_DEBUG
1483 MMechostr(MSKDEBUG, "SO3SceneCreate\n");
1484#endif
1485
1486 int name = MMpull(m);
1487 int channel = MMget(m, 0);
1488
1489 // Checking inputs parameters.
1490 if (name == NIL || channel == NIL)
1491 {
1492 MMset(m, 0, NIL);
1493 return 0;
1494 }
1495
1496 if (!SRoot::getSingleton().IsRenderInitialised())
1497 {
1498 MMechostr(MSKRUNTIME, "SO3SceneCreate Error: Create a window first to initialise ressources.");
1499 MMset(m, 0, NIL);
1500 return 0;
1501 }
1502
1503 // Creating the SO3Object.
1504 const char* sceneName = MMstartstr(m, MTOP(name));
1505 SScene* newScene = 0;
1506 try
1507 {
1508 newScene = scolRoot->CreateScene(sceneName);
1509 }
1510 catch (Ogre::Exception &e)
1511 {
1512 SAFE_DELETE(newScene);
1513 MMechostr(MSKDEBUG, "An exception has occurred: %s\nCreate a buffer first\n", e.what());
1514 MMset(m, 0, NIL);
1515 return 0;
1516 }
1517
1518 packdir mypack = (packdir)SCgetExtra("FirstPack");
1519 string pathStd;
1520 std::vector<string> partitions;
1521
1522 while (mypack)
1523 {
1524 pathStd = mypack->path;
1525 for (unsigned int i = 0; i < pathStd.length(); i++)
1526 {
1527 if (pathStd.substr(i, 1) == "\\")
1528 pathStd.replace(i, 1, "/");
1529 }
1530 partitions.push_back(pathStd);
1531 mypack = mypack->next;
1532 }
1533
1534 std::string groupResource = newScene->GetName() + Ogre::RGN_DEFAULT;
1535 std::vector<string>::iterator iPartition = partitions.begin();
1536 while (iPartition != partitions.end())
1537 {
1538 Ogre::ResourceGroupManager::getSingleton().addResourceLocation((*iPartition), "ScolFileSystem", groupResource, false);
1539
1540 iPartition++;
1541 }
1542
1543 // Allocating memory for the Scene Scol Object.
1544 if ((MMpushPointer(m, newScene) != 0))
1545 {
1546 MMset(m, 0, NIL);
1547 return MERRMEM;
1548 }
1549
1550 // Creating the Scol Scene Object.
1551 int scolSceneCreationReturn = OBJcreate(m, SO3SCENETYPE, SCOL_PTR newScene, NIL, 0);
1552
1553 // Get the SO3 root node.
1554 SNode* rootNode = newScene->GetRootNode();
1555
1556 // Initializing OBJcreate parameters for the root node.
1557 MMpush(m, channel);
1558
1559 if ((MMpushPointer(m, rootNode) != 0))
1560 {
1561 MMset(m, 0, NIL);
1562 return MERRMEM;
1563 }
1564
1565 // Creating the Scol node Object.
1566 OBJcreate(m, SO3OBJTYPE, SCOL_PTR rootNode, SO3SCENETYPE, SCOL_PTR newScene);
1567
1568 // Discard the last element in the stack, that is a SNode reference, and exiting the function leaving the SScene reference on the top of the stack.
1569 MMpull(m);
1570 return scolSceneCreationReturn;
1571}
1572
1573
1582int SO3SceneDelete(mmachine m)
1583{
1584#ifdef SO3_DEBUG
1585 MMechostr(MSKDEBUG, "SO3SceneDelete\n");
1586#endif
1587
1588 int s = MMget(m, 0);
1589 if (s == NIL)
1590 {
1591 MMset(m, 0, NIL);
1592 return 0;
1593 }
1594
1595 //$BB add destroyScene function and call it in OBJdel destroy callback
1596 OBJdelTM(m, SO3SCENETYPE, s);
1597 MMset(m, 0, ITOM(1));
1598 return 0;
1599}
1600
1601
1610int SO3SceneClear(mmachine m)
1611{
1612#ifdef SO3_DEBUG
1613 MMechostr(MSKDEBUG, "SO3SceneClear\n");
1614#endif
1615
1616 int s = MMget(m, 0);
1617 if (s == NIL)
1618 {
1619 MMset(m, 0, NIL);
1620 return 0;
1621 }
1622
1623 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
1624 if (scene == NULL)
1625 {
1626 MMset(m, 0, NIL);
1627 return 0;
1628 }
1629
1630 if (SRoot::getSingletonPtr()->IsRendering())
1631 {
1632 MMechostr(MSKRUNTIME, "SO3SceneClear: Can not be called in a render callback\n");
1633 MMset(m, 0, NIL);
1634 return 0;
1635 }
1636
1637 // Kill Stereo Mode && viewports
1638 const SWindowMap windowList = scolRoot->GetRenderWindowList();
1639 SWindowMap::const_iterator iWindowList = windowList.begin();
1640 while (iWindowList != windowList.end())
1641 {
1642 SWindow* curWin = iWindowList->second;
1643
1644 // Kill stereo
1645 curWin->SetStereoMode(StereoManager::SO3_NONE_STEREO);
1646
1647 // Kill compositors
1648 const SViewPortList sviewportList = curWin->GetViewportList();
1649 SViewPortList::const_iterator iViewportList = sviewportList.begin();
1650 while (iViewportList != sviewportList.end())
1651 {
1652 iViewportList->second->ClearCompositors();
1653 iViewportList++;
1654 }
1655 iWindowList++;
1656 }
1657
1658 // Destroy scol SO3MATERIAL objects. The list can be modified inside the loop by OBJdelTM function, so make a copy!
1659 const SGroupMaterialMap groupmatmap = (*scene->GetMaterials());
1660 SGroupMaterialMap::const_iterator iGroupMaterialList = groupmatmap.begin();
1661 while (iGroupMaterialList != groupmatmap.end())
1662 {
1663 // Make a copy of the map!
1664 const SMaterialMap matmap = (*iGroupMaterialList->second);
1665 SMaterialMap::const_iterator iMaterialList = matmap.begin();
1666 while (iMaterialList != matmap.end())
1667 {
1668 // Destroy scol SO3MATERIAL, it will destroy the associated SMaterial in cascade.
1669 OBJdelTH(m, SO3MATERIAL, SCOL_PTR(iMaterialList->second));
1670 iMaterialList++;
1671 }
1672 iGroupMaterialList++;
1673 }
1674
1675 // Destroy scol SO3TEXTURE objects. Make a copy of the list, because it can be modified inside the loop by OBJdelTM function.
1676 const SGroupTextureMap grouptexmap = (*scene->GetTextures());
1677 SGroupTextureMap::const_iterator iGroupTextureList = grouptexmap.begin();
1678 while (iGroupTextureList != grouptexmap.end())
1679 {
1680 // Make a copy of the map!
1681 const STextureMap texmap = (*iGroupTextureList->second);
1682 STextureMap::const_iterator iTextureList = texmap.begin();
1683 while (iTextureList != texmap.end())
1684 {
1685 // Destroy scol SO3TEXTURE, it will destroy the associated STexture in cascade.
1686 OBJdelTH(m, SO3TEXTURE, SCOL_PTR(iTextureList->second));
1687 iTextureList++;
1688 }
1689 iGroupTextureList++;
1690 }
1691
1692 // Destroy scol SO3PHYSICSMATERIALTYPE objects
1693 if (scene->GetPhysicsWorld())
1694 {
1695 const SMaterialIDMap physicMatIdList = scene->GetPhysicsWorld()->listOfMaterialID;
1696 SMaterialIDMap::const_iterator iMaterialIDList = physicMatIdList.begin();
1697 while (iMaterialIDList != physicMatIdList.end())
1698 {
1699 OBJdelTH(m, SO3PHYSICSMATERIALTYPE, SCOL_PTR(iMaterialIDList->second));
1700 iMaterialIDList++;
1701 }
1702 }
1703
1704 // Destroy scol SO3ANIM objects
1705 const SAnimMap seqAnimCopy = scene->GetAnimations();
1706 SAnimMap::const_iterator iSeqAnim = seqAnimCopy.begin();
1707 while (iSeqAnim != seqAnimCopy.end())
1708 {
1709 OBJdelTH(m, SO3ANIM, SCOL_PTR(iSeqAnim->second));
1710 iSeqAnim++;
1711 }
1712
1713 // Destroy scol SO3OBJTYPE objects
1714 const SNodeMap nodeListCopy = scene->GetNodeList();
1715 SNodeMap::const_iterator iNodeList = nodeListCopy.begin();
1716 while (iNodeList != nodeListCopy.end())
1717 {
1718 /*
1719 if (iNodeList->second->GetNodeType() == SNode::ENTITY_TYPE_ID)
1720 {
1721 SEntity* entity = static_cast<SEntity*>(iNodeList->second);
1722 entity->SetFreeResource(true);
1723 }
1724 */
1725 OBJdelTH(m, SO3OBJTYPE, SCOL_PTR(iNodeList->second));
1726 iNodeList++;
1727 }
1728
1729 // Destroy scol SO3OBJTYPE objects
1730 const STerrainMap terrainListCopy = scene->GetTerrainList();
1731 STerrainMap::const_iterator iTerrainList = terrainListCopy.begin();
1732 while (iTerrainList != terrainListCopy.end())
1733 {
1734 OBJdelTH(m, SO3TERRAINTYPE, SCOL_PTR(iTerrainList->second));
1735 iTerrainList++;
1736 }
1737
1738 if (scene->GetPhysicsWorld())
1739 {
1740 const PhysicContraintList jointList = scene->GetPhysicsWorld()->GetPhysicContraintList();
1741 PhysicContraintList::const_iterator jointIt;
1742 for (jointIt = jointList.begin(); jointIt != jointList.end(); ++jointIt)
1743 {
1744 OBJdelTH(m, SO3PHYSICCONTRAINT, SCOL_PTR(*jointIt));
1745 }
1746
1747 // TODO
1748 scene->GetPhysicsWorld()->listOfMaterialID.clear();
1749 scene->GetPhysicsWorld()->listOfPhysicsMaterialPair.clear();
1750 // TODO
1751 }
1752
1753 // Call clear function on SScene, because there's some SO3 objects that can still exist if they where not bounded to any scol object.
1754 scene->clearOgreScene();
1755 MMset(m, 0, ITOM(1));
1756 return 0;
1757}
1758
1759
1774int SO3SceneSetSkyBox(mmachine m)
1775{
1776#if SO3_DEBUG == 1
1777 MMechostr(MSKDEBUG, "SO3SceneSetSkyBox\n");
1778#endif
1779
1780 int drawFirst = MMpull(m);
1781 int enabled = MMpull(m);
1782 int group = MMpull(m);
1783 int orient = MTOP(MMpull(m));
1784 float dist = MTOF(MMpull(m));
1785 int mat = MMpull(m);
1786 int s = MMget(m, 0);
1787 if ((s == NIL) || (mat == NIL))
1788 {
1789 MMset(m, 0, NIL);
1790 return 0;
1791 }
1792
1793 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
1794 if (scene == 0)
1795 {
1796 MMset(m, 0, NIL);
1797 return 0;
1798 }
1799
1800 SMaterial * material = MMgetPointer<SMaterial*>(m, MTOP(mat));
1801 if (material == 0)
1802 {
1803 MMechostr(MSKDEBUG, "material==NULL\n");
1804 MMset(m, 0, NIL);
1805 return 0;
1806 }
1807
1808 bool isEnable = false;
1809 if (MTOI(enabled) == 1)
1810 isEnable = true;
1811
1812 bool isDrawFirst = false;
1813 if (MTOI(drawFirst) == 1)
1814 isDrawFirst = true;
1815
1816 std::string groupResource(Ogre::RGN_DEFAULT);
1817
1818 Ogre::Quaternion quat;
1819 if (orient == NIL)
1820 quat = Ogre::Quaternion::IDENTITY;
1821 else
1822 {
1823 quat.x = MTOF(MMfetch(m, orient, 0));
1824 quat.y = MTOF(MMfetch(m, orient, 1));
1825 quat.z = MTOF(MMfetch(m, orient, 2));
1826 quat.w = MTOF(MMfetch(m, orient, 3));
1827 }
1828 try
1829 {
1830 if (material->getOgreMaterialPointer())
1831 {
1832 // Destroy Older Material
1833 if (scene->skyBoxMat)
1834 {
1835 scene->O3MaterialManager->remove(scene->skyBoxMat->getName());
1836 scene->O3MaterialManager->unload(scene->skyBoxMat->getName());
1837 }
1838 // We add to create a copy of the material to avoid problem with shared materials
1839 // Create a copy of the current Ogre Material
1840 Ogre::MaterialPtr mCurrentMaterialPointer = material->getOgreMaterialPointer()->clone(scene->GetName() + "mSkyBoxMaterial_" + material->getOgreMaterialPointer()->getName(), groupResource);
1841 mCurrentMaterialPointer->setLightingEnabled(false);
1842
1843 scene->O3SceneManager->setSkyBox(isEnable, mCurrentMaterialPointer->getName(), dist, isDrawFirst, quat, groupResource);
1844 scene->skyBoxDrawFirst = isDrawFirst;
1845
1846 scene->hasSkyBox = true;
1847 scene->skyBoxMat = mCurrentMaterialPointer;
1848 }
1849 MMset(m, 0, ITOM(1));
1850 return 0;
1851 }
1852 catch (Ogre::Exception &e)
1853 {
1854 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
1855 MMset(m, 0, NIL);
1856 return 0;
1857 }
1858}
1859
1860
1871{
1872#if SO3_DEBUG == 1
1873 MMechostr(MSKDEBUG, "SO3SceneSetSkyBoxEnable\n");
1874#endif
1875
1876 int enabled = MMpull(m);
1877 int s = MMget(m, 0);
1878 if (s == NIL)
1879 {
1880 MMset(m, 0, NIL);
1881 return 0;
1882 }
1883
1884 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
1885 if (scene == NULL)
1886 {
1887 MMset(m, 0, NIL);
1888 return 0;
1889 }
1890
1891 if (!scene->skyBoxMat)
1892 {
1893 MMset(m, 0, NIL);
1894 return 0;
1895 }
1896
1897 try
1898 {
1899 if (scene->hasSkyBox)
1900 {
1901 if (scene->O3SceneManager->getSkyBoxNode() != 0)
1902 {
1903 if (MTOI(enabled) != 1)
1904 {
1905 scene->O3SceneManager->getSkyBoxNode()->setVisible(false);
1906 scene->O3SceneManager->setSkyBox(false, "");
1907 if (scene->skyBoxMat)
1908 {
1909 scene->O3MaterialManager->remove(scene->skyBoxMat->getName());
1910 scene->O3MaterialManager->unload(scene->skyBoxMat->getName());
1911 }
1912 }
1913 else
1914 {
1915 scene->O3SceneManager->getSkyBoxNode()->setVisible(true);
1916 scene->O3SceneManager->setSkyBox(true, scene->skyBoxMat->getName());
1917 }
1918 MMset(m, 0, ITOM(1));
1919 return 0;
1920 }
1921 }
1922 }
1923 catch (Ogre::Exception &e)
1924 {
1925 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
1926 }
1927
1928 MMset(m, 0, NIL);
1929 return 0;
1930}
1931
1932
1947{
1948#if SO3_DEBUG == 1
1949 MMechostr(MSKDEBUG, "SO3SceneGetSkyBoxParameters\n");
1950#endif
1951
1952 int s = MMget(m, 0);
1953 if (s == NIL)
1954 {
1955 MMset(m, 0, NIL);
1956 return 0;
1957 }
1958
1959 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
1960 if (scene == NULL)
1961 {
1962 MMset(m, 0, NIL);
1963 return 0;
1964 }
1965
1966 std::string groupResource(Ogre::RGN_DEFAULT);
1967
1968 try
1969 {
1970 if (scene->hasSkyBox)
1971 {
1972 // Getting material,bool and parameters
1973 //TODO GROUP / SKY Refacto
1974 SMaterial* curMat = scene->GetMaterial(groupResource, scene->skyBoxMat->getName().c_str());
1975 int mat = OBJfindTH(m, SO3MATERIAL, SCOL_PTR(curMat));
1976 if (mat != NIL)
1977 mat = MMfetch(m, mat, OFFOBJMAG);
1978 MMpush(m, mat);
1979
1980 float d = scene->O3SceneManager->getSkyBoxGenParameters().skyBoxDistance;
1981 MMpush(m, FTOM(d));
1982
1983 Ogre::Quaternion orient;
1984 orient = scene->O3SceneManager->getSkyBoxNode()->getOrientation();
1985 int rot = MMmalloc(m, 4, TYPETAB);
1986 if (rot == NIL)
1987 {
1988 MMset(m, 0, NIL);
1989 return MERRMEM;
1990 }
1991 MMstore(m, rot, 0, FTOM(orient.x));
1992 MMstore(m, rot, 1, FTOM(orient.y));
1993 MMstore(m, rot, 2, FTOM(orient.z));
1994 MMstore(m, rot, 3, FTOM(orient.w));
1995 MMpush(m, PTOM(rot));
1996
1997 int booleenEnable = 0;
1998 if (scene->O3SceneManager->isSkyBoxEnabled())
1999 booleenEnable = 1;
2000 MMpush(m, ITOM(booleenEnable));
2001
2002 int booleenDrawFirst = 0;
2003 if (scene->skyBoxDrawFirst)
2004 booleenDrawFirst = 1;
2005 MMpush(m, ITOM(booleenDrawFirst));
2006
2007
2008 int tuple = MMmalloc(m, 5, TYPETAB);
2009 if (tuple == NIL)
2010 {
2011 MMset(m, 0, NIL);
2012 return MERRMEM;
2013 }
2014 MMstore(m, tuple, 4, MMpull(m));
2015 MMstore(m, tuple, 3, MMpull(m));
2016 MMstore(m, tuple, 2, MMpull(m));
2017 MMstore(m, tuple, 1, MMpull(m));
2018 MMstore(m, tuple, 0, MMpull(m));
2019 MMset(m, 0, PTOM(tuple));
2020 return 0;
2021 }
2022 else
2023 {
2024 MMset(m, 0, NIL);
2025 return 0;
2026 }
2027 }
2028 catch (Ogre::Exception &e)
2029 {
2030 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
2031 MMset(m, 0, 0);
2032 return 0;
2033 }
2034}
2035
2036
2056int SO3SceneSetSkyDome(mmachine m)
2057{
2058#if SO3_DEBUG == 1
2059 MMechostr(MSKDEBUG, "SO3SceneSetSkyDome\n");
2060#endif
2061
2062 int drawFirst = MMpull(m);
2063 int enabled = MMpull(m);
2064 int group = MMpull(m);
2065 int yKeep = MTOI(MMpull(m));
2066 int ySeg = MTOI(MMpull(m));
2067 int xSeg = MTOI(MMpull(m));
2068 float tiling = MTOF(MMpull(m));
2069 float curvature = MTOF(MMpull(m));
2070 int orient = MTOP(MMpull(m));
2071 float dist = MTOF(MMpull(m));
2072 int mat = MMpull(m);
2073 int s = MMget(m, 0);
2074 if ((s == NIL) || (mat == NIL))
2075 {
2076 MMset(m, 0, NIL);
2077 return 0;
2078 }
2079
2080 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2081 if (scene == 0)
2082 {
2083 MMset(m, 0, NIL);
2084 return 0;
2085 }
2086
2087 SMaterial* material = MMgetPointer<SMaterial*>(m, MTOP(mat));
2088 if (material == 0)
2089 {
2090 MMechostr(MSKDEBUG, "SO3SceneSetSkyDome : material NULL\n");
2091 MMset(m, 0, NIL);
2092 return 0;
2093 }
2094
2095 std::string groupResource(Ogre::RGN_DEFAULT);
2096
2097 bool isEnable = false;
2098 if (MTOI(enabled) == 1)
2099 isEnable = true;
2100
2101 bool isDrawFirst = false;
2102 if (MTOI(drawFirst) == 1)
2103 isDrawFirst = true;
2104
2105 Ogre::Quaternion quat;
2106 if (orient == NIL)
2107 quat = Ogre::Quaternion::IDENTITY;
2108 else
2109 {
2110 quat.x = MTOF(MMfetch(m, orient, 0));
2111 quat.y = MTOF(MMfetch(m, orient, 1));
2112 quat.z = MTOF(MMfetch(m, orient, 2));
2113 quat.w = MTOF(MMfetch(m, orient, 3));
2114 }
2115 try
2116 {
2117 if (material->getOgreMaterialPointer())
2118 {
2119 // Destroy Older Material
2120 if (scene->skyDomeMat)
2121 {
2122 scene->O3MaterialManager->remove(scene->skyDomeMat->getName());
2123 scene->O3MaterialManager->unload(scene->skyDomeMat->getName());
2124 }
2125 // We add to create a copy of the material to avoid problem with shared materials
2126 // Create a copy of the current Ogre Material
2127 Ogre::MaterialPtr mCurrentMaterialPointer = material->getOgreMaterialPointer()->clone(scene->GetName() + "mSkyDomeMaterial_" + material->getOgreMaterialPointer()->getName(), groupResource);
2128 mCurrentMaterialPointer->setLightingEnabled(false);
2129 scene->skyDomeDrawFirst = isDrawFirst;
2130 scene->hasSkyDome = true;
2131 scene->skyDomeMat = mCurrentMaterialPointer;
2132 scene->O3SceneManager->setSkyDome(isEnable, mCurrentMaterialPointer->getName(), curvature, tiling, dist, isDrawFirst, quat, xSeg, ySeg, yKeep, groupResource);
2133 }
2134
2135 MMset(m, 0, ITOM(1));
2136 return 0;
2137 }
2138 catch (Ogre::Exception &e)
2139 {
2140 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
2141 MMset(m, 0, NIL);
2142 return 0;
2143 }
2144}
2145
2146
2157{
2158#if SO3_DEBUG == 1
2159 MMechostr(MSKDEBUG, "SO3SceneSetSkyDomeEnable\n");
2160#endif
2161
2162 int enabled = MMpull(m);
2163 int s = MMget(m, 0);
2164 if (s == NIL)
2165 {
2166 MMset(m, 0, NIL);
2167 return 0;
2168 }
2169
2170 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2171 if (scene == 0)
2172 {
2173 MMset(m, 0, NIL);
2174 return 0;
2175 }
2176
2177 try
2178 {
2179 if (scene->hasSkyDome)
2180 {
2181 if (scene->O3SceneManager->getSkyDomeNode() != 0)
2182 {
2183 if (MTOI(enabled) != 1)
2184 {
2185 scene->O3SceneManager->getSkyDomeNode()->setVisible(false);
2186 scene->O3SceneManager->setSkyDome(false, "");
2187 if (scene->skyDomeMat)
2188 {
2189 scene->O3MaterialManager->remove(scene->skyDomeMat->getName());
2190 scene->O3MaterialManager->unload(scene->skyDomeMat->getName());
2191 }
2192 }
2193 else
2194 {
2195 scene->O3SceneManager->getSkyDomeNode()->setVisible(true);
2196 scene->O3SceneManager->setSkyDome(true, scene->skyDomeMat->getName(), scene->O3SceneManager->getSkyDomeGenParameters().skyDomeCurvature, scene->O3SceneManager->getSkyDomeGenParameters().skyDomeTiling, scene->O3SceneManager->getSkyDomeGenParameters().skyDomeDistance);
2197 }
2198 }
2199 MMset(m, 0, ITOM(1));
2200 return 0;
2201 }
2202 }
2203 catch (Ogre::Exception &e)
2204 {
2205 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
2206 }
2207 MMset(m, 0, NIL);
2208 return 0;
2209}
2210
2211
2231{
2232#if SO3_DEBUG == 1
2233 MMechostr(MSKDEBUG, "SO3SceneGetSkyDomeParameters\n");
2234#endif
2235
2236 int s = MMget(m, 0);
2237 if (s == NIL)
2238 {
2239 MMset(m, 0, NIL);
2240 return 0;
2241 }
2242
2243 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2244 if (scene == 0)
2245 {
2246 MMset(m, 0, NIL);
2247 return 0;
2248 }
2249
2250 std::string groupResource(Ogre::RGN_DEFAULT);
2251
2252 try
2253 {
2254 if (scene->hasSkyDome)
2255 {
2256 // Getting material,bool and parameters
2257 // TODO Group / SKY refacto
2258 SMaterial * curMat = scene->GetMaterial(groupResource, scene->skyDomeMat->getName().c_str());
2259 int mat = OBJfindTH(m, SO3MATERIAL, SCOL_PTR(curMat));
2260 if (mat != NIL)
2261 mat = MMfetch(m, mat, OFFOBJMAG);
2262 MMpush(m, mat);
2263
2264 float curvature = scene->O3SceneManager->getSkyDomeGenParameters().skyDomeCurvature;
2265 MMpush(m, FTOM(curvature));
2266
2267 float tilling = scene->O3SceneManager->getSkyDomeGenParameters().skyDomeTiling;
2268 MMpush(m, FTOM(tilling));
2269
2270 float d = scene->O3SceneManager->getSkyDomeGenParameters().skyDomeDistance;
2271 MMpush(m, FTOM(d));
2272
2273 int xSeg = scene->O3SceneManager->getSkyDomeGenParameters().skyDomeXSegments;
2274 MMpush(m, ITOM(xSeg));
2275
2276 int ySeg = scene->O3SceneManager->getSkyDomeGenParameters().skyDomeYSegments;
2277 MMpush(m, ITOM(ySeg));
2278
2279 int keep = scene->O3SceneManager->getSkyDomeGenParameters().skyDomeYSegments_keep;
2280 MMpush(m, ITOM(keep));
2281
2282 Ogre::Quaternion orient;
2283 orient = scene->O3SceneManager->getSkyDomeNode()->getOrientation();
2284 int rot = MMmalloc(m, 4, TYPETAB);
2285 if (rot == NIL)
2286 {
2287 MMset(m, 0, NIL);
2288 return MERRMEM;
2289 }
2290 MMstore(m, rot, 0, FTOM(orient.x));
2291 MMstore(m, rot, 1, FTOM(orient.y));
2292 MMstore(m, rot, 2, FTOM(orient.z));
2293 MMstore(m, rot, 3, FTOM(orient.w));
2294 MMpush(m, PTOM(rot));
2295
2296 int booleenEnable = 0;
2297 if (scene->O3SceneManager->isSkyDomeEnabled())
2298 booleenEnable = 1;
2299 MMpush(m, ITOM(booleenEnable));
2300
2301 int booleenDrawFirst = 0;
2302 if (scene->skyDomeDrawFirst)
2303 booleenDrawFirst = 1;
2304 MMpush(m, ITOM(booleenDrawFirst));
2305
2306
2307 int tuple = MMmalloc(m, 10, TYPETAB);
2308 if (tuple == NIL)
2309 {
2310 MMset(m, 0, NIL);
2311 return MERRMEM;
2312 }
2313 MMstore(m, tuple, 9, MMpull(m));
2314 MMstore(m, tuple, 8, MMpull(m));
2315 MMstore(m, tuple, 7, MMpull(m));
2316 MMstore(m, tuple, 6, MMpull(m));
2317 MMstore(m, tuple, 5, MMpull(m));
2318 MMstore(m, tuple, 4, MMpull(m));
2319 MMstore(m, tuple, 3, MMpull(m));
2320 MMstore(m, tuple, 2, MMpull(m));
2321 MMstore(m, tuple, 1, MMpull(m));
2322 MMstore(m, tuple, 0, MMpull(m));
2323 MMset(m, 0, PTOM(tuple));
2324 return 0;
2325 }
2326 else
2327 {
2328 MMset(m, 0, NIL);
2329 return 0;
2330 }
2331
2332 }
2333 catch (Ogre::Exception &e)
2334 {
2335 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
2336 MMset(m, 0, NIL);
2337 return 0;
2338 }
2339}
2340
2341
2361int SO3SceneSetSkyPlane(mmachine m)
2362{
2363#if SO3_DEBUG == 1
2364 MMechostr(MSKDEBUG, "SO3SceneSetSkyPlane\n");
2365#endif
2366
2367 int drawFirst = MMpull(m);
2368 int enabled = MMpull(m);
2369 int group = MMpull(m);
2370 int ySeg = MTOI(MMpull(m));
2371 int xSeg = MTOI(MMpull(m));
2372 float bow = MTOF(MMpull(m));
2373 float tiling = MTOF(MMpull(m));
2374 float scale = MTOF(MMpull(m));
2375 int vec = MTOP(MMpull(m));
2376 float d = MTOF(MMpull(m));
2377 int mat = MMpull(m);
2378 int s = MMget(m, 0);
2379 if ((s == NIL) || (mat == NIL))
2380 {
2381 MMset(m, 0, NIL);
2382 return 0;
2383 }
2384
2385 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2386 if (scene == 0)
2387 {
2388 MMset(m, 0, NIL);
2389 return 0;
2390 }
2391
2392 SMaterial* material = MMgetPointer<SMaterial*>(m, MTOP(mat));
2393 if (material == 0)
2394 {
2395 MMechostr(MSKDEBUG, "material==NULL\n");
2396 MMset(m, 0, NIL);
2397 return 0;
2398 }
2399
2400 std::string groupResource(Ogre::RGN_DEFAULT);
2401
2402 bool isEnable = false;
2403 if (MTOI(enabled) == 1)
2404 isEnable = true;
2405
2406 bool isDrawFirst = false;
2407 if (MTOI(drawFirst) == 1)
2408 isDrawFirst = true;
2409
2410 try
2411 {
2412 if (material->getOgreMaterialPointer())
2413 {
2414 // Destroy Older Material
2415 if (scene->skyPlaneMat)
2416 {
2417 scene->O3MaterialManager->remove(scene->skyPlaneMat->getName());
2418 scene->O3MaterialManager->unload(scene->skyPlaneMat->getName());
2419 }
2420 // We add to create a copy of the material to avoid problem with shared materials
2421 // Create a copy of the current Ogre Material
2422 Ogre::MaterialPtr mCurrentMaterialPointer = material->getOgreMaterialPointer()->clone(scene->GetName() + "mSkyPlaneMaterial_" + material->getOgreMaterialPointer()->getName(), groupResource);
2423 mCurrentMaterialPointer->setLightingEnabled(false);
2424
2425 Ogre::Plane plane;
2426 Ogre::Vector3 vecteur;
2427 if (vec == NIL)
2428 {
2429 vecteur.NEGATIVE_UNIT_Y;
2430 }
2431 else
2432 {
2433 vecteur.x = MTOF(MMfetch(m, vec, 0));
2434 vecteur.y = MTOF(MMfetch(m, vec, 1));
2435 vecteur.z = MTOF(MMfetch(m, vec, 2));
2436 }
2437 plane.d = d;
2438 plane.normal = vecteur;
2439
2440 scene->O3SceneManager->setSkyPlane(isEnable, plane, mCurrentMaterialPointer->getName(), scale, tiling, isDrawFirst, bow, xSeg, ySeg, groupResource);
2441
2442 scene->skyPlaneDrawFirst = isDrawFirst;
2443 scene->hasSkyPlane = true;
2444 scene->skyPlaneMat = mCurrentMaterialPointer;
2445 scene->skyPlane = plane;
2446
2447 }
2448 MMset(m, 0, ITOM(1));
2449 return 0;
2450 }
2451 catch (Ogre::Exception &e)
2452 {
2453 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
2454 MMset(m, 0, NIL);
2455 return 0;
2456 }
2457}
2458
2459
2470{
2471#if SO3_DEBUG == 1
2472 MMechostr(MSKDEBUG, "SO3SceneSetSkyPlaneEnable\n");
2473#endif
2474
2475
2476 int enabled = MMpull(m);
2477 int s = MMget(m, 0);
2478 if (s == NIL)
2479 {
2480 MMset(m, 0, NIL);
2481 return 0;
2482 }
2483
2484 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2485 if (scene == NULL)
2486 {
2487 MMset(m, 0, NIL);
2488 return 0;
2489 }
2490
2491 try
2492 {
2493 if (scene->hasSkyPlane)
2494 {
2495 if (scene->O3SceneManager->getSkyPlaneNode() != 0)
2496 {
2497 if (MTOI(enabled) != 1)
2498 {
2499 scene->O3SceneManager->getSkyPlaneNode()->setVisible(false);
2500 scene->O3SceneManager->setSkyPlane(false, scene->skyPlane, "");
2501 if (scene->skyPlaneMat)
2502 {
2503 scene->O3MaterialManager->remove(scene->skyPlaneMat->getName());
2504 scene->O3MaterialManager->unload(scene->skyPlaneMat->getName());
2505 }
2506 }
2507 else
2508 {
2509 scene->O3SceneManager->getSkyPlaneNode()->setVisible(true);
2510 scene->O3SceneManager->setSkyPlane(true, scene->skyPlane, scene->skyPlaneMat->getName());
2511 }
2512 MMset(m, 0, ITOM(1));
2513 return 0;
2514 }
2515 }
2516 }
2517 catch (Ogre::Exception &e)
2518 {
2519 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
2520 }
2521 MMset(m, 0, NIL);
2522 return 0;
2523}
2524
2525
2545{
2546#if SO3_DEBUG == 1
2547 MMechostr(MSKDEBUG, "SO3SceneGetSkyPlaneParameters\n");
2548#endif
2549
2550 int s = MMget(m, 0);
2551 if (s == NIL)
2552 {
2553 MMset(m, 0, NIL);
2554 return 0;
2555 }
2556
2557 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2558 if (scene == NULL)
2559 {
2560 MMset(m, 0, NIL);
2561 return 0;
2562 }
2563
2564 MMpull(m);
2565
2566 std::string groupResource(Ogre::RGN_DEFAULT);
2567
2568 try
2569 {
2570 if (scene->hasSkyPlane)
2571 {
2572 // Getting material,bool and parameters
2573 // TODO Group / SKY refacto
2574 SMaterial* curMat = scene->GetMaterial(groupResource, scene->skyPlaneMat->getName().c_str());
2576
2577 float bow = scene->O3SceneManager->getSkyPlaneGenParameters().skyPlaneBow;
2578 MMpush(m, FTOM(bow));
2579
2580 float scale = scene->O3SceneManager->getSkyPlaneGenParameters().skyPlaneScale;
2581 MMpush(m, FTOM(scale));
2582
2583 float tiling = scene->O3SceneManager->getSkyPlaneGenParameters().skyPlaneTiling;
2584 MMpush(m, FTOM(tiling));
2585
2586 int xSeg = scene->O3SceneManager->getSkyPlaneGenParameters().skyPlaneXSegments;
2587 MMpush(m, ITOM(xSeg));
2588
2589 int ySeg = scene->O3SceneManager->getSkyPlaneGenParameters().skyPlaneYSegments;
2590 MMpush(m, ITOM(ySeg));
2591
2592 float d = scene->skyPlane.d;
2593 MMpush(m, FTOM(d));
2594
2595 Ogre::Vector3 vec;
2596 vec = scene->skyPlane.normal;
2597 int vecteur = MMmalloc(m, 3, TYPETAB);
2598 if (vecteur == NIL)
2599 {
2600 MMpush(m, NIL);
2601 return MERRMEM;
2602 }
2603 MMstore(m, vecteur, 0, FTOM(vec.x));
2604 MMstore(m, vecteur, 1, FTOM(vec.y));
2605 MMstore(m, vecteur, 2, FTOM(vec.z));
2606 MMpush(m, PTOM(vecteur));
2607
2608 int booleenEnable = 0;
2609 if (scene->O3SceneManager->isSkyPlaneEnabled())
2610 booleenEnable = 1;
2611 MMpush(m, ITOM(booleenEnable));
2612
2613 int booleenDrawFirst = 0;
2614 if (scene->skyBoxDrawFirst)
2615 booleenDrawFirst = 1;
2616 MMpush(m, ITOM(booleenDrawFirst));
2617
2618
2619 int tuple = MMmalloc(m, 10, TYPETAB);
2620 if (tuple == NIL)
2621 {
2622 MMpush(m, NIL);
2623 return MERRMEM;
2624 }
2625 MMstore(m, tuple, 9, MMpull(m));
2626 MMstore(m, tuple, 8, MMpull(m));
2627 MMstore(m, tuple, 7, MMpull(m));
2628 MMstore(m, tuple, 6, MMpull(m));
2629 MMstore(m, tuple, 5, MMpull(m));
2630 MMstore(m, tuple, 4, MMpull(m));
2631 MMstore(m, tuple, 3, MMpull(m));
2632 MMstore(m, tuple, 2, MMpull(m));
2633 MMstore(m, tuple, 1, MMpull(m));
2634 MMstore(m, tuple, 0, MMpull(m));
2635 MMpush(m, PTOM(tuple));
2636 return 0;
2637 }
2638 else
2639 {
2640 MMpush(m, NIL);
2641 return 0;
2642 }
2643
2644 }
2645 catch (Ogre::Exception &e)
2646 {
2647 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
2648 MMpush(m, NIL);
2649 return 0;
2650 }
2651}
2652
2653
2664{
2665#ifdef SO3_DEBUG
2666 MMechostr(MSKDEBUG, "SO3SceneSetAmbientLight\n");
2667#endif
2668
2669 int ambient = MTOI(MMpull(m));
2670 int s = MMget(m, 0);
2671 if ((s == NIL) || (ambient == NIL))
2672 {
2673 MMset(m, 0, NIL);
2674 return 0;
2675 }
2676 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2677 if (scene == NULL)
2678 {
2679 MMset(m, 0, NIL);
2680 return 0;
2681 }
2682 float r, g, b, a = 0.0;
2683 r = ((ambient >> 23) & 0x000000ff) / CONST_COLOR;
2684 g = ((ambient >> 15) & 0x000000ff) / CONST_COLOR;
2685 b = ((ambient >> 7) & 0x000000ff) / CONST_COLOR;
2686 a = ((ambient)& 0x0000007E) / CONST_COLOR_ALPHA;
2687 Ogre::ColourValue ambientColor;
2688 ambientColor.a = a;
2689 ambientColor.r = r;
2690 ambientColor.g = g;
2691 ambientColor.b = b;
2692 scene->SetAmbientLight(ambientColor);
2693 MMset(m, 0, ITOM(1));
2694 return 0;
2695}
2696
2697
2707{
2708#ifdef SO3_DEBUG
2709 MMechostr(MSKDEBUG, "SO3SceneGetAmbientLight\n");
2710#endif
2711
2712 int s = MMget(m, 0);
2713 if (s == NIL)
2714 {
2715 MMset(m, 0, 0);
2716 return 0;
2717 }
2718 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2719 if (scene == NULL)
2720 {
2721 MMset(m, 0, 0);
2722 return 0;
2723 }
2724
2725 Ogre::ColourValue color = scene->GetAmbientLight();
2726 int a = static_cast <int> (color.a*CONST_COLOR_ALPHA);
2727 int b = static_cast <int> (color.b*CONST_COLOR);
2728 int g = static_cast <int> (color.g*CONST_COLOR);
2729 int r = static_cast <int> (color.r*CONST_COLOR);
2730
2731 int val = (a & 0x0000007E) + ((b & 0x000000ff) << 7) + ((g & 0x000000ff) << 15) + ((r & 0x000000ff) << 23);
2732
2733 MMset(m, 0, ITOM(val));
2734 return 0;
2735}
2736
2737
2746int SO3SceneGetFogColor(mmachine m)
2747{
2748#ifdef SO3_DEBUG
2749 MMechostr(MSKDEBUG, "SO3SceneGetFogColor\n");
2750#endif
2751
2752 int s = MMget(m, 0);
2753 if (s == NIL)
2754 {
2755 MMset(m, 0, 0);
2756 return 0;
2757 }
2758 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2759 if (scene == NULL)
2760 {
2761 MMset(m, 0, 0);
2762 return 0;
2763 }
2764
2765 int a = static_cast <int> (scene->O3SceneManager->getFogColour().a*CONST_COLOR_ALPHA);
2766 int b = static_cast <int> (scene->O3SceneManager->getFogColour().b*CONST_COLOR);
2767 int g = static_cast <int> (scene->O3SceneManager->getFogColour().g*CONST_COLOR);
2768 int r = static_cast <int> (scene->O3SceneManager->getFogColour().r*CONST_COLOR);
2769
2770 int val = (a & 0x0000007E) + ((b & 0x000000ff) << 7) + ((g & 0x000000ff) << 15) + ((r & 0x000000ff) << 23);
2771
2772 MMset(m, 0, ITOM(val));
2773 return 0;
2774}
2775
2776
2791int SO3SceneGetFogMode(mmachine m)
2792{
2793#ifdef SO3_DEBUG
2794 MMechostr(MSKDEBUG, "SO3SceneGetFogMode\n");
2795#endif
2796
2797 int s = MMget(m, 0);
2798 if (s == NIL)
2799 {
2800 MMset(m, 0, 0);
2801 return 0;
2802 }
2803 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2804 if (scene == NULL)
2805 {
2806 MMset(m, 0, 0);
2807 return 0;
2808 }
2809
2810 int val = (int)scene->O3SceneManager->getFogMode();
2811
2812 MMset(m, 0, ITOM(val));
2813 return 0;
2814}
2815
2816
2826{
2827#ifdef SO3_DEBUG
2828 MMechostr(MSKDEBUG, "SO3SceneGetFogDensity\n");
2829#endif
2830
2831 int s = MMget(m, 0);
2832 if (s == NIL)
2833 {
2834 MMset(m, 0, 0);
2835 return 0;
2836 }
2837 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2838 if (scene == NULL)
2839 {
2840 MMset(m, 0, 0);
2841 return 0;
2842 }
2843
2844 float val = scene->O3SceneManager->getFogDensity();
2845
2846 MMset(m, 0, FTOM(val));
2847 return 0;
2848}
2849
2850
2859int SO3SceneGetFogStart(mmachine m)
2860{
2861#ifdef SO3_DEBUG
2862 MMechostr(MSKDEBUG, "SO3SceneGetFogStart\n");
2863#endif
2864
2865 int s = MMget(m, 0);
2866 if (s == NIL)
2867 {
2868 MMset(m, 0, 0);
2869 return 0;
2870 }
2871 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2872 if (scene == NULL)
2873 {
2874 MMset(m, 0, 0);
2875 return 0;
2876 }
2877
2878 float val = scene->O3SceneManager->getFogStart();
2879
2880 MMset(m, 0, FTOM(val));
2881 return 0;
2882}
2883
2884
2893int SO3SceneGetFogEnd(mmachine m)
2894{
2895#ifdef SO3_DEBUG
2896 MMechostr(MSKDEBUG, "SO3SceneGetFogEnd\n");
2897#endif
2898
2899 int s = MMget(m, 0);
2900 if (s == NIL)
2901 {
2902 MMset(m, 0, 0);
2903 return 0;
2904 }
2905 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2906 if (scene == NULL)
2907 {
2908 MMset(m, 0, 0);
2909 return 0;
2910 }
2911
2912 float val = scene->O3SceneManager->getFogEnd();
2913
2914 MMset(m, 0, FTOM(val));
2915 return 0;
2916}
2917
2918
2938int SO3SceneSetFog(mmachine m)
2939{
2940#ifdef SO3_DEBUG
2941 MMechostr(MSKDEBUG, "SO3SceneSetFog\n");
2942#endif
2943
2944 int linE = MMpull(m);
2945 int linS = MMpull(m);
2946 int expo = MMpull(m);
2947 int color = MTOI(MMpull(m));
2948 int mode = MTOI(MMpull(m));
2949 int s = MMget(m, 0);
2950 if ((s == NIL) || (color == NIL) || (expo == NIL) || (linS == NIL) || (linE == NIL) || (mode == NIL))
2951 {
2952 MMset(m, 0, NIL);
2953 return 0;
2954 }
2955 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
2956 if (scene == NULL)
2957 {
2958 MMset(m, 0, NIL);
2959 return 0;
2960 }
2961
2962 float r, g, b, a = 0.0;
2963
2964 r = ((color >> 23) & 0x000000ff) / CONST_COLOR;
2965 g = ((color >> 15) & 0x000000ff) / CONST_COLOR;
2966 b = ((color >> 7) & 0x000000ff) / CONST_COLOR;
2967 a = ((color)& 0x0000007E) / CONST_COLOR_ALPHA;
2968
2969 Ogre::ColourValue diffuseColor;
2970 diffuseColor.a = a;
2971 diffuseColor.r = r;
2972 diffuseColor.g = g;
2973 diffuseColor.b = b;
2974
2975 float fExpo = 0.0f;
2976 float fLinS = 0.0f;
2977 float fLinE = 0.0f;
2978 if (mode)
2979 {
2980 fExpo = MTOF(expo);
2981 fLinS = MTOF(linS);
2982 fLinE = MTOF(linE);
2983 }
2984
2985 scene->O3SceneManager->setFog((Ogre::FogMode)mode, diffuseColor, (Ogre::Real)fExpo, (Ogre::Real)fLinS, (Ogre::Real)fLinE);
2986
2987 MMset(m, 0, ITOM(1));
2988 return 0;
2989}
2990
2991
3001int SO3SceneGetNode(mmachine m)
3002{
3003#ifdef SO3_DEBUG
3004 MMechostr(MSKDEBUG, "SO3SceneGetNode\n");
3005#endif
3006
3007 int name = MMpull(m);
3008 int s = MMget(m, 0);
3009 if ((name == NIL) || (s == NIL))
3010 {
3011 MMset(m, 0, NIL);
3012 return 0;
3013 }
3014 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3015 if (scene == NULL)
3016 {
3017 MMset(m, 0, NIL);
3018 return 0;
3019 }
3020 SNode* curNode;
3021 curNode = NULL;
3022 curNode = scene->GetNode(string(MMstartstr(m, MTOP(name))));
3023 if (curNode == NULL)
3024 {
3025 MMset(m, 0, NIL);
3026 return 0;
3027 }
3028 int so3obj = OBJfindTH(m, SO3OBJTYPE, SCOL_PTR(curNode));
3029 if (so3obj != NIL)
3030 so3obj = MMfetch(m, so3obj, OFFOBJMAG);
3031 MMset(m, 0, so3obj);
3032 return 0;
3033}
3034
3035
3045int SO3SceneGetObject(mmachine m)
3046{
3047#ifdef SO3_DEBUG
3048 MMechostr(MSKDEBUG, "SO3SceneGetObject\n");
3049#endif
3050
3051 int name = MMpull(m);
3052 int s = MMget(m, 0);
3053 if ((name == NIL) || (s == NIL))
3054 {
3055 MMset(m, 0, NIL);
3056 return 0;
3057 }
3058
3059 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3060 if (scene == NULL)
3061 {
3062 MMset(m, 0, NIL);
3063 return 0;
3064 }
3065
3066 SNode* curNode = 0;
3067 string tmpName(MMstartstr(m, MTOP(name)));
3068
3069 // check if it's the root scene Node that is requested.
3070 if (tmpName == scene->GetRootNode()->GetName())
3071 curNode = scene->GetRootNode();
3072 else
3073 curNode = scene->GetNode(tmpName);
3074
3075 if (curNode == 0)
3076 {
3077 MMechostr(MSKDEBUG, "SO3SceneGetObject : Node is NULL : %s \n", tmpName.c_str());
3078 MMset(m, 0, NIL);
3079 return 0;
3080 }
3081
3082 int c = OBJfindTH(m, SO3OBJTYPE, SCOL_PTR(curNode));
3083 if (c != NIL)
3084 c = MMfetch(m, c, OFFOBJMAG);
3085
3086 MMset(m, 0, c);
3087 return 0;
3088}
3089
3090
3100int SO3SceneNodeCreate(mmachine m)
3101{
3102#ifdef SO3_DEBUG
3103 MMechostr(MSKDEBUG, "SO3SceneNodeCreate\n");
3104#endif
3105
3106 int name = MMpull(m);
3107 int s = MMget(m, 0);
3108 if (s == NIL)
3109 {
3110 MMset(m, 0, NIL);
3111 return 0;
3112 }
3113
3114 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3115 if (scene == NULL)
3116 {
3117 MMset(m, 0, NIL);
3118 return 0;
3119 }
3120
3121 // Crée le Node
3122 std::string tmpNodeName(MMstartstr(m, MTOP(name)));
3123 SNode* node = 0;
3124 try
3125 {
3126 node = scene->CreateNode(tmpNodeName);
3127 }
3128 catch (SO3::SException &e)
3129 {
3130 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
3131 MMset(m, 0, NIL);
3132 return 0;
3133 }
3134 catch (Ogre::Exception &e)
3135 {
3136 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
3137 MMset(m, 0, NIL);
3138 return 0;
3139 }
3140
3141 // remove last param
3142 MMpull(m);
3143 return createObject(m, node, scene);
3144}
3145
3146
3157{
3158#ifdef SO3_DEBUG
3159 MMechostr(MSKDEBUG, "SO3SceneParseMaterialsFromGroup\n");
3160#endif
3161
3162 int group = MMpull(m);
3163 int s = MMpull(m);
3164 if (s == NIL)
3165 {
3166 MMpush(m, NIL);
3167 return 0;
3168 }
3169
3170 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3171 if (scene == NULL)
3172 {
3173 MMpush(m, NIL);
3174 return 0;
3175 }
3176
3177 std::string groupResource(Ogre::RGN_DEFAULT);
3178 if (group != NIL)
3179 groupResource = MMstartstr(m, MTOP(group));
3180
3181 if (groupResource.substr(0, 4) != "SO3/")
3182 groupResource = scene->GetName() + groupResource;
3183
3184 const SMaterialMap* groupMaterials = scene->GetMaterials(groupResource);
3185 if (groupMaterials == 0)
3186 {
3187 MMechostr(MSKDEBUG, "SO3SceneParseMaterialsFromGroup: resource group \"%s\" not found!\n", groupResource.c_str());
3188 MMpush(m, NIL);
3189 return 0;
3190 }
3191 else
3192 {
3193 unsigned int count = 0;
3194 // Valid group, iterate content
3195 SMaterialMap::const_iterator i = groupMaterials->begin();
3196 while (i != groupMaterials->end())
3197 {
3198 std::string matName = i->second->GetName();
3199 if (matName.find(std::string(SO3_INTERNAL_RESOURCE_GROUP)) != 0 && matName.find(std::string(Ogre::RGN_DEFAULT)) != 0)
3200 {
3201 createOrRetrieveScolMaterialAndSendToVM(m, scene, i->second);
3202 count++;
3203 };
3204 i++;
3205 }
3206
3207 if (MMpush(m, NIL))
3208 return MERRMEM;
3209
3210 for (unsigned int j = 0; j < count; j++)
3211 {
3212 if (MMpush(m, 2 * 2))
3213 return MERRMEM;
3214 if (int k = MBdeftab(m))
3215 return k;
3216 }
3217 }
3218 return 0;
3219}
3220
3221
3232{
3233#ifdef SO3_DEBUG
3234 MMechostr(MSKDEBUG, "SO3SceneParseCompositorsFromGroup\n");
3235#endif
3236
3237 int group = MMpull(m);
3238 int s = MMpull(m);
3239 if (s == NIL)
3240 {
3241 MMpush(m, NIL);
3242 return 0;
3243 }
3244
3245 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3246 if (scene == NULL)
3247 {
3248 MMpush(m, NIL);
3249 return 0;
3250 }
3251
3252 std::string groupResource(Ogre::RGN_DEFAULT);
3253 if (group != NIL)
3254 groupResource = MMstartstr(m, MTOP(group));
3255
3256 if (groupResource.substr(0, 4) != "SO3/")
3257 groupResource = scene->GetName() + groupResource;
3258
3259 Ogre::CompositorManager::ResourceMapIterator it = Ogre::CompositorManager::getSingleton().getResourceIterator();
3260 int p = 0;
3261 int k;
3262 std::set<string> myStr;
3263 while (it.hasMoreElements())
3264 {
3265 Ogre::CompositorPtr curComp = Ogre::static_pointer_cast<Ogre::Compositor>(it.getNext());
3266 std::string compName = curComp->getName();
3267 if ((compName.find(std::string(SO3_INTERNAL_RESOURCE_GROUP)) != 0) && (compName.find(std::string(Ogre::RGN_DEFAULT)) != 0) && (curComp->getGroup() == groupResource))
3268 {
3269 myStr.insert(curComp->getName());
3270 }
3271 }
3272
3273 std::set<string>::iterator iMyStr = myStr.begin();
3274 while (iMyStr != myStr.end())
3275 {
3276 if (k = Mpushstrbloc(m, (char*)(*iMyStr).c_str()))
3277 return k;
3278
3279 iMyStr++;
3280 }
3281
3282 if (MMpush(m, NIL))
3283 return MERRMEM;
3284
3285 for (unsigned int i = 0; i < myStr.size(); i++)
3286 {
3287 if (MMpush(m, 2 * 2))
3288 return MERRMEM;
3289 if (k = MBdeftab(m))
3290 return k;
3291 }
3292 return 0;
3293}
3294
3295
3306{
3307#ifdef SO3_DEBUG
3308 MMechostr(MSKDEBUG, "SO3SceneParseSchemeFromGroup\n");
3309#endif
3310
3311 int group = MMpull(m);
3312 int s = MMpull(m);
3313 if (s == NIL)
3314 {
3315 MMpush(m, NIL);
3316 return 0;
3317 }
3318
3319 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3320 if (scene == NULL)
3321 {
3322 MMpush(m, NIL);
3323 return 0;
3324 }
3325
3326 std::string groupResource(Ogre::RGN_DEFAULT);
3327 if (group != NIL)
3328 groupResource = MMstartstr(m, MTOP(group));
3329
3330 if (groupResource.substr(0, 4) != "SO3/")
3331 groupResource = scene->GetName() + groupResource;
3332
3333 Ogre::MaterialManager::ResourceMapIterator it = scene->O3MaterialManager->getResourceIterator();
3334 int p = 0;
3335 int k;
3336 std::set<string> myStr;
3337 while (it.hasMoreElements())
3338 {
3339 Ogre::MaterialPtr curMat = Ogre::static_pointer_cast<Ogre::Material>(it.getNext());
3340 if (curMat->getGroup() == groupResource)
3341 {
3342 for (int i = 0; i < curMat->getNumTechniques(); i++)
3343 {
3344 std::string schemeName = curMat->getTechnique(i)->getSchemeName();
3345 if (schemeName == "Default")
3346 continue;
3347
3348 if (schemeName.find(std::string(SO3_INTERNAL_RESOURCE_GROUP)) != 0)
3349 {
3350 if (schemeName.find("ShaderGenerator") != std::string::npos)
3351 schemeName = schemeName.erase(0, 15);
3352 myStr.insert(schemeName);
3353 }
3354 }
3355 }
3356 }
3357
3358 auto strit = myStr.find("DefaultScheme");
3359 if (strit == myStr.end())
3360 myStr.insert("DefaultScheme");
3361
3362 std::set<string>::iterator iSchemeList = myStr.begin();
3363 while (iSchemeList != myStr.end())
3364 {
3365 if (k = Mpushstrbloc(m, (char*)(*iSchemeList).c_str()))
3366 return k;
3367
3368 iSchemeList++;
3369 }
3370
3371 if (MMpush(m, NIL))
3372 return MERRMEM;
3373
3374 for (unsigned int i = 0; i < myStr.size(); i++)
3375 {
3376 if (MMpush(m, 2 * 2))
3377 return MERRMEM;
3378 if (k = MBdeftab(m))
3379 return k;
3380 }
3381 return 0;
3382}
3383
3384
3395{
3396#ifdef SO3_DEBUG
3397 MMechostr(MSKDEBUG, "SO3SceneParseParticleSystemsFromGroup\n");
3398#endif
3399
3400 int group = MMpull(m);
3401 int s = MMpull(m);
3402 if (s == NIL)
3403 {
3404 MMpush(m, NIL);
3405 return 0;
3406 }
3407
3408 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3409 if (scene == NULL)
3410 {
3411 MMpush(m, NIL);
3412 return 0;
3413 }
3414
3415 std::string groupResource(Ogre::RGN_DEFAULT);
3416 if (group != NIL)
3417 groupResource = MMstartstr(m, MTOP(group));
3418
3419 if (groupResource.substr(0, 4) != "SO3/")
3420 groupResource = scene->GetName() + groupResource;
3421
3422 Ogre::ParticleSystemManager::ParticleSystemTemplateIterator it = Ogre::ParticleSystemManager::getSingletonPtr()->getTemplateIterator();
3423 int p = 0;
3424 int k;
3425 std::set<string> myStr;
3426 while (it.hasMoreElements())
3427 {
3428 Ogre::ParticleSystem * curPS = it.getNext();
3429 if (curPS->getResourceGroupName() == groupResource)
3430 {
3431 myStr.insert(curPS->getName());
3432 }
3433 }
3434
3435 std::set<string>::iterator iMyStr = myStr.begin();
3436 while (iMyStr != myStr.end())
3437 {
3438 if (k = Mpushstrbloc(m, (char*)(*iMyStr).c_str()))
3439 return k;
3440
3441 iMyStr++;
3442 }
3443
3444 if (MMpush(m, NIL))
3445 return MERRMEM;
3446 for (unsigned int i = 0; i < myStr.size(); i++)
3447 {
3448 if (MMpush(m, 2 * 2))
3449 return MERRMEM;
3450 if (k = MBdeftab(m))
3451 return k;
3452 }
3453 return 0;
3454}
3455
3456
3467int SO3SceneGetMaterial(mmachine m)
3468{
3469#ifdef SO3_DEBUG
3470 MMechostr(MSKDEBUG, "SO3SceneGetMaterial\n");
3471#endif
3472
3473 int name = MMpull(m);
3474 int group = MMpull(m);
3475 int s = MMget(m, 0);
3476 if ((name == NIL) || (s == NIL))
3477 {
3478 MMset(m, 0, NIL);
3479 return 0;
3480 }
3481
3482 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3483 if (scene == NULL)
3484 {
3485 MMset(m, 0, NIL);
3486 return 0;
3487 }
3488
3489 std::string groupResource(Ogre::RGN_DEFAULT);
3490 if (group != NIL)
3491 groupResource = MMstartstr(m, MTOP(group));
3492
3493 if (groupResource.substr(0, 4) != "SO3/")
3494 groupResource = scene->GetName() + groupResource;
3495
3496 SMaterial* tmpMat = scene->GetMaterial(groupResource, MMstartstr(m, MTOP(name)));
3497 if (tmpMat == 0)
3498 {
3499 MMset(m, 0, NIL);
3500 return 0;
3501 }
3502
3503 //remove last param
3504 MMpull(m);
3505 return createOrRetrieveScolMaterialAndSendToVM(m, scene, tmpMat);
3506}
3507
3508
3519int SO3SceneGetTexture(mmachine m)
3520{
3521#ifdef SO3_DEBUG
3522 MMechostr(MSKDEBUG, "SO3SceneGetTexture\n");
3523#endif
3524
3525 int name = MMpull(m);
3526 int group = MMpull(m);
3527 int s = MMget(m, 0);
3528 if ((name == NIL) || (s == NIL))
3529 {
3530 MMset(m, 0, NIL);
3531 return 0;
3532 }
3533 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3534 if (scene == NULL)
3535 {
3536 MMset(m, 0, NIL);
3537 return 0;
3538 }
3539
3540 //remove last param
3541 MMpull(m);
3542
3543 std::string groupResource(Ogre::RGN_DEFAULT);
3544 if (group != NIL)
3545 groupResource = MMstartstr(m, MTOP(group));
3546
3547 if (groupResource.substr(0, 4) != "SO3/")
3548 groupResource = scene->GetName() + groupResource;
3549
3550 STexture* texture = scene->GetTexture(groupResource, MMstartstr(m, MTOP(name)));
3551 if (texture != NULL)
3552 {
3553 int tx = OBJfindTH(m, SO3TEXTURE, SCOL_PTR(texture));
3554 if (tx != NIL)
3555 tx = MMfetch(m, tx, OFFOBJMAG);
3556 MMpush(m, tx);
3557 return 0;
3558 }
3559 else
3560 {
3561 std::string tmpTextureName(MMstartstr(m, MTOP(name)));
3562
3563 STexture* newTex = scene->CreateTexture(groupResource, tmpTextureName, std::string(""));
3564 if (newTex == NULL)
3565 {
3566 MMpush(m, NIL);
3567 return 0;
3568 }
3569 return createTexture(m, newTex, scene);
3570 }
3571
3572 return 0;
3573}
3574
3588int SO3PlaneCreate(mmachine m)
3589{
3590#ifdef SO3_DEBUG
3591 MMechostr(MSKDEBUG, "SO3PlaneCreate\n");
3592#endif
3593
3594 int puv = MMpull(m);
3595 int pseg = MMpull(m);
3596 int psize = MMpull(m);
3597 int name = MMpull(m);
3598 int group = MMpull(m);
3599 int s = MMpull(m);
3600 if ((name == NIL) || (s == NIL) || (psize == NIL))
3601 {
3602 MMpush(m, NIL);
3603 return 0;
3604 }
3605
3606 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3607 if (scene == NULL)
3608 {
3609 MMpush(m, NIL);
3610 return 0;
3611 }
3612
3613 std::string groupResource(Ogre::RGN_DEFAULT);
3614 if (group != NIL)
3615 groupResource = MMstartstr(m, MTOP(group));
3616
3617 groupResource = scene->GetName() + groupResource;
3618
3619 std::string planeName = MMstartstr(m, MTOP(name));
3620
3621 SPointFloat uv(1.0f, 1.0f);
3622 if (puv != NIL)
3623 {
3624 uv.x = MTOF(MMfetch(m, MTOP(puv), 0));
3625 uv.y = MTOF(MMfetch(m, MTOP(puv), 1));
3626 }
3627
3628 SPointInt seg(1, 1);
3629 if (pseg != NIL)
3630 {
3631 seg.x = MTOI(MMfetch(m, MTOP(pseg), 0));
3632 seg.y = MTOI(MMfetch(m, MTOP(pseg), 1));
3633 }
3634
3635 SPointFloat sizev;
3636 sizev.x = MTOF(MMfetch(m, MTOP(psize), 0));
3637 sizev.y = MTOF(MMfetch(m, MTOP(psize), 1));
3638
3639 SEntity* newEntity = 0;
3640 try
3641 {
3642 newEntity = scene->CreatePlane(groupResource, planeName, sizev, seg, uv);
3643 }
3644 catch (SO3::SException &e)
3645 {
3646 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
3647 MMpush(m, NIL);
3648 return 0;
3649 }
3650 catch (Ogre::Exception &e)
3651 {
3652 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
3653 MMpush(m, NIL);
3654 return 0;
3655 }
3656
3657 return createObject(m, newEntity, scene);
3658}
3659
3673int SO3SphereCreate(mmachine m)
3674{
3675#ifdef SO3_DEBUG
3676 MMechostr(MSKDEBUG, "SO3SphereCreate\n");
3677#endif
3678
3679 int iseg = MMpull(m);
3680 int irings = MMpull(m);
3681 int iradius = MMpull(m);
3682 int name = MMpull(m);
3683 int group = MMpull(m);
3684 int s = MMpull(m);
3685 if ((name == NIL) || (s == NIL))
3686 {
3687 MMpush(m, NIL);
3688 return 0;
3689 }
3690
3691 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3692 if (scene == NULL)
3693 {
3694 MMpush(m, NIL);
3695 return 0;
3696 }
3697
3698 std::string groupResource(Ogre::RGN_DEFAULT);
3699 if (group != NIL)
3700 groupResource = MMstartstr(m, MTOP(group));
3701
3702 groupResource = scene->GetName() + groupResource;
3703
3704 std::string objName = MMstartstr(m, MTOP(name));
3705
3706 float radius = 1.0f;
3707 if (iradius != NIL)
3708 radius = MTOF(iradius);
3709
3710 int rings = 8;
3711 if (irings != NIL)
3712 rings = MTOI(irings);
3713
3714 int seg = 8;
3715 if (iseg != NIL)
3716 seg = MTOI(iseg);
3717
3718 SEntity* newEntity = 0;
3719 try
3720 {
3721 newEntity = scene->CreateSphere(groupResource, objName, radius, rings, seg);
3722 }
3723 catch (SO3::SException &e)
3724 {
3725 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
3726 MMpush(m, NIL);
3727 return 0;
3728 }
3729 catch (Ogre::Exception &e)
3730 {
3731 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
3732 MMpush(m, NIL);
3733 return 0;
3734 }
3735
3736 return createObject(m, newEntity, scene);
3737}
3738
3752int SO3ConeCreate(mmachine m)
3753{
3754#ifdef SO3_DEBUG
3755 MMechostr(MSKDEBUG, "SO3ConeCreate\n");
3756#endif
3757
3758 int iseg = MMpull(m);
3759 int iheight = MMpull(m);
3760 int iradius = MMpull(m);
3761 int name = MMpull(m);
3762 int group = MMpull(m);
3763 int s = MMpull(m);
3764 if ((name == NIL) || (s == NIL))
3765 {
3766 MMpush(m, NIL);
3767 return 0;
3768 }
3769
3770 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3771 if (scene == NULL)
3772 {
3773 MMpush(m, NIL);
3774 return 0;
3775 }
3776
3777 std::string groupResource(Ogre::RGN_DEFAULT);
3778 if (group != NIL)
3779 groupResource = MMstartstr(m, MTOP(group));
3780
3781 groupResource = scene->GetName() + groupResource;
3782
3783 std::string objName = MMstartstr(m, MTOP(name));
3784
3785 float radius = 1.0f;
3786 if (iradius != NIL)
3787 radius = MTOF(iradius);
3788
3789 float height = 8;
3790 if (iheight != NIL)
3791 height = MTOF(iheight);
3792
3793 int seg = 8;
3794 if (iseg != NIL)
3795 seg = MTOI(iseg);
3796
3797 SEntity* newEntity = 0;
3798 try
3799 {
3800 newEntity = scene->CreateCone(groupResource, objName, radius, height, seg);
3801 }
3802 catch (SO3::SException &e)
3803 {
3804 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
3805 MMpush(m, NIL);
3806 return 0;
3807 }
3808 catch (Ogre::Exception &e)
3809 {
3810 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
3811 MMpush(m, NIL);
3812 return 0;
3813 }
3814
3815 return createObject(m, newEntity, scene);
3816}
3817
3831int SO3OctahedronCreate(mmachine m)
3832{
3833#ifdef SO3_DEBUG
3834 MMechostr(MSKDEBUG, "SO3OctahedronCreate\n");
3835#endif
3836
3837 int iup = MMpull(m);
3838 int ibottom = MMpull(m);
3839 int ibase = MMpull(m);
3840 int name = MMpull(m);
3841 int group = MMpull(m);
3842 int s = MMpull(m);
3843 if ((name == NIL) || (s == NIL))
3844 {
3845 MMpush(m, NIL);
3846 return 0;
3847 }
3848
3849 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3850 if (scene == NULL)
3851 {
3852 MMpush(m, NIL);
3853 return 0;
3854 }
3855
3856 std::string groupResource(Ogre::RGN_DEFAULT);
3857 if (group != NIL)
3858 groupResource = MMstartstr(m, MTOP(group));
3859
3860 groupResource = scene->GetName() + groupResource;
3861
3862 std::string objName = MMstartstr(m, MTOP(name));
3863
3864 float base = 1.0f;
3865 if (ibase != NIL)
3866 base = MTOF(ibase);
3867
3868 float bottom = 1.0f;
3869 if (ibottom != NIL)
3870 bottom = MTOF(ibottom);
3871
3872 float up = 1.0f;
3873 if (iup != NIL)
3874 up = MTOF(iup);
3875
3876 SEntity* newEntity = 0;
3877 try
3878 {
3879 newEntity = scene->CreateOctahedron(groupResource, objName, base, bottom, up);
3880 }
3881 catch (SO3::SException &e)
3882 {
3883 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
3884 MMpush(m, NIL);
3885 return 0;
3886 }
3887 catch (Ogre::Exception &e)
3888 {
3889 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
3890 MMpush(m, NIL);
3891 return 0;
3892 }
3893
3894 return createObject(m, newEntity, scene);
3895}
3896
3907{
3908#ifdef SO3_DEBUG
3909 MMechostr(MSKDEBUG, "SO3SceneGetAnimation\n");
3910#endif
3911
3912 int name = MMpull(m);
3913 int s = MMget(m, 0);
3914 if ((name == NIL) || (s == NIL))
3915 {
3916 MMset(m, 0, NIL);
3917 return 0;
3918 }
3919
3920 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3921 if (scene == NULL)
3922 {
3923 MMset(m, 0, NIL);
3924 return 0;
3925 }
3926
3927 std::string animationName(MMstartstr(m, MTOP(name)));
3928 SAnim* curAnim = scene->GetAnimation(animationName);
3929 if (curAnim == 0)
3930 {
3931 MMechostr(MSKDEBUG, "Animation not found!\n");
3932 MMset(m, 0, NIL);
3933 return 0;
3934 }
3935
3936 int a = OBJfindTH(m, SO3ANIM, SCOL_PTR(curAnim));
3937 if (a != NIL)
3938 a = MMfetch(m, a, OFFOBJMAG);
3939
3940 MMset(m, 0, a);
3941 return 0;
3942}
3943
3953{
3954#ifdef SO3_DEBUG
3955 MMechostr(MSKDEBUG, "SO3SceneGetAnimations\n");
3956#endif
3957
3958 int s = MMpull(m);
3959 if (s == NIL)
3960 {
3961 MMpush(m, NIL);
3962 return 0;
3963 }
3964
3965 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
3966 if (scene == NULL)
3967 {
3968 MMpush(m, NIL);
3969 return 0;
3970 }
3971
3972 int icount = 0;
3973
3974 const SAnimMap animationListCopy = scene->GetAnimations();
3975 SAnimMap::const_iterator iAnimations = animationListCopy.begin();
3976 while (iAnimations != animationListCopy.end())
3977 {
3978 int a = OBJfindTH(m, SO3ANIM, SCOL_PTR(iAnimations->second));
3979
3980 if (a != NIL)
3981 a = MMfetch(m, a, OFFOBJMAG);
3982
3983 if (MMpush(m, a))
3984 return MERRMEM;
3985
3986 iAnimations++;
3987 icount++;
3988 }
3989
3990 if (MMpush(m, NIL))
3991 return MERRMEM;
3992
3993 for (int j = 0; j < icount; j++)
3994 {
3995 if (MMpush(m, 2 * 2))
3996 return MERRMEM;
3997
3998 if (int k = MBdeftab(m))
3999 return k;
4000 }
4001
4002 return 0;
4003}
4004
4014{
4015#ifdef SO3_DEBUG
4016 MMechostr(MSKDEBUG, "SO3SceneGetNumAnimations\n");
4017#endif
4018
4019 int s = MMget(m, 0);
4020 if (s == NIL)
4021 {
4022 MMset(m, 0, NIL);
4023 return 0;
4024 }
4025
4026 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
4027 if (scene == NULL)
4028 {
4029 MMset(m, 0, NIL);
4030 return 0;
4031 }
4032
4033 MMset(m, 0, ITOM(scene->GetNumAnimations()));
4034 return 0;
4035}
4036
4047{
4048#ifdef SO3_DEBUG
4049 MMechostr(MSKDEBUG, "SO3SceneSetMaterialsPointSize\n");
4050#endif
4051
4052 int isize = MMpull(m);
4053 int s = MMget(m, 0);
4054 if (s == NIL)
4055 {
4056 MMset(m, 0, NIL);
4057 return 0;
4058 }
4059
4060 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
4061 if (scene == NULL)
4062 {
4063 MMset(m, 0, NIL);
4064 return 0;
4065 }
4066
4067 float nsize = 0.0f;
4068 if (isize != NIL)
4069 nsize = MTOF(isize);
4070
4071 scene->SetMaterialsPointSize(nsize);
4072 return 0;
4073}
4074
4075
4087int SO3CbScenePreRender(mmachine m)
4088{
4089#ifdef SO3_DEBUG
4090 MMechostr(MSKDEBUG, "SO3CbScenePreRender\n");
4091#endif
4092
4093 int k = OBJaddreflex(m, SO3SCENETYPE, SO3_SCENE_PRE_RENDER_EVENT);
4094
4095#ifdef SO3_DEBUG
4096 MMechostr(MSKDEBUG, "SO3CbScenePreRender : ok!\n");
4097#endif
4098 return k;
4099}
4100
4113{
4114#ifdef SO3_DEBUG
4115 MMechostr(MSKDEBUG, "SO3CbScenePreRenderPhysic\n");
4116#endif
4117
4118 int k = OBJaddreflex(m, SO3SCENETYPE, SO3_SCENE_PRE_RENDER_PHYSIC_EVENT);
4119
4120#ifdef SO3_DEBUG
4121 MMechostr(MSKDEBUG, "SO3CbScenePreRenderPhysic : ok!\n");
4122#endif
4123 return k;
4124}
4125
4126
4139{
4140#ifdef SO3_DEBUG
4141 MMechostr(MSKDEBUG, "SO3CbScenePreRender2\n");
4142#endif
4143
4144 int k = OBJaddreflex(m, SO3SCENETYPE, SO3_SCENE_PRE_RENDER_EVENT2);
4145
4146#ifdef SO3_DEBUG
4147 MMechostr(MSKDEBUG, "SO3CbScenePreRender2 : ok!\n");
4148#endif
4149 return k;
4150}
4151
4164{
4165#ifdef SO3_DEBUG
4166 MMechostr(MSKDEBUG, "SO3CbScenePostRender\n");
4167#endif
4168
4169 int k = OBJaddreflex(m, SO3SCENETYPE, SO3_SCENE_POST_RENDER_EVENT);
4170
4171#ifdef SO3_DEBUG
4172 MMechostr(MSKDEBUG, "SO3CbScenePostRender : ok!\n");
4173#endif
4174 return k;
4175}
4176
4177int getScenePreRenderEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
4178{
4179#ifdef SO3_DEBUG
4180 MMechostr(MSKDEBUG, "getScenePreRenderEvent\n");
4181#endif
4182
4183 int k = 0;
4184 if (!(k = OBJbeginreflex(m, SO3SCENETYPE, id, SO3_SCENE_PRE_RENDER_EVENT)))
4185 {
4186 MMpush(m, ITOM(static_cast<int>(param)));
4187
4188 k = OBJcallreflex(m, 1);
4189 }
4190 return k;
4191}
4192
4193int getScenePreRenderEvent2(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
4194{
4195#ifdef SO3_DEBUG
4196 MMechostr(MSKDEBUG, "getScenePreRenderEvent2\n");
4197#endif
4198
4199 int k = 0;
4200
4201 if (!(k = OBJbeginreflex(m, SO3SCENETYPE, id, SO3_SCENE_PRE_RENDER_EVENT2)))
4202 {
4203 MMpush(m, ITOM(static_cast<int>(param)));
4204
4205 k = OBJcallreflex(m, 1);
4206 }
4207 return k;
4208}
4209
4210int getScenePostRenderEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
4211{
4212#ifdef SO3_DEBUG
4213 MMechostr(MSKDEBUG, "getScenePostRenderEvent\n");
4214#endif
4215
4216 int k = 0;
4217
4218 if (!(k = OBJbeginreflex(m, SO3SCENETYPE, id, SO3_SCENE_POST_RENDER_EVENT)))
4219 {
4220 MMpush(m, ITOM(static_cast<int>(param)));
4221
4222 k = OBJcallreflex(m, 1);
4223 }
4224 return k;
4225}
4226
4227int getScenePreRenderPhysicEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
4228{
4229#ifdef SO3_DEBUG
4230 MMechostr(MSKDEBUG, "getScenePreRenderPhysicEvent\n");
4231#endif
4232
4233 int k = 0;
4234
4235 if (!(k = OBJbeginreflex(m, SO3SCENETYPE, id, SO3_SCENE_PRE_RENDER_PHYSIC_EVENT)))
4236 {
4237 MMpush(m, ITOM(static_cast<int>(param)));
4238
4239 k = OBJcallreflex(m, 1);
4240 }
4241 return k;
4242}
4243
4244
4245int getObjectLoadedEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
4246{
4247#ifdef SO3_DEBUG
4248 MMechostr(MSKDEBUG, "getObjectLoadedEvent\n");
4249#endif
4250
4251 int k = 0;
4252 SEntity* newEntity = (SEntity*)id;
4253
4254 int obj = OBJfindTH(m, SO3OBJTYPE, id);
4255 if (!newEntity || obj == NIL)
4256 return 0;
4257
4258 // Create Scol Animations Object from entity SAnim.
4259 createEntinyAnimationsScol(m, newEntity);
4260
4261 if (!(k = OBJbeginreflex(m, SO3OBJTYPE, id, SO3_OBJECT_LOADED_EVENT)))
4262 {
4263 k = OBJcallreflex(m, 0);
4264 }
4265 return k;
4266}
4267
4268
4269NativeDefinition natSO3Scene[] = {
4270 { "SO3CONVERTER_SPLIT_LARGE_MESHES", TYPVAR, "I", SCOL_TYPTYPE(so3Converter_SplitLargeMeshes)},
4271 { "SO3CONVERTER_GEN_SMOOTH_NORMALS", TYPVAR, "I", SCOL_TYPTYPE(so3Converter_GenSmoothNormals)},
4272 { "SO3CONVERTER_OPTIMIZE_MESHES", TYPVAR, "I", SCOL_TYPTYPE(so3Converter_OptimizeMeshes)},
4273 { "SO3CONVERTER_OPTIMIZE_SCENEGRAPH", TYPVAR, "I", SCOL_TYPTYPE(so3Converter_OptimizeGraph) },
4274 { "SO3CONVERTER_ROTATE_X", TYPVAR, "I", SCOL_TYPTYPE(so3Converter_RotateX) },
4275 { "SO3CONVERTER_GEN_LOD", TYPVAR, "I", SCOL_TYPTYPE(so3Converter_GenerateLod) },
4276 { "SO3CONVERTER_OPTIMIZE_TEXTURES", TYPVAR, "I", SCOL_TYPTYPE(so3Converter_OptimizeTextures)},
4277 { "SO3CONVERTER_OPTIMIZE_TEXTURES_VERYLOW",TYPVAR, "I", SCOL_TYPTYPE(so3Converter_OptimizeTextures_VeryLow)},
4278 { "SO3CONVERTER_OPTIMIZE_TEXTURES_LOW", TYPVAR, "I", SCOL_TYPTYPE(so3Converter_OptimizeTextures_Low)},
4279 { "SO3CONVERTER_OPTIMIZE_TEXTURES_MEDIUM", TYPVAR, "I", SCOL_TYPTYPE(so3Converter_OptimizeTextures_Medium)},
4280 { "SO3CONVERTER_OPTIMIZE_TEXTURES_HIGH", TYPVAR, "I", SCOL_TYPTYPE(so3Converter_OptimizeTextures_High)},
4281 { "SO3CONVERTER_OPTIMIZE_TEXTURES_VERYHIGH",TYPVAR, "I", SCOL_TYPTYPE(so3Converter_OptimizeTextures_VeryHigh)},
4282 { "SO3SceneLoadEntity", 4, "fun [SO3_SCENE S S P] SO3_OBJECT", SO3SceneLoadEntity },
4283 { "SO3SceneLoadEntityByResourceName", 4, "fun [SO3_SCENE S S S] SO3_OBJECT", SO3SceneLoadEntityByResourceName },
4284 { "SO3SceneLoadEntityInBackground", 6, "fun [SO3_SCENE S S P fun [SO3_OBJECT u0] u1 u0] SO3_OBJECT", SO3SceneLoadEntityInBackground },
4285 { "SO3SceneCloneEntity", 3, "fun [SO3_SCENE S SO3_OBJECT] SO3_OBJECT", SO3SceneCloneEntity },
4286 { "SO3SceneUnloadResource", 3, "fun [SO3_SCENE S I] I", SO3SceneUnloadResource },
4287 { "SO3SceneLoadResource", 4, "fun [SO3_SCENE S P I] I", SO3SceneLoadResource },
4288 { "SO3SceneCloneAnimation", 3, "fun [SO3_SCENE SO3_ANIM S] SO3_ANIM", SO3SceneCloneAnimation },
4289 { "SO3SceneCloneAnimTrack", 4, "fun [SO3_SCENE SO3_OBJECT SO3_ANIM SO3_ANIMTRACK] SO3_ANIMTRACK", SO3SceneCloneAnimTrack },
4290 { "SO3SceneLoadResourceMaterial", 3, "fun [SO3_SCENE S S] I", SO3SceneLoadResourceMaterial },
4291 { "SO3SceneCreate", 2, "fun [Chn S] SO3_SCENE", SO3SceneCreate },
4292 { "SO3SceneDelete", 1, "fun [SO3_SCENE] I", SO3SceneDelete },
4293 { "SO3SceneClear", 1, "fun [SO3_SCENE] I", SO3SceneClear },
4294 { "SO3SceneSetSkyBox", 7, "fun [SO3_SCENE SO3_MATERIAL F [F F F F] S I I] I", SO3SceneSetSkyBox },
4295 { "SO3SceneSetSkyBoxEnable", 2, "fun [SO3_SCENE I] I", SO3SceneSetSkyBoxEnable },
4296 { "SO3SceneGetSkyBoxParameters", 1, "fun [SO3_SCENE] [SO3_MATERIAL F [F F F F] I I]", SO3SceneGetSkyBoxParameters },
4297 { "SO3SceneSetSkyDome", 12, "fun [SO3_SCENE SO3_MATERIAL F [F F F F] F F I I I S I I] I", SO3SceneSetSkyDome },
4298 { "SO3SceneSetSkyDomeEnable", 2, "fun [SO3_SCENE I] I", SO3SceneSetSkyDomeEnable },
4299 { "SO3SceneGetSkyDomeParameters", 1, "fun [SO3_SCENE] [SO3_MATERIAL F F F I I I [F F F F] I I]", SO3SceneGetSkyDomeParameters },
4300 { "SO3SceneSetSkyPlane", 12, "fun [SO3_SCENE SO3_MATERIAL F [F F F] F F F I I S I I] I", SO3SceneSetSkyPlane },
4301 { "SO3SceneSetSkyPlaneEnable", 2, "fun [SO3_SCENE I] I", SO3SceneSetSkyPlaneEnable },
4302 { "SO3SceneGetSkyPlaneParameters", 1, "fun [SO3_SCENE] [SO3_MATERIAL F F F I I F [F F F] I I]", SO3SceneGetSkyPlaneParameters },
4303 { "SO3SceneSetAmbientLight", 2, "fun [SO3_SCENE I] I", SO3SceneSetAmbientLight },
4304 { "SO3SceneGetAmbientLight", 1, "fun [SO3_SCENE] I", SO3SceneGetAmbientLight },
4305 { "SO3SceneGetFogColor", 1, "fun [SO3_SCENE] I", SO3SceneGetFogColor },
4306 { "SO3SceneGetFogMode", 1, "fun [SO3_SCENE] I", SO3SceneGetFogMode },
4307 { "SO3SceneGetFogDensity", 1, "fun [SO3_SCENE] F", SO3SceneGetFogDensity },
4308 { "SO3SceneGetFogStart", 1, "fun [SO3_SCENE] F", SO3SceneGetFogStart },
4309 { "SO3SceneGetFogEnd", 1, "fun [SO3_SCENE] F", SO3SceneGetFogEnd },
4310 { "SO3SceneSetFog", 6, "fun [SO3_SCENE I I F F F] I", SO3SceneSetFog },
4311 { "SO3SceneGetNode", 2, "fun [SO3_SCENE S] SO3_OBJECT", SO3SceneGetNode },
4312 { "SO3SceneGetObject", 2, "fun [SO3_SCENE S] SO3_OBJECT", SO3SceneGetObject },
4313 { "SO3SceneNodeCreate", 2, "fun [SO3_SCENE S] SO3_OBJECT", SO3SceneNodeCreate },
4314 { "SO3SceneParseMaterialsFromGroup", 2, "fun [SO3_SCENE S] [SO3_MATERIAL r1]", SO3SceneParseMaterialsFromGroup },
4315 { "SO3SceneParseCompositorsFromGroup", 2, "fun [SO3_SCENE S] [S r1]", SO3SceneParseCompositorsFromGroup },
4316 { "SO3SceneParseSchemeFromGroup", 2, "fun [SO3_SCENE S] [S r1]", SO3SceneParseSchemeFromGroup },
4317 { "SO3SceneParseParticleSystemsFromGroup", 2, "fun [SO3_SCENE S] [S r1]", SO3SceneParseParticleSystemsFromGroup },
4318 { "SO3SceneGetMaterial", 3, "fun [SO3_SCENE S S] SO3_MATERIAL", SO3SceneGetMaterial },
4319 { "SO3SceneGetTexture", 3, "fun [SO3_SCENE S S] SO3_TEXTURE", SO3SceneGetTexture },
4320 { "SO3PlaneCreate", 6, "fun [SO3_SCENE S S [F F] [I I] [F F]] SO3_OBJECT", SO3PlaneCreate },
4321 { "SO3SphereCreate", 6, "fun [SO3_SCENE S S F I I] SO3_OBJECT", SO3SphereCreate },
4322 { "SO3ConeCreate", 6, "fun [SO3_SCENE S S F F I] SO3_OBJECT", SO3ConeCreate },
4323 { "SO3OctahedronCreate", 6, "fun [SO3_SCENE S S F F F] SO3_OBJECT", SO3OctahedronCreate },
4324 { "SO3CbScenePreRender", 3, "fun [SO3_SCENE fun [SO3_SCENE u0 I] u1 u0] SO3_SCENE", SO3CbScenePreRender },
4325 { "SO3CbScenePreRenderPhysic", 3, "fun [SO3_SCENE fun [SO3_SCENE u0 I] u1 u0] SO3_SCENE", SO3CbScenePreRenderPhysic },
4326 { "SO3CbScenePreRender2", 3, "fun [SO3_SCENE fun [SO3_SCENE u0 I] u1 u0] SO3_SCENE", SO3CbScenePreRender2 },
4327 { "SO3CbScenePostRender", 3, "fun [SO3_SCENE fun [SO3_SCENE u0 I] u1 u0] SO3_SCENE", SO3CbScenePostRender },
4328 { "SO3SceneCreateAnimationSequence", 2, "fun [SO3_SCENE S] SO3_ANIM", SO3SceneCreateAnimationSequence },
4329 { "SO3SceneGetAnimation", 2, "fun [SO3_SCENE S] SO3_ANIM", SO3SceneGetAnimation },
4330 { "SO3SceneGetAnimations", 1, "fun [SO3_SCENE] [SO3_ANIM r1]", SO3SceneGetAnimations },
4331 { "SO3SceneGetNumAnimations", 1, "fun [SO3_SCENE] I", SO3SceneGetNumAnimations },
4332 { "SO3SceneLoadFile", 5, "fun [SO3_SCENE S P SO3_OBJECT I] I", SO3SceneLoadFile },
4333 { "SO3SceneConvertFile", 3, "fun [P S I] P", SO3SceneConvertFile },
4334 { "SO3SceneLoadFileEx", 6, "fun [SO3_SCENE S P SO3_OBJECT I F] I", SO3SceneLoadFileEx },
4335 { "SO3SceneConvertFileEx", 4, "fun [P S I F] P", SO3SceneConvertFileEx },
4336 { "SO3SceneSetMaterialsPointSize", 2, "fun [SO3_SCENE F] SO3_SCENE", SO3SceneSetMaterialsPointSize }
4337};
4338
4339
4345int SCOLloadScene(mmachine m, cbmachine w)
4346{
4347 SCENE_PRE_RENDER_EVENT = OBJgetUserEvent();
4349 SCENE_PRE_RENDER_EVENT2 = OBJgetUserEvent();
4351 SCENE_POST_RENDER_EVENT = OBJgetUserEvent();
4353 SCENE_PRE_RENDER_PHYSIC_EVENT = OBJgetUserEvent();
4355
4356 OBJECT_LOADED_EVENT = OBJgetUserEvent();
4358
4359 return PKhardpak2(m, "SO3Scene.pkg", sizeof(natSO3Scene) / sizeof(natSO3Scene[0]), natSO3Scene);
4360}
int getScenePostRenderEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
int SCENE_POST_RENDER_EVENT
Definition SO3SCOL.cpp:191
int getScenePreRenderEvent2(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
int getScenePreRenderEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
int SCENE_PRE_RENDER_EVENT2
Definition SO3SCOL.cpp:190
int SCOLloadScene(mmachine m, cbmachine w)
Load the SO3Engine Viewport function.
int getScenePreRenderPhysicEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
int SCENE_PRE_RENDER_PHYSIC_EVENT
Definition SO3SCOL.cpp:192
int SCENE_PRE_RENDER_EVENT
main include
Definition SO3SCOL.cpp:189
NativeDefinition natSO3Scene[]
int createEntinyAnimationsScol(mmachine m, SEntity *entity)
Definition SCOLScene.cpp:77
SRoot * scolRoot
Shared data.
Definition SO3SCOL.cpp:186
int OBJECT_LOADED_EVENT
Definition SO3SCOL.cpp:194
int getObjectLoadedEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
Definition SO3SCOL.cpp:5150
SCOL_EXPORT void SCOL_PTR_TYPE param
Definition SO3SCOL.cpp:5089
int createAnimTrack(mmachine m, SAnimTrack *curAnimTrack, SAnim *curAnim)
int SO3PHYSICCONTRAINT
Definition SO3SCOL.cpp:100
int SO3PHYSICSMATERIALTYPE
Definition SO3SCOL.cpp:95
int createTexture(mmachine m, STexture *curTexture, SScene *curScene)
int createAnim(mmachine m, SAnim *curAnim, SNode *curNode)
int SO3MATERIAL
Definition SO3SCOL.cpp:97
int SO3SCENETYPE
Definition SO3SCOL.cpp:88
int SO3TERRAINTYPE
Definition SO3SCOL.cpp:91
int SO3OBJTYPE
Definition SO3SCOL.cpp:90
int SO3ANIM
Definition SO3SCOL.cpp:92
int createOrRetrieveScolMaterialAndSendToVM(mmachine m, SScene *scene, SMaterial *mat)
int createObject(mmachine m, SNode *curNode, SScene *curScene)
int SO3TEXTURE
Definition SO3SCOL.cpp:98
int createBone(mmachine m, SNode *curNode, SScene *curScene, SNode *curFather)
static std::string cleanString(std::string str, bool toLower=true, bool clASCII=true, bool clSpaces=true, bool bUID=true)
Clean a string.
Base class for SO3 custom exception.
const char * what() const
int SO3SceneCreateAnimationSequence(mmachine m)
SO3SceneCreateAnimationSequence : Create a Scene Animation sequence.
int SO3SceneConvertFileEx(mmachine m)
SO3SceneConvertFileEx : Convert a file.
int SO3SceneLoadResourceMaterial(mmachine m)
SO3SceneLoadResourceMaterial :Load Resource Material in Scene Deprecated
int SO3SceneGetSkyPlaneParameters(mmachine m)
SO3SceneGetSkyPlaneParameters : function to get the sky plane parameters.
int SO3SceneGetObject(mmachine m)
SO3SceneGetObject : return a scene object by its name.
int SO3SceneGetFogEnd(mmachine m)
SO3SceneGetFogEnd : function to get the fog end of the scene.
int SO3SphereCreate(mmachine m)
SO3SphereCreate : create a sphere as a SO3_OBJECT.
int SO3SceneClear(mmachine m)
SO3SceneClear : clear a scene.
int SO3SceneSetSkyBox(mmachine m)
SO3SceneSetSkyBox : function to set a sky box for a scene.
int SO3OctahedronCreate(mmachine m)
SO3OctahedronCreate : create an octahedron as a SO3_OBJECT.
int SO3CbScenePreRender2(mmachine m)
SO3CbScenePreRender2 : defines callback for pre render event, but after the animations and physics up...
int SO3SceneGetFogMode(mmachine m)
SO3SceneGetFogColor : function to get the fog mode of the scene.
int SO3SceneLoadFile(mmachine m)
SO3SceneLoadFile : create an Entity as a new SO3_Object.
int SO3SceneSetSkyPlane(mmachine m)
SO3SceneSetSkyPlane : function to set a sky plane for a scene.
int SO3SceneGetFogDensity(mmachine m)
SO3SceneGetFogDensity : function to get the fog density of the scene.
int SO3SceneGetAnimation(mmachine m)
SO3SceneGetAnimation : return an animation by its name.
int SO3PlaneCreate(mmachine m)
SO3PlaneCreate : create a plane as a SO3_OBJECT.
int SO3SceneCreate(mmachine m)
SO3SceneCreate : Create a new scene.
int SO3SceneGetTexture(mmachine m)
SO3SceneGetTexture : Return a texture by its name.
int SO3SceneParseMaterialsFromGroup(mmachine m)
SO3SceneParseMaterialsFromGroup : Return the list of materials from a group name.
int SO3SceneGetAmbientLight(mmachine m)
SO3SceneGetAmbientLight : function to get the ambient light of the scene.
int SO3SceneParseParticleSystemsFromGroup(mmachine m)
SO3SceneParseParticleSystemsFromGroup : Return the list of particle systems from a group name.
int SO3SceneParseCompositorsFromGroup(mmachine m)
SO3SceneParseCompositorsFromGroup : Return the list of compositors from a group name.
int SO3SceneLoadResource(mmachine m)
SO3SceneLoadResource : Load a resource in Scene.
int SO3SceneNodeCreate(mmachine m)
SO3SceneNodeCreate : Create a new node.
int SO3SceneGetNumAnimations(mmachine m)
SO3SceneGetNumAnimations : return an animation by its name.
int SO3SceneGetSkyDomeParameters(mmachine m)
SO3SceneGetSkyDomeParameters : function to get the sky dome parameters.
int SO3SceneSetAmbientLight(mmachine m)
SO3SceneSetAmbientLight : function to defines ambient light of the scene.
int SO3SceneGetAnimations(mmachine m)
SO3SceneGetAnimations : Return the list of animations on a scene.
int SO3ConeCreate(mmachine m)
SO3ConeCreate : create a cone as a SO3_OBJECT.
int SO3CbScenePreRenderPhysic(mmachine m)
SO3CbScenePreRenderPhysic : defines callback for pre render event, but after the animations and befor...
int SO3SceneLoadFileEx(mmachine m)
SO3SceneLoadFileEx : create an Entity as a new SO3_Object.
int SO3SceneCloneAnimation(mmachine m)
SO3SceneCloneAnimation : Clone a SO3_ANIM in Scene.
int SO3SceneCloneAnimTrack(mmachine m)
SO3SceneCloneAnimTrack : Clone a SO3_ANIMTRACK in Scene on a given SO3_ANIM DEPRECATED FUNCTION Proto...
int SO3SceneLoadEntity(mmachine m)
SO3SceneLoadEntity : create an Entity as a new SO3_Object.
int SO3CbScenePostRender(mmachine m)
SO3CbScenePostRender : defines callback for post render event.
int SO3SceneGetFogStart(mmachine m)
SO3SceneGetFogStart : function to get the fog start of the scene.
int SO3SceneSetFog(mmachine m)
SO3SceneSetFog : function to defines fog properties of the scene.
int SO3SceneSetMaterialsPointSize(mmachine m)
SO3SceneSetMaterialsPointSize : Set all scene materials point cloud size.
int SO3SceneGetMaterial(mmachine m)
SO3SceneGetMaterial : Return a material by its name.
int SO3SceneGetFogColor(mmachine m)
SO3SceneGetFogColor : function to get the fog color of the scene.
int SO3SceneCloneEntity(mmachine m)
SO3SceneCloneEntity : clone an Entity as a new SO3_Object.
int SO3SceneConvertFile(mmachine m)
SO3SceneConvertFile : Convert a file.
int SO3SceneSetSkyDomeEnable(mmachine m)
SO3SceneSetSkyDomeEnable : function to defines visiblity state for a sky dome.
int SO3SceneLoadEntityInBackground(mmachine m)
SO3SceneLoadEntityInBackground : create an Entity as a new SO3_Object.
int SO3SceneSetSkyDome(mmachine m)
SO3SceneSetSkyDome : function to set a sky dome for a scene.
int SO3SceneUnloadResource(mmachine m)
SO3SceneUnloadResource : Unload a resource from Scene TODO!
int SO3CbScenePreRender(mmachine m)
SO3CbScenePreRender : defines callback for pre render event.
int SO3SceneSetSkyBoxEnable(mmachine m)
SO3SceneSetSkyBox : function to defines visiblity state for a sky box.
int SO3SceneDelete(mmachine m)
SO3SceneDelete : destroy a scene.
int SO3SceneParseSchemeFromGroup(mmachine m)
SO3SceneParseSchemeFromGroup : Return the list of material scheme from a group name.
int SO3SceneGetNode(mmachine m)
SO3SceneGetNode : return a scene node by its name.
int SO3SceneLoadEntityByResourceName(mmachine m)
SO3SceneLoadEntityByResourceName : create an Entity as a new SO3_Object.
int SO3SceneSetSkyPlaneEnable(mmachine m)
SO3SceneSetSkyPlaneEnable : function to defines visiblity state for a sky plane.
int SO3SceneGetSkyBoxParameters(mmachine m)
SO3SceneGetSkyBoxParameters : function to get the sky box parameters.
STBI_EXTERN unsigned long flags
Definition stb_image.h:1182