├── .github
└── workflows
│ └── c-cpp.yml
├── .gitmodules
├── CMakeLists.txt
├── README.html
├── README.md
├── README.tex.md
├── assignment_setup.h
├── cmake
└── FindLIBIGL.cmake
├── data
├── sphere.obj
├── square_cloth.obj
└── triangle.obj
├── images
├── 01f349799d08738b3ed7187a8adfa8b7.svg
├── 034d0a6be0424bffe9a6e7ac9236c0f5.svg
├── 07617f9d8fe48b4a7b3f523d6730eef0.svg
├── 07640d208ac0851eb169c73b736e6bb1.svg
├── 0a36368a7b551a7c6aa055de5009bea3.svg
├── 1757afe2b054e59c6d5c465cf82bd885.svg
├── 1767c7f7922c97563d66b8446ba75840.svg
├── 1e910408a8c30e48164f77629c847ebe.svg
├── 286f7d4815c0996530bda7973b1ec5ea.svg
├── 2ad9d098b937e46f9f58968551adac57.svg
├── 2f118ee06d05f3c2d98361d9c30e38ce.svg
├── 357a3518901055dabec2b6272f82e942.svg
├── 36b5afebdba34564d884d347484ac0c7.svg
├── 3b6459009b4b915041dfd6286e7e0c2b.svg
├── 3def24cf259215eefdd43e76525fb473.svg
├── 3e365d0313ccf4a7bdc45ac83825ea92.svg
├── 52999a1482045a0142d3cbd60a381afe.svg
├── 57354dd3723345bfc2d7b2a89dd465a7.svg
├── 57d6ce76b81f64d9de86d723aaf06fcf.svg
├── 58c2313bc1ea66cc4d86d27f83c1941d.svg
├── 5c09159163d9a8fe55c1a3016a3ad75a.svg
├── 5cae4b0b649a9b8d2fe83816e5ea8db6.svg
├── 6018bf12266e0674a19d0a622989ad88.svg
├── 6f6d7d2d59fa79786810222c5181b7c8.svg
├── 77a3b857d53fb44e33b53e4c8b68351a.svg
├── 79361f938b80de1c32bb7d7724ce3590.svg
├── 7c7c6fbc6e734e01d65098befa8bd28f.svg
├── 82f2067d05c8a81659bc2b949d23b64a.svg
├── 84a62034abeb6bfffada277b45a096c7.svg
├── 870c98e8c4b120f06c7a15af3b02d6e7.svg
├── 97c7f491f7ac1623c0a86b1fb656029b.svg
├── 985383447914a70e21e1b46c8b075b81.svg
├── 9a05c8a8b310cb0d9f34636450b3d442.svg
├── 9f2b6b0a7f3d99fd3f396a1515926eb3.svg
├── a0d1fd43ad34510636923359f83becfa.svg
├── a8c1f0c39cf12de6d64430cd9bc86046.svg
├── a9a3a4a202d80326bda413b5562d5cd1.svg
├── aba2578ca1be0bea64b5de8519cf7b12.svg
├── ac3148a5746b81298cb0c456b661f197.svg
├── b23332f99af850a48831f80dbf681ed6.svg
├── b38dda0a0c1ab15d9dae0b9b9e8aa1dc.svg
├── b56595d2a30a0af329086562ca12d521.svg
├── b8bc815b5e9d5177af01fd4d3d3c2f10.svg
├── b93e9b71beaf724ff1d0f85841e9ae61.svg
├── bccab73005d96290c8ef588703533a21.svg
├── bfdc1036a225b1cba16ea97fa96d82de.svg
├── c019432b974b538f20a9d3cb38176a2d.svg
├── c36ef0ba4721f49285945f33a25e7a45.svg
├── c83e439282bef5aadf55a91521506c1a.svg
├── ca2d7f8fc10bcbce38360119af40ad8e.svg
├── cloth.gif
├── d05b996d2c08252f77613c25205a0f04.svg
├── df63751855fcec904c3e28f701952a87.svg
├── e846e5631eca1fe2f735605515f5be61.svg
├── e9c52417462e27805f522b91127f71ab.svg
├── ea4bbf715156e61bd05c0ec553601019.svg
├── fd8be73b54f5436a5cd2e73ba9b6bfa9.svg
├── fdacaa2009a566aee165e36a976fa9cd.svg
└── fe4e62694c7a379a0b31c6aa14046dd0.svg
├── include
├── T_cloth.h
├── V_membrane_corotational.h
├── V_spring_particle_particle.h
├── assemble_forces.h
├── assemble_stiffness.h
├── collision_detection_cloth_sphere.h
├── d2V_membrane_corotational_dq2.h
├── dV_cloth_gravity_dq.h
├── dV_membrane_corotational_dq.h
├── dV_spring_particle_particle_dq.h
├── dphi_cloth_triangle_dX.h
├── dsvd.h
├── fixed_point_constraints.h
├── linearly_implicit_euler.h
├── mass_matrix_mesh.h
├── pick_nearest_vertices.h
└── velocity_filter_cloth_sphere.h
├── main.cpp
├── shared
├── include
│ ├── EigenTypes.h
│ ├── find_max_vertices.h
│ ├── find_min_vertices.h
│ ├── init_state.h
│ ├── read_tetgen.h
│ └── visualization.h
└── src
│ ├── find_max_vertices.cpp
│ ├── find_min_vertices.cpp
│ ├── init_state.cpp
│ ├── read_tetgen.cpp
│ └── visualization.cpp
├── src
├── T_cloth.cpp
├── V_membrane_corotational.cpp
├── V_spring_particle_particle.cpp
├── assemble_forces.cpp
├── assemble_stiffness.cpp
├── collision_detection_cloth_sphere.cpp
├── d2V_membrane_corotational_dq2.cpp
├── dV_cloth_gravity_dq.cpp
├── dV_membrane_corotational_dq.cpp
├── dV_spring_particle_particle_dq.cpp
├── dphi_cloth_triangle_dX.cpp
├── dsvd.cpp
├── fixed_point_constraints.cpp
├── mass_matrix_mesh.cpp
├── pick_nearest_vertices.cpp
└── velocity_filter_cloth_sphere.cpp
└── tex
├── 01f349799d08738b3ed7187a8adfa8b7.svg
├── 06e2a3399a63952999493870081a4d64.svg
├── 07617f9d8fe48b4a7b3f523d6730eef0.svg
├── 07640d208ac0851eb169c73b736e6bb1.svg
├── 07fa8f51f4cd0e31f63743c0638a3388.svg
├── 0a36368a7b551a7c6aa055de5009bea3.svg
├── 1757afe2b054e59c6d5c465cf82bd885.svg
├── 1767c7f7922c97563d66b8446ba75840.svg
├── 1e910408a8c30e48164f77629c847ebe.svg
├── 247ed86bbeef7615018d6bc51947544a.svg
├── 286f7d4815c0996530bda7973b1ec5ea.svg
├── 319d907db67f3000780e9b2d1a2816d9.svg
├── 357a3518901055dabec2b6272f82e942.svg
├── 358bf7b214f6e3ed24776b7ec9a31866.svg
├── 36b5afebdba34564d884d347484ac0c7.svg
├── 3b6459009b4b915041dfd6286e7e0c2b.svg
├── 3ccec9688059decb33d458cf7478ec22.svg
├── 3def24cf259215eefdd43e76525fb473.svg
├── 3ed8894ad18b8f13e6b16019cd987ca2.svg
├── 46e42d6ebfb1f8b50fe3a47153d01cd2.svg
├── 4f4f4e395762a3af4575de74c019ebb5.svg
├── 52999a1482045a0142d3cbd60a381afe.svg
├── 56521ffe4b9da108377a9739876d408a.svg
├── 57354dd3723345bfc2d7b2a89dd465a7.svg
├── 57d6ce76b81f64d9de86d723aaf06fcf.svg
├── 58c2313bc1ea66cc4d86d27f83c1941d.svg
├── 5c09159163d9a8fe55c1a3016a3ad75a.svg
├── 5c9c456d532a537597b4c601b26a1c23.svg
├── 5cae4b0b649a9b8d2fe83816e5ea8db6.svg
├── 5d9ea342efc9120401f89cbe3f833ad1.svg
├── 6018bf12266e0674a19d0a622989ad88.svg
├── 6bac6ec50c01592407695ef84f457232.svg
├── 77a3b857d53fb44e33b53e4c8b68351a.svg
├── 79361f938b80de1c32bb7d7724ce3590.svg
├── 7d6ab38d6d05964698ae8a092d1948fc.svg
├── 7f9c21b8882b50ee8b7a2ba3d6be1d09.svg
├── 82f2067d05c8a81659bc2b949d23b64a.svg
├── 84a62034abeb6bfffada277b45a096c7.svg
├── 870c98e8c4b120f06c7a15af3b02d6e7.svg
├── 873246b3685f69b2a152de8f0199546c.svg
├── 88787d1576b44fdadc099c2c2d5cd9f6.svg
├── 97c7f491f7ac1623c0a86b1fb656029b.svg
├── 99876db7d3f4ab121c85347e0275a67f.svg
├── 9a05c8a8b310cb0d9f34636450b3d442.svg
├── 9b01119ffd35fe6d8a8795a24fc11616.svg
├── 9f2b6b0a7f3d99fd3f396a1515926eb3.svg
├── a0d1fd43ad34510636923359f83becfa.svg
├── a8c1f0c39cf12de6d64430cd9bc86046.svg
├── a9a3a4a202d80326bda413b5562d5cd1.svg
├── ab23897fbb310593a19e9659aff87d65.svg
├── ac3148a5746b81298cb0c456b661f197.svg
├── b23332f99af850a48831f80dbf681ed6.svg
├── b38dda0a0c1ab15d9dae0b9b9e8aa1dc.svg
├── b56595d2a30a0af329086562ca12d521.svg
├── b8bc815b5e9d5177af01fd4d3d3c2f10.svg
├── b93e9b71beaf724ff1d0f85841e9ae61.svg
├── bfdc1036a225b1cba16ea97fa96d82de.svg
├── c019432b974b538f20a9d3cb38176a2d.svg
├── c2e078f6be9fb7d3936f8f2c596c2efc.svg
├── c36ef0ba4721f49285945f33a25e7a45.svg
├── c83e439282bef5aadf55a91521506c1a.svg
├── d05b996d2c08252f77613c25205a0f04.svg
├── d4f90ae5560ad92e3d914767e406044c.svg
├── d5b9b96cdc2cdabfd94eaaedae1a759d.svg
├── dad3127bb1a3a78ddd7fce06f6261345.svg
├── e1df9ab5f065f666cdd061d6ef23f8f4.svg
├── e380f5951fb9f765922182550d7fa939.svg
├── e825c2910f10d1a0ef1babeb28698a51.svg
├── ea4bbf715156e61bd05c0ec553601019.svg
├── fd8be73b54f5436a5cd2e73ba9b6bfa9.svg
└── fe4e62694c7a379a0b31c6aa14046dd0.svg
/.github/workflows/c-cpp.yml:
--------------------------------------------------------------------------------
1 | name: Build-CSC2549-Assignment-Four
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | # Linux / macOS
11 | Unix:
12 | name: ${{ matrix.name }} (${{ matrix.config }})
13 | runs-on: ${{ matrix.os }}
14 | strategy:
15 | fail-fast: false
16 | matrix:
17 | os: [ubuntu-latest, macos-latest]
18 | config: [Release]
19 | include:
20 | - os: macos-latest
21 | name: macOS
22 | - os: ubuntu-latest
23 | name: Linux
24 |
25 | env:
26 | OMP_NUM_THREADS: 1
27 |
28 | steps:
29 | - name: Checkout repository
30 | uses: actions/checkout@v2
31 | with:
32 | fetch-depth: 10
33 |
34 | - name: Checkout submodules
35 | run: git submodule update --init --recursive
36 |
37 | - name: Dependencies (Linux)
38 | if: runner.os == 'Linux'
39 | run: |
40 | sudo apt-get update
41 | sudo apt-get install \
42 | build-essential \
43 | cmake \
44 | mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev \
45 | xorg-dev \
46 | libx11-dev \
47 | libxinerama1 libxinerama-dev \
48 | libxcursor-dev libxrandr-dev libxi-dev libxmu-dev \
49 |
50 | - name: Dependencies (macOS)
51 | if: runner.os == 'macOS'
52 | run: |
53 | brew update
54 | brew info git || brew install git
55 | brew info cmake || brew install cmake
56 |
57 | - name: Configure
58 | run: |
59 | mkdir -p build
60 | cd build
61 | cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.config }}
62 | - name: Build
63 | run: |
64 | cd build
65 | make
66 |
67 | # Windows
68 | Windows:
69 | runs-on: windows-latest
70 | env:
71 | CC: cl.exe
72 | CXX: cl.exe
73 | strategy:
74 | fail-fast: false
75 | matrix:
76 | config: [Release]
77 | steps:
78 | - name: Checkout repository
79 | uses: actions/checkout@v2
80 | with:
81 | fetch-depth: 10
82 |
83 | - name: Checkout submodules
84 | run: git submodule update --init --recursive
85 |
86 | - name: Configure and build
87 | shell: cmd
88 | run: |
89 | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=x64
90 | cmake -G Ninja ^
91 | -DCMAKE_BUILD_TYPE=${{ matrix.config }} ^
92 | -B build ^
93 | -S .
94 | cmake --build build
95 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "extern/libigl"]
2 | path = extern/libigl
3 | url = https://github.com/libigl/libigl.git
4 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.2)
2 |
3 | project(a4-cloth-simulation)
4 |
5 | #Important CMAKE stuff
6 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
7 |
8 | #setup libigl properly
9 | # libigl
10 | option(LIBIGL_WITH_OPENGL "Use OpenGL" ON)
11 | option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON)
12 | option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON)
13 |
14 | find_package(LIBIGL REQUIRED QUIET)
15 |
16 | #include directories
17 | include_directories(${PROJECT_SOURCE_DIR}/shared/include)
18 | include_directories(${PROJECT_SOURCE_DIR}/include)
19 | include_directories(${PROJECT_SOURCE_DIR})
20 | include_directories(${LIBIGL_INCLUDE_DIR})
21 |
22 | #include source code
23 | file(GLOB H_FILES ${PROJECT_SOURCE_DIR}/include/*.h)
24 | file(GLOB H_SHARED_FILES ${PROJECT_SOURCE_DIR}/shared/include/*.h)
25 | file(GLOB CPP_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
26 | file(GLOB CPP_SHARED_FILES ${PROJECT_SOURCE_DIR}/shared/src/*.cpp)
27 |
28 | #build executable
29 | add_executable(${PROJECT_NAME} main.cpp assignment_setup.h ${H_FILES} ${H_SHARED_FILES} ${CPP_FILES} ${CPP_SHARED_FILES})
30 | target_link_libraries(${PROJECT_NAME} igl::core igl::opengl igl::opengl_glfw igl::opengl_glfw_imgui)
31 |
32 |
33 |
--------------------------------------------------------------------------------
/cmake/FindLIBIGL.cmake:
--------------------------------------------------------------------------------
1 | # - Try to find the LIBIGL library
2 | # Once done this will define
3 | #
4 | # LIBIGL_FOUND - system has LIBIGL
5 | # LIBIGL_INCLUDE_DIR - **the** LIBIGL include directory
6 | if(LIBIGL_FOUND)
7 | return()
8 | endif()
9 |
10 | find_path(LIBIGL_INCLUDE_DIR igl/readOBJ.h
11 | HINTS
12 | ENV LIBIGL
13 | ENV LIBIGLROOT
14 | ENV LIBIGL_ROOT
15 | ENV LIBIGL_DIR
16 | PATHS
17 | ${CMAKE_SOURCE_DIR}/../..
18 | ${CMAKE_SOURCE_DIR}/..
19 | ${CMAKE_SOURCE_DIR}
20 | ${CMAKE_SOURCE_DIR}/extern/libigl/include
21 | ${CMAKE_SOURCE_DIR}/../libigl
22 | ${CMAKE_SOURCE_DIR}/../../libigl
23 | /usr
24 | /usr/local
25 | /usr/local/igl/libigl
26 | PATH_SUFFIXES include
27 | )
28 |
29 | include(FindPackageHandleStandardArgs)
30 | find_package_handle_standard_args(LIBIGL
31 | "\nlibigl not found --- You can download it using:\n\tgit clone --recursive https://github.com/libigl/libigl.git ${CMAKE_SOURCE_DIR}/../libigl"
32 | LIBIGL_INCLUDE_DIR)
33 | mark_as_advanced(LIBIGL_INCLUDE_DIR)
34 |
35 | list(APPEND CMAKE_MODULE_PATH "${LIBIGL_INCLUDE_DIR}/../cmake")
36 | include(libigl)
--------------------------------------------------------------------------------
/data/triangle.obj:
--------------------------------------------------------------------------------
1 | v 0.1 0 0
2 | v 0 0 0
3 | v 0.05 -0.1 0
4 | f 1 2 3
5 |
6 |
7 |
--------------------------------------------------------------------------------
/images/034d0a6be0424bffe9a6e7ac9236c0f5.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/07617f9d8fe48b4a7b3f523d6730eef0.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/07640d208ac0851eb169c73b736e6bb1.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/images/0a36368a7b551a7c6aa055de5009bea3.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/1757afe2b054e59c6d5c465cf82bd885.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/286f7d4815c0996530bda7973b1ec5ea.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/2ad9d098b937e46f9f58968551adac57.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/2f118ee06d05f3c2d98361d9c30e38ce.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/36b5afebdba34564d884d347484ac0c7.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/58c2313bc1ea66cc4d86d27f83c1941d.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/images/6018bf12266e0674a19d0a622989ad88.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/images/77a3b857d53fb44e33b53e4c8b68351a.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/97c7f491f7ac1623c0a86b1fb656029b.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/9f2b6b0a7f3d99fd3f396a1515926eb3.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/images/a9a3a4a202d80326bda413b5562d5cd1.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/ac3148a5746b81298cb0c456b661f197.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/b23332f99af850a48831f80dbf681ed6.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/b38dda0a0c1ab15d9dae0b9b9e8aa1dc.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/images/b56595d2a30a0af329086562ca12d521.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/b8bc815b5e9d5177af01fd4d3d3c2f10.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/bccab73005d96290c8ef588703533a21.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/c36ef0ba4721f49285945f33a25e7a45.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/images/c83e439282bef5aadf55a91521506c1a.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/cloth.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dilevin/CSC417-a4-cloth-simulation/0261f9928cb2dded3463d8cadaa95c4263ecff9a/images/cloth.gif
--------------------------------------------------------------------------------
/images/d05b996d2c08252f77613c25205a0f04.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/e846e5631eca1fe2f735605515f5be61.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/ea4bbf715156e61bd05c0ec553601019.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/fd8be73b54f5436a5cd2e73ba9b6bfa9.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/fdacaa2009a566aee165e36a976fa9cd.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/fe4e62694c7a379a0b31c6aa14046dd0.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/include/T_cloth.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | //Input:
6 | // qdot - generalized velocities for the FEM system
7 | // V - the nx3 matrix of undeformed vertex positions
8 | // F - the mx3 matrix of triangle-vertex indices
9 | // M - the sparse mass matrix for the FEM system.
10 |
11 | //Output:
12 | // T - the kinetic energy for the entire cloth mesh.
13 | void T_cloth(double &T, Eigen::Ref qdot, Eigen::Ref V, Eigen::Ref F, Eigen::SparseMatrixd &M);
--------------------------------------------------------------------------------
/include/V_membrane_corotational.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | // q - generalized coordinates for the FEM system
5 | // dX - the 3x3 matrix containing dphi/dX
6 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
7 | // element - the vertex indices of this triangle
8 | // area - the area of this triangle
9 | // mu,lambda - material parameters for the cloth material model
10 | //Output:
11 | // energy- the per-triangle potential energy (the linear model described in the README).
12 | void V_membrane_corotational(double &energy, Eigen::Ref q, Eigen::Ref dX,
13 | Eigen::Ref V, Eigen::Ref element, double area,
14 | double mu, double lambda);
--------------------------------------------------------------------------------
/include/V_spring_particle_particle.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //Input:
4 | // q0 - the generalized coordinates of the first node of the spring
5 | // q1 - the generalized coordinates of the second node of the spring
6 | // l0 - the undeformed length of the spring
7 | // stiffness - the stiffness constant for this spring
8 | //Output:
9 | // V - potential energy for the spring
10 | void V_spring_particle_particle(double &V, Eigen::Ref q0, Eigen::Ref q1, double l0, double stiffness);
--------------------------------------------------------------------------------
/include/assemble_forces.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | //Input:
7 | // q - generalized coordinates for the FEM system
8 | // qdot - generalized velocity for the FEM system
9 | // dX - an mx9 matrix which stores the flattened dphi/dX matrices for each tetrahedron.
10 | // Convert this values back to 3x3 matrices using the following code (NOTE YOU MUST USE THE TEMPORARY VARIABLE tmp_row):
11 | // Eigen::Matrix tmp_row
12 | // tmp_row = dX.row(ei); //ei is the triangle index.
13 | // Eigen::Map(tmp_row.data())
14 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
15 | // F - the mx3 triangle connectivity matrix. Each row contains to indices into V that indicate a spring between those vertices.
16 | // a0 - the mx1 vector of undeformed triangle areas
17 | // mu,lambda - material parameters for the cloth material model
18 | //Output:
19 | // f - the vector 3xn vector of forces acting on each node of the mass-spring system
20 | void assemble_forces(Eigen::VectorXd &f, Eigen::Ref q, Eigen::Ref qdot, Eigen::Ref dX,
21 | Eigen::Ref V, Eigen::Ref F, Eigen::Ref a0,
22 | double mu, double lambda);
--------------------------------------------------------------------------------
/include/assemble_stiffness.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // q - generalized coordinates for the FEM system
7 | // qdot - generalized velocity for the FEM system
8 | // dX - an mx9 matrix which stores the flattened dphi/dX matrices for each tetrahedron.
9 | // Convert this values back to 3x3 matrices using the following code (NOTE YOU MUST USE THE TEMPORARY VARIABLE tmp_row):
10 | // Eigen::Matrix tmp_row
11 | // tmp_row = dX.row(ei); //ei is the triangle index.
12 | // Eigen::Map(tmp_row.data())
13 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
14 | // F - the mx3 triangle connectivity matrix. Each row contains to indices into V that indicate a spring between those vertices.
15 | // a0 - the mx1 vector of undeformed triangle areas
16 | // mu,lambda - material parameters for the cloth material model
17 | //Output:
18 | // K- the 3n by 3n sparse stiffness matrix.
19 | void assemble_stiffness(Eigen::SparseMatrixd &K, Eigen::Ref q, Eigen::Ref qdot, Eigen::Ref dX,
20 | Eigen::Ref V, Eigen::Ref T, Eigen::Ref a0,
21 | double mu, double lambda);
--------------------------------------------------------------------------------
/include/collision_detection_cloth_sphere.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | // q - generalized coordinates for the FEM system
5 | // center - the position of the sphere center in the world space
6 | // radius - the radius of the sphere in the world space
7 | //Output:
8 | // cloth_index - the indices of all vertices currently in contact with the sphere
9 | // normals - the outward facing contact normals for each contacting vertex.
10 | void collision_detection_cloth_sphere(std::vector &cloth_index, std::vector &normals, Eigen::Ref q, Eigen::Ref center, double radius);
--------------------------------------------------------------------------------
/include/d2V_membrane_corotational_dq2.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | // q - generalized coordinates for the FEM system
6 | // dX - the 3x3 matrix containing dphi/dX
7 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
8 | // element - the vertex indices of this triangle
9 | // area - the area of this triangle
10 | // mu,lambda - material parameters for the cloth material model
11 | //Output:
12 | // H - the per-triangle Hessian of the potential energy (the linear model described in the README).
13 | void d2V_membrane_corotational_dq2(Eigen::Matrix99d &H, Eigen::Ref q, Eigen::Ref dX,
14 | Eigen::Ref V, Eigen::Ref element, double area,
15 | double mu, double lambda);
16 |
--------------------------------------------------------------------------------
/include/dV_cloth_gravity_dq.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | // M - sparse mass matrix for the entire mesh
5 | // g - the acceleration due to gravity
6 | //Output:
7 | // fg - the gradient of the gravitational potential for the entire mesh
8 | void dV_cloth_gravity_dq(Eigen::VectorXd &fg, Eigen::SparseMatrixd &M, Eigen::Ref g);
9 |
--------------------------------------------------------------------------------
/include/dV_membrane_corotational_dq.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | // q - generalized coordinates for the FEM system
5 | // dX - the 3x3 matrix containing dphi/dX
6 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
7 | // element - the vertex indices of this triangle
8 | // area - the area of this triangle
9 | // mu,lambda - material parameters for the cloth material model
10 | //Output:
11 | // f - the per-triangle gradient of the membrane potential energy (the linear model described in the README).
12 | void dV_membrane_corotational_dq(Eigen::Vector9d &f, Eigen::Ref q, Eigen::Ref dX,
13 | Eigen::Ref V, Eigen::Ref element, double area,
14 | double mu, double lambda);
--------------------------------------------------------------------------------
/include/dV_spring_particle_particle_dq.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // q0 - the generalized coordinates of the first node of the spring
6 | // q1 - the generalized coordinates of the second node of the spring
7 | // l0 - the undeformed length of the spring
8 | // stiffness - the stiffness constant for this spring
9 | //Output:
10 | // f - the 6x1 per spring energy gradient
11 | void dV_spring_particle_particle_dq(Eigen::Ref f, Eigen::Ref q0, Eigen::Ref q1, double l0, double stiffness);
--------------------------------------------------------------------------------
/include/dphi_cloth_triangle_dX.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
6 | // element - the 1x3 vertex indices for this tetrahedron
7 | // X - the 3D position in the underformed space at which to compute the gradient
8 | //Output:
9 | // dphi - the 3x3 gradient of the the basis functions wrt to X. The i'th row stores d phi_i/dX
10 | void dphi_cloth_triangle_dX(Eigen::Matrix3d &dphi, Eigen::Ref V, Eigen::Ref element, Eigen::Ref X);
11 |
--------------------------------------------------------------------------------
/include/dsvd.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //NOTE: Then tensor data structure stores arrays of matrix/vectors.
5 | // For a 3D tensor, such as dS, the entry dS[i][j] = dS/dF_ij, which is a vector
6 | // For a 4D tensors, such as dV, the entry dV[i][j] = dV/dF_ij which is a matrix
7 | //Input:
8 | // F - this function computes the gradient of svd(F), where F is a 3x3 matrix.
9 | //Output (for the definition of the tensorial types, see EigenTypes.h):
10 | // dU - the 3x3x3x3 derivative of U wrt to F. dU[x][y][i][j] contains the derivative of U[x][y] wrt to F[i][j]
11 | // dV - the 3x3x3x3 derivative of U wrt to F. dV[x][y][i][j] contains the derivative of V[x][y] wrt to F[i][j]
12 | // dS - the 3x3x3 derivative of the singular values wrt to F. dS[x][i][j] contains the derivative of the x^{th} singlar value wrt to F[i][j]
13 | void dsvd(Eigen::Tensor3333d &dU, Eigen::Tensor333d &dS, Eigen::Tensor3333d &dV, Eigen::Ref F);
14 |
--------------------------------------------------------------------------------
/include/fixed_point_constraints.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include
6 |
7 | //Input:
8 | // q_size - total number of scalar generalized coordinates (3 times number of vertices in the mesh)
9 | // indices - indices (row ids in V) for fixed vertices
10 | //Output:
11 | // P - 3*mx3*n sparse matrix which projects out fixed vertices
12 | void fixed_point_constraints(Eigen::SparseMatrixd &P, unsigned int q_size, const std::vector indices);
--------------------------------------------------------------------------------
/include/linearly_implicit_euler.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | //Input:
7 | // q - generalized coordinates for the FEM system
8 | // qdot - generalized velocity for the FEM system
9 | // dt - the time step in seconds
10 | // mass - the mass matrix
11 | // force(f, q, qdot) - a function that computes the force acting on the FEM system. This takes q and qdot as parameters, returns the force in f.
12 | // stiffness(K, q, qdot) - a function that computes the stiffness (negative second derivative of the potential energy). This takes q and qdot as parameters, returns the stiffness matrix in K.
13 | // tmp_force - scratch space to collect forces
14 | // tmp_stiffness - scratch space to collect stiffness matrix
15 | //Output:
16 | // q - set q to the updated generalized coordinate using linearly implicit time integration
17 | // qdot - set qdot to the updated generalized velocity using linearly implicit time integration
18 | template
19 | inline void linearly_implicit_euler(Eigen::VectorXd &q, Eigen::VectorXd &qdot, double dt,
20 | const Eigen::SparseMatrixd &mass, FORCE &force, STIFFNESS &stiffness,
21 | Eigen::VectorXd &tmp_force, Eigen::SparseMatrixd &tmp_stiffness) {
22 |
23 |
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/include/mass_matrix_mesh.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | //Input:
6 | // q - generalized coordinates for the FEM system
7 | // V - the nx3 matrix of undeformed vertex positions
8 | // F - the mx3 matrix of triangle-vertex indices
9 | // density - the density of the cloth material
10 | // areas - the mx1 vector of undeformed triangle areas
11 | //Output:
12 | // M - sparse mass matrix for the entire mesh
13 | void mass_matrix_mesh(Eigen::SparseMatrixd &M, Eigen::Ref q,
14 | Eigen::Ref V, Eigen::Ref F,
15 | double density, Eigen::Ref areas);
--------------------------------------------------------------------------------
/include/pick_nearest_vertices.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 |
6 | //NOTE: You can use the libigl igl::unproject function to implement this method
7 |
8 | //Input:
9 | // win - window coordinate of mouse click (x_window, y_window, 0)
10 | // view - view transformation matrix
11 | // proj - projection matrix
12 | // viewport - viewport coordinates .
13 | // V - 3xn dense matrix of mesh vertices, each row of the matrix is a single vertex.
14 | // radius - selection radius for vertex picking
15 | //Output:
16 | // verts - vertex ids (rows in V) of selected vertices
17 | bool pick_nearest_vertices(std::vector &verts, Eigen::Ref win,
18 | Eigen::Ref view, Eigen::Ref proj, Eigen::Vector4f viewport,
19 | Eigen::Ref V, Eigen::Ref F, double radius);
--------------------------------------------------------------------------------
/include/velocity_filter_cloth_sphere.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // qdot - the 3nx1 generalized velocities of the cloth mesh
6 | // index - a list of collision vertex indices from the collision detector
7 | // normals - a list of collision normals from the collision detector
8 | //Output:
9 | // qdot- the filtered 3nx1 generalized velocities
10 | void velocity_filter_cloth_sphere(Eigen::VectorXd &qdot, const std::vector &index,
11 | const std::vector &normals);
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include
5 | #include
6 |
7 | //Simulation State
8 | Eigen::VectorXd q;
9 | Eigen::VectorXd qdot;
10 |
11 | //simulation time and time step
12 | double t = 0; //simulation time
13 | double dt = 0.001; //time step
14 |
15 | //simulation loop
16 | bool simulating = true;
17 |
18 | bool simulation_callback() {
19 |
20 | while(simulating) {
21 | simulate(q, qdot, dt, t);
22 | t += dt;
23 | }
24 |
25 | return false;
26 | }
27 |
28 | bool draw_callback(igl::opengl::glfw::Viewer &viewer) {
29 |
30 | draw(q, qdot, t);
31 |
32 | return false;
33 | }
34 |
35 | void f(int &a, int b, int c) {
36 | a = b + c;
37 |
38 |
39 | }
40 |
41 | void g(Eigen::Vector3d &a, Eigen::Vector3d b, Eigen::Vector3d c) {
42 | a = b + c;
43 | }
44 |
45 | template
46 | void h(Ret &&a, B b, C c, void (*func)(Ret, B, C)) {
47 | func(a,b,c);
48 | }
49 |
50 | int main(int argc, char **argv) {
51 |
52 | std::cout<<"Start A4\n";
53 |
54 | //assignment specific setup
55 | assignment_setup(argc, argv, q, qdot);
56 |
57 | //run simulation in seperate thread to avoid slowing down the UI
58 | std::thread simulation_thread(simulation_callback);
59 | simulation_thread.detach();
60 |
61 | //setup libigl viewer and activate
62 | Visualize::setup(q, qdot, true);
63 | Visualize::viewer().callback_post_draw = &draw_callback;
64 | Visualize::viewer().launch();
65 |
66 | return 1;
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/shared/include/EigenTypes.h:
--------------------------------------------------------------------------------
1 | #ifndef EIGENTYPES_H
2 | #define EIGENTYPES_H
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | namespace Eigen {
10 |
11 | //dense types
12 | using Vector4d = Eigen::Matrix;
13 | using Vector6d = Eigen::Matrix;
14 | using Vector9d = Eigen::Matrix;
15 | using Vector12d = Eigen::Matrix;
16 |
17 | using Matrix32d = Eigen::Matrix;
18 | using Matrix34d = Eigen::Matrix;
19 | using Matrix36d = Eigen::Matrix;
20 | using Matrix39d = Eigen::Matrix;
21 | using Matrix43d = Eigen::Matrix;
22 | using Matrix66d = Eigen::Matrix;
23 | using Matrix99d = Eigen::Matrix;
24 | using Matrix93d = Eigen::Matrix;
25 | using Matrix1212d = Eigen::Matrix;
26 | using Matrix44f = Eigen::Matrix;
27 |
28 | //sparse types
29 | using SparseMatrixd = Eigen::SparseMatrix;
30 |
31 | //tensor types (which are just arrays of matrices)
32 | using Tensor333d = std::array, 3>;
33 | using Tensor3333d = std::array, 3>;
34 |
35 | }
36 |
37 | inline double stablePow(double a, double b) {
38 | return static_cast (std::pow(std::cbrt(static_cast(a)),static_cast(b)));
39 | }
40 |
41 | inline void inverse33(Eigen::Ref result, Eigen::Ref A) {
42 | double determinant = +A(0,0)*(A(1,1)*A(2,2)-A(2,1)*A(1,2))
43 | -A(0,1)*(A(1,0)*A(2,2)-A(1,2)*A(2,0))
44 | +A(0,2)*(A(1,0)*A(2,1)-A(1,1)*A(2,0));
45 | double invdet = 1/determinant;
46 | result(0,0) = (A(1,1)*A(2,2)-A(2,1)*A(1,2))*invdet;
47 | result(1,0) = -(A(0,1)*A(2,2)-A(0,2)*A(2,1))*invdet;
48 | result(2,0) = (A(0,1)*A(1,2)-A(0,2)*A(1,1))*invdet;
49 | result(0,1) = -(A(1,0)*A(2,2)-A(1,2)*A(2,0))*invdet;
50 | result(1,1) = (A(0,0)*A(2,2)-A(0,2)*A(2,0))*invdet;
51 | result(2,1) = -(A(0,0)*A(1,2)-A(1,0)*A(0,2))*invdet;
52 | result(0,2) = (A(1,0)*A(2,1)-A(2,0)*A(1,1))*invdet;
53 | result(1,2) = -(A(0,0)*A(2,1)-A(2,0)*A(0,1))*invdet;
54 | result(2,2) = (A(0,0)*A(1,1)-A(1,0)*A(0,1))*invdet;
55 | result.transposeInPlace();
56 | }
57 |
58 |
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/shared/include/find_max_vertices.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void find_max_vertices(std::vector &indices, Eigen::Ref V, double tol = 1e-3);
--------------------------------------------------------------------------------
/shared/include/find_min_vertices.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void find_min_vertices(std::vector &indices, Eigen::Ref V, double tol = 1e-3);
--------------------------------------------------------------------------------
/shared/include/init_state.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | void init_state(Eigen::VectorXd &q, Eigen::VectorXd &qdot, Eigen::Ref V);
--------------------------------------------------------------------------------
/shared/include/read_tetgen.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | void read_tetgen(Eigen::MatrixXd &V, Eigen::MatrixXi &F, const std::string nodeFile, const std::string eleFile);
--------------------------------------------------------------------------------
/shared/include/visualization.h:
--------------------------------------------------------------------------------
1 | #ifndef VISUALIZATION_H
2 | #define VISUALIZATION_H
3 |
4 | #define IMGUI_DEFINE_MATH_OPERATORS
5 |
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | //stl
16 | #include
17 | #include
18 | #include
19 |
20 | //Eigen
21 | #include
22 |
23 | namespace Visualize {
24 |
25 | //custom phase space plot
26 | bool plot_phase_space(const char *label, ImVec2 q_bounds, ImVec2 q_dot_bounds, const Eigen::VectorXd &q, const Eigen::VectorXd &q_dot);
27 |
28 | void add_energy(float t, float T, float V);
29 | bool plot_energy(const char *label, unsigned int type, ImVec2 T_bounds, ImVec2 V_bounds, ImU32 plot_col);
30 |
31 | void setup(const Eigen::VectorXd &q, const Eigen::VectorXd &qdot, bool ps_plot = false);
32 |
33 | void add_object_to_scene(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::MatrixXd &V_skin,
34 | const Eigen::MatrixXi &F_skin, const Eigen::SparseMatrixd &N, Eigen::RowVector3d color);
35 |
36 | void set_visible(unsigned int obj_id, bool visible);
37 |
38 | //animate geometry using physics simulation
39 | void rigid_transform_1d(unsigned int id, double x);
40 |
41 | void scale_x(unsigned int id, double x);
42 |
43 | void update_vertex_positions(unsigned int id, Eigen::Ref pos);
44 |
45 | void set_picking_tolerance(double);
46 |
47 | //UI methods
48 | bool mouse_down(igl::opengl::glfw::Viewer &viewer, int x, int y);
49 |
50 | bool mouse_up(igl::opengl::glfw::Viewer &viewer, int x, int y);
51 |
52 | bool mouse_move(igl::opengl::glfw::Viewer &viewer, int x, int y);
53 |
54 | igl::opengl::glfw::Viewer & viewer();
55 |
56 | igl::opengl::glfw::imgui::ImGuiMenu & viewer_menu();
57 |
58 | const Eigen::Vector3d & mouse_world();
59 |
60 | const Eigen::Vector3d & mouse_drag_world();
61 |
62 |
63 | const std::vector & picked_vertices();
64 |
65 | bool is_mouse_dragging();
66 |
67 | void toggle_skinning(bool skinning);
68 | }
69 |
70 |
71 | #endif
--------------------------------------------------------------------------------
/shared/src/find_max_vertices.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void find_max_vertices(std::vector &indices, Eigen::Ref V, double tol) {
5 |
6 | double max_vertex = V(0,1);
7 |
8 | for(unsigned int vi=0; vi max_vertex ? V(vi,1) : max_vertex);
10 | }
11 |
12 | for(unsigned int vi=0; vi
2 | #include
3 |
4 | void find_min_vertices(std::vector &indices, Eigen::Ref V, double tol) {
5 |
6 | double min_vertex = V(0,1);
7 |
8 | for(unsigned int vi=0; vi
2 |
3 | //void init_state(Eigen::Ref q, Eigen::Ref qdot, Eigen::Ref V)
4 | void init_state(Eigen::VectorXd &q, Eigen::VectorXd &qdot, Eigen::Ref V) {
5 |
6 | q.resize(V.rows()*V.cols());
7 | qdot.resize(V.rows()*V.cols());
8 |
9 | Eigen::MatrixXd Vt = V.transpose();
10 | q = Eigen::Map(Vt.data(), Vt.rows()*Vt.cols());
11 | qdot.setZero();
12 | }
--------------------------------------------------------------------------------
/shared/src/read_tetgen.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //Written by Desai Chen for SIMIT
4 | int openIfstream(std::ifstream &in, std::string filename)
5 | {
6 | in.open(filename);
7 | if(!in.good()){
8 | std::cout<<"Cannot read "<>intVal;
32 |
33 | V.resize(intVal,3); //resize vertex array
34 | std::string line;
35 | unsigned int cnt = 0;
36 | //discard rest of the first line.
37 | getline(nodeIn,line);
38 | while(1) {
39 | getline(nodeIn,line);
40 | if(nodeIn.eof()) {
41 | break;
42 | }
43 | //skip empty lines
44 | if(line.size()<3) {
45 | continue;
46 | }
47 | //skip comments
48 | if(line.at(0)=='#') {
49 | continue;
50 | }
51 | std::stringstream ss(line);
52 |
53 | ss>>intVal;
54 | for(int ii = 0;ii<3;ii++){
55 | ss>>V(cnt,ii);
56 | }
57 | cnt ++ ;
58 | if(cnt>=V.rows()){
59 | break;
60 | }
61 | }
62 |
63 | //load elements
64 | eleIn>>intVal;
65 | F.resize(intVal, 4); //resize face list
66 |
67 | int nV=0;
68 | eleIn>>nV;
69 | cnt = 0;
70 | getline(eleIn,line);
71 | while(1) {
72 | getline(eleIn,line);
73 | if(eleIn.eof()) {
74 | break;
75 | }
76 | if(line.size()<3) {
77 | continue;
78 | }
79 | if(line.at(0)=='#') {
80 | continue;
81 | }
82 | std::stringstream ss(line);
83 | ss>>intVal;
84 |
85 | //e[cnt].resize(nV);
86 | for(int ii = 0;ii>F(cnt,ii);
88 | }
89 |
90 | cnt ++ ;
91 | if(cnt>=F.rows()){
92 | break;
93 | }
94 | }
95 | return 0;
96 | }
97 |
98 | //Lions share of code borrowed from Desai Chen for SIMIT
99 | void read_tetgen(Eigen::MatrixXd &V, Eigen::MatrixXi &F, const std::string nodeFile, const std::string eleFile) {
100 |
101 | std::cout<<"Reading tetrahedral mesh from "<
2 |
3 | void T_cloth(double &T, Eigen::Ref qdot, Eigen::Ref V, Eigen::Ref F, Eigen::SparseMatrixd &M) {
4 |
5 |
6 | }
--------------------------------------------------------------------------------
/src/V_membrane_corotational.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //Allowed to use libigl SVD or Eigen SVD for this part
4 | void V_membrane_corotational(double &energy, Eigen::Ref q, Eigen::Ref dX,
5 | Eigen::Ref V, Eigen::Ref element, double area,
6 | double mu, double lambda) {
7 |
8 |
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/V_spring_particle_particle.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void V_spring_particle_particle(double &V, Eigen ::Ref q0, Eigen::Ref q1, double l0, double stiffness) {
4 |
5 |
6 |
7 | }
--------------------------------------------------------------------------------
/src/assemble_forces.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void assemble_forces(Eigen::VectorXd &f, Eigen::Ref q, Eigen::Ref qdot, Eigen::Ref dX,
5 | Eigen::Ref V, Eigen::Ref F, Eigen::Ref a0,
6 | double mu, double lambda) {
7 |
8 |
9 |
10 | };
11 |
--------------------------------------------------------------------------------
/src/assemble_stiffness.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | void assemble_stiffness(Eigen::SparseMatrixd &K, Eigen::Ref q, Eigen::Ref qdot, Eigen::Ref dX,
4 | Eigen::Ref V, Eigen::Ref F, Eigen::Ref a0,
5 | double mu, double lambda) {
6 |
7 |
8 |
9 | };
10 |
--------------------------------------------------------------------------------
/src/collision_detection_cloth_sphere.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | void collision_detection_cloth_sphere(std::vector &cloth_index, std::vector &normals, Eigen::Ref q, Eigen::Ref center, double radius) {
4 |
5 | cloth_index.clear();
6 | normals.clear();
7 |
8 |
9 | }
--------------------------------------------------------------------------------
/src/d2V_membrane_corotational_dq2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void d2V_membrane_corotational_dq2(Eigen::Matrix99d &H, Eigen::Ref q, Eigen::Ref dX,
5 | Eigen::Ref V, Eigen::Ref element, double area,
6 | double mu, double lambda) {
7 |
8 |
9 | //SVD = USW^T
10 | Eigen::Matrix3d U;
11 | Eigen::Vector3d S;
12 | Eigen::Matrix3d W;
13 | Eigen::Matrix3d F; //deformation gradient
14 |
15 | double tol = 1e-5;
16 |
17 | //Compute SVD of F here
18 |
19 | //deal with singularity in the svd gradient
20 | if(std::fabs(S[0] - S[1]) < tol || std::fabs(S[1] - S[2]) < tol || std::fabs(S[0] - S[2]) < tol) {
21 | F += Eigen::Matrix3d::Random()*tol;
22 | Eigen::JacobiSVD svd2(F, Eigen::ComputeFullU | Eigen::ComputeFullV);
23 | U = svd2.matrixU();
24 | W = svd2.matrixV();
25 | S = svd2.singularValues();
26 | }
27 |
28 | //Fix for inverted elements (thanks to Danny Kaufman)
29 | double det = S[0]*S[1];
30 |
31 | if(det <= -1e-10)
32 | {
33 | if(S[0] < 0) S[0] *= -1;
34 | if(S[1] < 0) S[1] *= -1;
35 | if(S[2] < 0) S[2] *= -1;
36 | }
37 |
38 | if(U.determinant() <= 0)
39 | {
40 | U(0, 2) *= -1;
41 | U(1, 2) *= -1;
42 | U(2, 2) *= -1;
43 | }
44 |
45 | if(W.determinant() <= 0)
46 | {
47 | W(0, 2) *= -1;
48 | W(1, 2) *= -1;
49 | W(2, 2) *= -1;
50 | }
51 |
52 | //TODO: compute H, the hessian of the corotational energy
53 |
54 |
55 | //fix errant eigenvalues
56 | Eigen::SelfAdjointEigenSolver es(H);
57 |
58 | Eigen::MatrixXd DiagEval = es.eigenvalues().real().asDiagonal();
59 | Eigen::MatrixXd Evec = es.eigenvectors().real();
60 |
61 | for (int i = 0; i < 9; ++i) {
62 | if (es.eigenvalues()[i]<1e-6) {
63 | DiagEval(i,i) = 1e-3;
64 | }
65 | }
66 |
67 | H = Evec * DiagEval * Evec.transpose();
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/dV_cloth_gravity_dq.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void dV_cloth_gravity_dq(Eigen::VectorXd &fg, Eigen::SparseMatrixd &M, Eigen::Ref g) {
4 |
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/src/dV_membrane_corotational_dq.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void dV_membrane_corotational_dq(Eigen::Vector9d &dV, Eigen::Ref q, Eigen::Ref dX,
5 | Eigen::Ref V, Eigen::Ref element, double area,
6 | double mu, double lambda) {
7 |
8 | //Deformation Gradient
9 | Eigen::Matrix3d dx; //deformed tangent matrix
10 | Eigen::Matrix3d U;
11 | Eigen::Vector3d S;
12 | Eigen::Matrix3d W;
13 |
14 | //TODO: SVD Here
15 |
16 | //Fix for inverted elements (thanks to Danny Kaufman)
17 | double det = S[0]*S[1];
18 |
19 | if(det <= -1e-10)
20 | {
21 | if(S[0] < 0) S[0] *= -1;
22 | if(S[1] < 0) S[1] *= -1;
23 | if(S[2] < 0) S[2] *= -1;
24 | }
25 |
26 | if(U.determinant() <= 0)
27 | {
28 | U(0, 2) *= -1;
29 | U(1, 2) *= -1;
30 | U(2, 2) *= -1;
31 | }
32 |
33 | if(W.determinant() <= 0)
34 | {
35 | W(0, 2) *= -1;
36 | W(1, 2) *= -1;
37 | W(2, 2) *= -1;
38 | }
39 |
40 | //TODO: energy model gradient
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/dV_spring_particle_particle_dq.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void dV_spring_particle_particle_dq(Eigen::Ref f, Eigen::Ref q0, Eigen::Ref q1, double l0, double stiffness) {
4 |
5 |
6 |
7 | }
--------------------------------------------------------------------------------
/src/dphi_cloth_triangle_dX.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //compute 3x3 deformation gradient
4 | void dphi_cloth_triangle_dX(Eigen::Matrix3d &dphi, Eigen::Ref V, Eigen::Ref element, Eigen::Ref X) {
5 |
6 |
7 |
8 | }
--------------------------------------------------------------------------------
/src/dsvd.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void dsvd(Eigen::Tensor3333d &dU, Eigen::Tensor333d &dS, Eigen::Tensor3333d &dV, Eigen::Ref Fin) {
4 |
5 | Eigen::Matrix3d UVT, tmp, U,V;
6 | Eigen::Matrix3d lambda;
7 | Eigen::Matrix3d F;
8 | Eigen::Vector3d S;
9 | //get the SVD
10 | F = Fin;
11 | Eigen::JacobiSVD svd(F, Eigen::ComputeFullU | Eigen::ComputeFullV);
12 | U = svd.matrixU();
13 | V = svd.matrixV();
14 | S = svd.singularValues();
15 |
16 | //crappy hack for now
17 | double tol = 1e-5;
18 |
19 | if(std::fabs(S[0] - S[1]) < tol || std::fabs(S[1] - S[2]) < tol || std::fabs(S[0] - S[2]) < tol) {
20 | F += Eigen::Matrix3d::Random()*tol;
21 | Eigen::JacobiSVD svd2(F, Eigen::ComputeFullU | Eigen::ComputeFullV);
22 | U = svd2.matrixU();
23 | V = svd2.matrixV();
24 | S = svd2.singularValues();
25 | }
26 |
27 | double w01, w02, w12;
28 | double d01, d02, d12;
29 |
30 | d01 = S(1)*S(1)-S(0)*S(0);
31 | d02 = S(2)*S(2)-S(0)*S(0);
32 | d12 = S(2)*S(2)-S(1)*S(1);
33 |
34 | //corresponds to conservative solution --- if singularity is detected no angular velocity
35 | d01 = 1.0/(std::abs(d01) < tol ? std::numeric_limits::infinity() : d01);
36 | d02 = 1.0/(std::abs(d02) < tol ? std::numeric_limits::infinity() : d02);
37 | d12 = 1.0/(std::abs(d12) < tol ? std::numeric_limits::infinity() : d12);
38 |
39 | for(unsigned int r=0; r<3; ++r) {
40 | for(unsigned int s =0; s <3; ++s) {
41 |
42 | UVT = U.row(r).transpose()*V.row(s);
43 |
44 | //Compute dS
45 | dS[r][s] = UVT.diagonal();
46 |
47 | UVT -= dS[r][s].asDiagonal();
48 |
49 | tmp = S.asDiagonal()*UVT + UVT.transpose()*S.asDiagonal();
50 | w01 = tmp(0,1)*d01;
51 | w02 = tmp(0,2)*d02;
52 | w12 = tmp(1,2)*d12;
53 | tmp << 0, w01, w02,
54 | -w01, 0, w12,
55 | -w02, -w12, 0;
56 |
57 | dV[r][s] = V*tmp;
58 |
59 | tmp = UVT*S.asDiagonal() + S.asDiagonal()*UVT.transpose();
60 | w01 = tmp(0,1)*d01;
61 | w02 = tmp(0,2)*d02;
62 | w12 = tmp(1,2)*d12;
63 | tmp << 0, w01, w02,
64 | -w01, 0, w12,
65 | -w02, -w12, 0;
66 |
67 | dU[r][s] = U*tmp;
68 |
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/fixed_point_constraints.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | void fixed_point_constraints(Eigen::SparseMatrixd &P, unsigned int q_size, const std::vector indices) {
4 |
5 |
6 |
7 | }
--------------------------------------------------------------------------------
/src/mass_matrix_mesh.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void mass_matrix_mesh(Eigen::SparseMatrixd &M, Eigen::Ref q,
4 | Eigen::Ref V, Eigen::Ref F,
5 | double density, Eigen::Ref areas) {
6 |
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/src/pick_nearest_vertices.cpp:
--------------------------------------------------------------------------------
1 | #include