WIP: Experiment with solvespace library #114757

Draft
Jacques Lucke wants to merge 1 commits from JacquesLucke/blender:slvs-test into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Playing with the CAD Sketcher addon made me want to play with the solvespace library. I don't have any concrete plan to continue to work on this myself, just wanted to get a better understand for how it works for now.

The image shows how the library solves a distance constraint between the two vertices.

image

Testing this currently requires some manual effort to get the library to link. I had to apply the changes below to solvespace so that it results in a static library without additional dependencies.

Solvespace Patch
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0e9129f..b3c5aa3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -66,7 +66,7 @@ if(APPLE)
 endif()
 
 # libslvs
-add_library(slvs SHARED
+add_library(slvs STATIC
     solvespace.h
     platform/platform.h
     util.cpp
diff --git a/src/platform/platform.cpp b/src/platform/platform.cpp
index 6ad19dc..fa29466 100644
--- a/src/platform/platform.cpp
+++ b/src/platform/platform.cpp
@@ -698,22 +698,21 @@ void DebugPrint(const char *fmt, ...) {
 //-----------------------------------------------------------------------------
 
 struct MimallocHeap {
+    std::vector<void *> buffers;
     mi_heap_t *heap = NULL;
 
     ~MimallocHeap() {
-        if(heap != NULL)
-            mi_heap_destroy(heap);
+        for (void *buffer : buffers) {
+            free(buffer);
+        }
     }
 };
 
 static thread_local MimallocHeap TempArena;
 
 void *AllocTemporary(size_t size) {
-    if(TempArena.heap == NULL) {
-        TempArena.heap = mi_heap_new();
-        ssassert(TempArena.heap != NULL, "out of memory");
-    }
-    void *ptr = mi_heap_zalloc(TempArena.heap, size);
+    void *ptr = malloc(size);
+    TempArena.buffers.push_back(ptr);
     ssassert(ptr != NULL, "out of memory");
     return ptr;
 }
Playing with the [CAD Sketcher](https://www.cadsketcher.com/) addon made me want to play with the [solvespace](https://github.com/solvespace/solvespace) library. I don't have any concrete plan to continue to work on this myself, just wanted to get a better understand for how it works for now. The image shows how the library solves a distance constraint between the two vertices. ![image](/attachments/be93dfa5-f9a4-43bc-b5c7-974b54b382d2) Testing this currently requires some manual effort to get the library to link. I had to apply the changes below to [solvespace](https://github.com/solvespace/solvespace) so that it results in a static library without additional dependencies. <details> <summary>Solvespace Patch</summary> ```diff diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0e9129f..b3c5aa3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,7 +66,7 @@ if(APPLE) endif() # libslvs -add_library(slvs SHARED +add_library(slvs STATIC solvespace.h platform/platform.h util.cpp diff --git a/src/platform/platform.cpp b/src/platform/platform.cpp index 6ad19dc..fa29466 100644 --- a/src/platform/platform.cpp +++ b/src/platform/platform.cpp @@ -698,22 +698,21 @@ void DebugPrint(const char *fmt, ...) { //----------------------------------------------------------------------------- struct MimallocHeap { + std::vector<void *> buffers; mi_heap_t *heap = NULL; ~MimallocHeap() { - if(heap != NULL) - mi_heap_destroy(heap); + for (void *buffer : buffers) { + free(buffer); + } } }; static thread_local MimallocHeap TempArena; void *AllocTemporary(size_t size) { - if(TempArena.heap == NULL) { - TempArena.heap = mi_heap_new(); - ssassert(TempArena.heap != NULL, "out of memory"); - } - void *ptr = mi_heap_zalloc(TempArena.heap, size); + void *ptr = malloc(size); + TempArena.buffers.push_back(ptr); ssassert(ptr != NULL, "out of memory"); return ptr; } ``` </details>
118 KiB
Jacques Lucke added 1 commit 2023-11-12 13:01:43 +01:00

I have no any experience with any CAD (just few know about its workflow and seen video series about developing simple CAD on C#). Is that contastaits is something like system to solve to compute final transform? I hope that could be builded from a field. Just not sure if solvespace workflow is similar to geometry nodes one. Wondering you already have thought about that?

I have no any experience with any CAD (just few know about its workflow and seen video series about developing simple CAD on C#). Is that contastaits is something like system to solve to compute final transform? I hope that could be builded from a field. Just not sure if solvespace workflow is similar to geometry nodes one. Wondering you already have thought about that?
Author
Member

I don't think the solving would be integrated into geometry nodes (at least at the beginning). I'm just putting my experiments into nodes because that's the area I know best. The solving is more likely to be done on original geometry, similar to what the CAD Sketcher addon does, maybe just give it a try.

I don't think the solving would be integrated into geometry nodes (at least at the beginning). I'm just putting my experiments into nodes because that's the area I know best. The solving is more likely to be done on original geometry, similar to what the CAD Sketcher addon does, maybe just give it a try.
This pull request has changes conflicting with the target branch.
  • source/blender/nodes/geometry/CMakeLists.txt

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u slvs-test:JacquesLucke-slvs-test
git checkout JacquesLucke-slvs-test
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#114757
No description provided.