 Any guy Guest |
Quote
|
2023-07-07 05:24:23 |
|
I have this code snippet in a function created in the CplayerScript.cpp file:
irr::io::IAttributes* attr = LastPlayer->Scripting->createParameterListFromScriptObject(obj);
if (attr && attr->getAttributeCount() == 1) { irr::core::stringc filename = attr->getAttributeAsString(0); irr::video::IVideoDriver* driver = LastPlayer->Device->getVideoDriver(); irr::scene::ISceneManager* smgr = LastPlayer->Device->getSceneManager(); irr::scene::IAnimatedMesh* mesh = smgr->getMesh(filename.c_str()); scene::IMeshSceneNode* node = nullptr; if (node) { node = smgr->addMeshSceneNode(mesh); node->setMaterialFlag(video::EMF_LIGHTING, false); node->setScale(core::vector3df(1.0f, 1.0f, 1.0f)); node->setRotation(core::vector3df(0.0f, 0.0f, 0.0f)); node->setPosition(core::vector3df(0.0f, 0.0f, 0.0f)); } } if (attr) attr->drop(); return 0;
This code is just a prototype that I was testing and it was just to see if it worked
I created a function in the engine that when a key is pressed it executes this script:
Ccbloadfile("object.obj")//// function name in c++
Then compiling and going to cmd and running this command
Win32player -debug
When I press the A key this is shown in the console
Mesh loaded "object.obj" , But it is not shown in the object scene, how do I render it?
|
 just_in_case Moderator |
Quote
|
2023-07-07 06:16:42 |
|
Hi there, please write your title of the post in English as well whenever you post something.
Also there is already, 3D models loading has been added to the extended API by me, I added this when @sven created .obj loader for his javascript.
So in the next update you will already be able to laod the models with CC using javascript API. I haven't tested with all the formats but it works with most of them.
|
 Any guy Guest |
Quote
|
2023-07-07 14:05:43 |
|
Sorry is that English is not my native language, I'm using Google translator, sometimes I forget to translate some things, but back to the main subject, thanks for the information
|
 any guy Guest |
Quote
|
2023-07-09 03:35:41 |
|
I made this script in c++ to load an obj file and it worked perfectly, example of a js api call:
ccbLoadDyanmicFileObj("model/example.obj","building",0,0,0,0,0,0,3,3,3);
1-argument: the file
2-argument: node name is always added a number at the end, example if you want to call this node you will have to use building1 and so on...(I hope it's clear)
3-argument: position x
4-argument: position y
5-argument: position z
6-argument: rotation x
7-argument: rotation y
8-argument: z rotation
9-scale: x scale
10-argument: scale y
11-argument: z scale
function in c:
long CPlayer::ccbLoadDyanmicFileObj(irr::ScriptFunctionParameterObject obj) {
int returnCount = 0;
irr::io::IAttributes* attr = LastPlayer->Scripting->createParameterListFromScriptObject(obj);
if (attr && attr->getAttributeCount() == 8) { const irr::core::stringc filePath = attr->getAttributeAsString(0); const irr::core::stringc nodename = attr->getAttributeAsString(1); float Posx = attr->getAttributeAsFloat(2); float Posy = attr->getAttributeAsFloat(3); float Posz = attr->getAttributeAsFloat(4); float Scalx = attr->getAttributeAsFloat(5); float Scaly = attr->getAttributeAsFloat(6); float Scalz = attr->getAttributeAsFloat(7);
irr::scene::ISceneManager* smgr = LastPlayer->CurrentSceneManager;
if (smgr) { irr::scene::IAnimatedMesh* mesh = smgr->getMesh(filePath.c_str());
if (mesh) { irr::scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
if (node) { node->setMaterialFlag(irr::video::EMF_LIGHTING, true); node->setPosition(irr::core::vector3df(Posx, Posy, Posz)); node->setScale(irr::core::vector3df(Scalx, Scaly, Scalz)); setUniqueNameForSceneNode(node,nodename.c_str(),smgr); returnCount = 1; } } } }
if (attr) attr->drop();
return returnCount; }
thank you for your attention.
|
 any guy Guest |
Quote
|
2023-07-09 03:37:34 |
|
Sorry I sent the code without all the arguments, updated code below:
long CPlayer::ccbLoadDyanmicFileObj(irr::ScriptFunctionParameterObject obj) { irr::io::IAttributes* attr = LastPlayer->Scripting->createParameterListFromScriptObject(obj);
if (attr && attr->getAttributeCount() == 11) { const irr::core::stringc filePath = attr->getAttributeAsString(0); const irr::core::stringc nodename = attr->getAttributeAsString(1); float Posx = attr->getAttributeAsFloat(2); float Posy = attr->getAttributeAsFloat(3); float Posz = attr->getAttributeAsFloat(4); float Rotx = attr->getAttributeAsFloat(5); float Roty = attr->getAttributeAsFloat(6); float Rotz = attr->getAttributeAsFloat(7); float Scalx = attr->getAttributeAsFloat(8); float Scaly = attr->getAttributeAsFloat(9); float Scalz = attr->getAttributeAsFloat(10);
irr::scene::ISceneManager* smgr = LastPlayer->CurrentSceneManager;
if (smgr) { irr::scene::IAnimatedMesh* mesh = smgr->getMesh(filePath.c_str());
if (mesh) { irr::scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
if (node) { node->setMaterialFlag(irr::video::EMF_LIGHTING, true); node->setPosition(irr::core::vector3df(Posx, Posy, Posz)); node->setRotation(irr::core::vector3df(Rotx, Roty, Rotz)); node->setScale(irr::core::vector3df(Scalx, Scaly, Scalz)); setUniqueNameForSceneNode(node,nodename.c_str(),smgr); } } } }
if (attr) attr->drop();
return 0; }
|