Jump to content

Josh

Staff
  • Posts

    24,629
  • Joined

  • Last visited

Everything posted by Josh

  1. Hi, A point to a Lua function is just the function name: function loadhook(progress) Print(progress) end LoadMap("Maps/test.map", "loadhook") In Ultra, the Lua binding system I am using provides more control, and the Lua function itself can be passed to functions.
  2. You can create an instance or copy of it in another world. Switching worlds would probably cause a lot of problems.
  3. Yeah, it's fixed, I just have not updated the lib. I'll do it within a couple hours from now.
  4. Newton forum is back up: http://newtondynamics.com/forum/viewtopic.php?f=12&t=9825
  5. Update Lua template executables, functionality is complete up through the terrain class in the documentation.
  6. What would I do without @SpiderPig?
  7. @SpiderPigThe lib has been updated with this fix now.
  8. Lots of functionality added in the Lua API. Not complete, but I have worked through to the Light class in the documentation.
  9. Added executables and scripts to Lua template folder. Haven't tested these much yet.
  10. Here is the project I used to generate the Lua docs from C++: chatgpt.zip
  11. I'm using this to generate Lua documentation from the existing C++ content. Here is a simple example to use the API. #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <windows.h> #endif #include <string> #include <curl/curl.h> #include "json.hpp" std::string APIKEY = ""; std::string logtext; #ifndef _DEBUG BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: curl_global_init(0); break; case DLL_PROCESS_DETACH: curl_global_cleanup(); break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: break; } return TRUE; } #endif void Print(const std::string& s) { OutputDebugStringA(s.c_str()); printf((s + std::string("\n")).c_str()); if (not logtext.empty()) logtext += "\n"; logtext += s; } size_t WriteCallback(char* contents, size_t size, size_t nmemb, void* userp) { ((std::string*)userp)->append((char*)contents, size * nmemb); return size * nmemb; } // trim from start (in place) static inline void ltrim(std::string& s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); } // trim from end (in place) static inline void rtrim(std::string& s) { s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); } // trim from both ends (in place) static inline void trim(std::string& s) { rtrim(s); ltrim(s); } std::string Chat(const std::string prompt, const std::string& APIKEY) { std::string response; bool success = false; std::string imageurl; if (APIKEY.empty()) return 0; std::string url = "https://api.openai.com/v1/chat/completions"; std::string readBuffer; std::string bearerTokenHeader = "Authorization: Bearer " + APIKEY; std::string contentType = "Content-Type: application/json"; auto curl = curl_easy_init(); struct curl_slist* headers = NULL; headers = curl_slist_append(headers, bearerTokenHeader.c_str()); headers = curl_slist_append(headers, contentType.c_str()); nlohmann::json j3, msg; j3["model"] = "gpt-3.5-turbo"; j3["messages"] = {}; msg["role"] = "user"; msg["content"] = prompt; j3["messages"].push_back(msg); std::string postfields = j3.dump(); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postfields.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); auto errcode = curl_easy_perform(curl); if (errcode == CURLE_OK) { //OutputDebugStringA(readBuffer.c_str()); trim(readBuffer); if (readBuffer.size() > 1 and readBuffer[0] == '{' and readBuffer[readBuffer.size() - 1] == '}') { j3 = nlohmann::json::parse(readBuffer); if (j3.is_object()) { if (j3["error"].is_object()) { if (j3["error"]["message"].is_string()) { std::string msg = j3["error"]["message"]; msg = "Error: " + msg; Print(msg.c_str()); } else { Print("Error: Unknown error."); } } else { if (j3["data"].is_array() or j3["data"].size() == 0) { if (j3["choices"].is_array() and not j3["choices"].empty()) { std::string s = j3["choices"][0]["message"]["content"]; response = s; success = true; } } } } else { Print("Error: Response is not a valid JSON object."); Print(readBuffer); } } else { Print("Error: Response is not a valid JSON object."); Print(readBuffer); } } else { Print("Error: Request failed."); } curl_easy_cleanup(curl); return response; } int main(int argc, char* argv[]) { std::string key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; std::string prompt = "What is 2 plus 3?"; std::string response = Chat(prompt, key); printf(response.c_str()); return 0; }
  12. I tried commenting out the assert statement. In my code below, any rotation closer to 180 causes the joint to just not react. I suppose this is better than crashing, but still not ideal. #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { auto displays = GetDisplays(); auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); auto framebuffer = CreateFramebuffer(window); auto world = CreateWorld(); auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetPosition(0, 0, -4); camera->SetDebugPhysicsMode(true); auto light = CreateDirectionalLight(world); light->SetRotation(35, 35, 0); auto box = CreateCylinder(world, 0.5f, 1.8f); box->SetMass(1.0f); auto joint = CreateKinematicJoint(box->position, box); while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { if (window->KeyHit(KEY_SPACE)) { joint->SetPose(Vec3(0, 0, 0), Vec3(0, 178.6, 0)); } world->Update(); world->Render(framebuffer); } return 0; }
  13. Oh, I see. There is a camera in the scene that is getting used to render the viewport...
  14. Yeah, so I think we are talking about a feature for a static visibility list.
  15. Reported here: https://github.com/MADEAPPS/newton-dynamics/issues/321
  16. It seems to be because the target rotation is 180 degrees away from the current orientation. Maybe the solver can't decide which way to turn? Line 337 of dgCustomKinematicController.cpp: dAssert(lateralDir.DotProduct3(lateralDir) > 1.0e-6f); Simplified example: #include "UltraEngine.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { auto displays = GetDisplays(); auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); auto framebuffer = CreateFramebuffer(window); auto world = CreateWorld(); auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetPosition(0, 0, -8); camera->SetDebugPhysicsMode(true); auto light = CreateDirectionalLight(world); light->SetRotation(35, 35, 0); auto box = CreateCylinder(world, 0.5f, 1.8f); box->SetMass(1.0f); auto joint = CreateKinematicJoint(box->position, box); while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { joint->SetPose(Vec3(0, 0, 0), Vec3(0,180,0)); world->Update(); world->Render(framebuffer); } return 0; }
  17. Added brush texture mapping scale setting in general options. Fixed some events not being detected.
  18. 1. and 2. are fixed. 3. is not technically a bug.
  19. Added Joint::GetMaxForce and GetMaxTorque Fixed Joint::SetMaxForce bug
×
×
  • Create New...