├── .gitignore ├── arcsim ├── .gitignore ├── AdaptiveCloth.sln ├── AdaptiveCloth │ ├── AdaptiveCloth.vcxproj │ ├── AdaptiveCloth.vcxproj.filters │ ├── AdaptiveCloth.vcxproj.user │ ├── Application.cpp │ ├── Application.h │ ├── Main.cpp │ ├── auglag.cpp │ ├── auglag.hpp │ ├── bah.cpp │ ├── bah.hpp │ ├── blockvectors.hpp │ ├── bvh.cpp │ ├── bvh.hpp │ ├── cloth.cpp │ ├── cloth.hpp │ ├── collision.cpp │ ├── collision.hpp │ ├── collisionutil.cpp │ ├── collisionutil.hpp │ ├── conf.cpp │ ├── conf.hpp │ ├── constraint.cpp │ ├── constraint.hpp │ ├── dde.cpp │ ├── dde.hpp │ ├── display.cpp │ ├── display.hpp │ ├── displayphysics.cpp │ ├── displayphysics.hpp │ ├── displayreplay.cpp │ ├── displayreplay.hpp │ ├── displaytesting.cpp │ ├── displaytesting.hpp │ ├── dynamicremesh.cpp │ ├── dynamicremesh.hpp │ ├── geometry.cpp │ ├── geometry.hpp │ ├── handle.cpp │ ├── handle.hpp │ ├── io.cpp │ ├── io.hpp │ ├── lbfgs.cpp │ ├── lsnewton.cpp │ ├── magic.cpp │ ├── magic.hpp │ ├── mesh.cpp │ ├── mesh.hpp │ ├── misc.cpp │ ├── misc.hpp │ ├── morph.cpp │ ├── morph.hpp │ ├── mot_parser.cpp │ ├── mot_parser.hpp │ ├── nearobs.cpp │ ├── nearobs.hpp │ ├── nlcg.cpp │ ├── obstacle.cpp │ ├── obstacle.hpp │ ├── opengl.hpp │ ├── optimization.hpp │ ├── physics.cpp │ ├── physics.hpp │ ├── plasticity.cpp │ ├── plasticity.hpp │ ├── popfilter.cpp │ ├── popfilter.hpp │ ├── proximity.cpp │ ├── proximity.hpp │ ├── remesh.cpp │ ├── remesh.hpp │ ├── runphysics.cpp │ ├── runphysics.hpp │ ├── separate.cpp │ ├── separate.hpp │ ├── separateobs.cpp │ ├── separateobs.hpp │ ├── simulation.cpp │ ├── simulation.hpp │ ├── sparse.hpp │ ├── spline.cpp │ ├── spline.hpp │ ├── strainlimiting.cpp │ ├── strainlimiting.hpp │ ├── taucs.cpp │ ├── taucs.hpp │ ├── tensormax.cpp │ ├── tensormax.hpp │ ├── timer.cpp │ ├── timer.hpp │ ├── transformation.cpp │ ├── transformation.hpp │ ├── trustregion.cpp │ ├── util.cpp │ ├── util.hpp │ ├── vectors.cpp │ ├── vectors.hpp │ └── winport.hpp ├── Configurations │ ├── crumple-pnas.json │ ├── crumple.json │ ├── crush.json │ ├── crush2.json │ ├── cylinder.json │ ├── dart.json │ ├── dress-blue.json │ ├── dress-yellow.json │ ├── flag.json │ ├── fold.json │ ├── karate.json │ ├── pcb.json │ ├── pcb_flag.json │ ├── sleeve.json │ ├── sphere-annotated.json │ ├── sphere.json │ ├── square-pop.json │ ├── square.json │ └── tshirt.json ├── Materials │ ├── 11oz-black-denim.json │ ├── PcbBending.json │ ├── aluminium.json │ ├── camel-ponte-roma.json │ ├── gray-interlock.json │ ├── ivory-rib-knit.json │ ├── navy-sparkle-sweat.json │ ├── paper.json │ ├── pink-ribbon-brown.json │ ├── royal-target.json │ ├── tango-red-jet-set.json │ ├── white-dots-on-blk.json │ └── white-swim-solid.json └── Meshes │ ├── dance-paused.mot │ ├── dance.mot │ ├── dress.ma │ ├── dress.poly │ ├── dress2.ma │ ├── dress3.ma │ ├── dressp.svg │ ├── female-objs │ └── shrink.hs │ ├── karate-smooth.mot │ ├── karate.ma │ ├── karate.mot │ ├── locking-clinder.mtl │ ├── locking-square.mtl │ ├── locking-square.obj.mtl │ ├── nodefiles │ ├── flag.node │ ├── mktablecloth.py │ ├── square.1.ele │ ├── square.1.node │ └── square.node │ ├── pants.mtl │ ├── scripts │ ├── Obj.hs │ ├── count.hs │ ├── cylinder.hs │ ├── ffwd.sh │ ├── flip.hs │ ├── fold.hs │ ├── pause.hs │ ├── plastic.hs │ ├── rotate.hs │ ├── shrink.hs │ ├── svg2poly.hs │ └── translate.hs │ ├── shrinkobj.py │ └── sphere.mot ├── bending_validation ├── AssembleMatrix.m ├── BendingCurve.m ├── BuildTopo.m ├── CreateCloth.m ├── DihedralBendingHessianForce.m ├── GenerateModulusForSampling.m ├── GetHW.m ├── LICENSE ├── LoadMasterCurve.m ├── Main.m ├── PlotMasterCurve.m ├── README.md ├── ReadObj.m ├── SetFixed.m ├── SpringHessianForce.m ├── UpdateXV.m ├── master_curve.png ├── master_curve_data.mat └── ribbon.obj ├── dataset └── dataset.csv ├── evaluation ├── backbones │ ├── alexnet.py │ ├── base.py │ ├── effnet.py │ ├── effnet_util.py │ ├── resnet.py │ └── vgg16.py ├── depth_data │ ├── mesh0 │ │ ├── 0.png │ │ ├── 1.png │ │ ├── 2.png │ │ ├── 3.png │ │ └── density.txt │ ├── mesh1 │ │ ├── 0.png │ │ ├── 1.png │ │ ├── 2.png │ │ ├── 3.png │ │ └── density.txt │ ├── mesh2 │ │ ├── 0.png │ │ ├── 1.png │ │ ├── 2.png │ │ ├── 3.png │ │ └── density.txt │ └── mesh3 │ │ ├── 0.png │ │ ├── 1.png │ │ ├── 2.png │ │ ├── 3.png │ │ └── density.txt ├── evaluation.py ├── network.pth ├── proputil.py └── resnet.py ├── readme.md └── subspace ├── dataloader.py ├── init_dataset.py ├── sampling.py ├── test.txt ├── train.txt ├── vae.py └── vae_subspace.pkl /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | .vs/ 3 | Third-Party 4 | Output/ -------------------------------------------------------------------------------- /arcsim/.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.572 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AdaptiveCloth", "AdaptiveCloth\AdaptiveCloth.vcxproj", "{66DC224B-8EB7-40F0-B026-E2A0B2CF554B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {66DC224B-8EB7-40F0-B026-E2A0B2CF554B}.Debug|x64.ActiveCfg = Debug|x64 15 | {66DC224B-8EB7-40F0-B026-E2A0B2CF554B}.Debug|x64.Build.0 = Debug|x64 16 | {66DC224B-8EB7-40F0-B026-E2A0B2CF554B}.Release|x64.ActiveCfg = Release|x64 17 | {66DC224B-8EB7-40F0-B026-E2A0B2CF554B}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {D378786E-332C-4407-ABD6-DB4C024F6F14} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/AdaptiveCloth.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(SolutionDir) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(SolutionDir) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/Application.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | *************************** Application **************************** 3 | *************************************************************************/ 4 | 5 | #include 6 | #include 7 | #include "Application.h" 8 | 9 | #include "display.hpp" 10 | #include "runphysics.hpp" 11 | #include "displayphysics.hpp" 12 | 13 | using namespace ArcSim; 14 | using namespace std::chrono_literals; 15 | 16 | /************************************************************************* 17 | *************************** Application **************************** 18 | *************************************************************************/ 19 | Application::Application() : m_IsRunning(false) 20 | { 21 | 22 | } 23 | 24 | static bool s_IsRunning = false; 25 | 26 | void idle() 27 | { 28 | 29 | if (!s_IsRunning) 30 | return; 31 | 32 | sim_step(); 33 | redisplay(); 34 | } 35 | 36 | extern void zoom(bool in); 37 | 38 | static void keyboard(unsigned char key, int x, int y) 39 | { 40 | unsigned char esc = 27, space = ' '; 41 | if (key == esc) 42 | { 43 | exit(EXIT_SUCCESS); 44 | } 45 | else if (key == space) 46 | { 47 | ::s_IsRunning = !::s_IsRunning; 48 | } 49 | else if (key == 's') 50 | { 51 | ::s_IsRunning = !::s_IsRunning; 52 | idle(); 53 | ::s_IsRunning = !::s_IsRunning; 54 | } 55 | else if (key == 'z') 56 | { 57 | zoom(true); 58 | } 59 | else if (key == 'x') 60 | { 61 | zoom(false); 62 | } 63 | } 64 | 65 | 66 | void Application::RunSimulate(std::string jsonPath, std::string savingPath) 67 | { 68 | init_physics(jsonPath, savingPath, false); 69 | 70 | GlutCallbacks cb; 71 | cb.idle = idle; 72 | cb.keyboard = keyboard; 73 | 74 | run_glut(cb); 75 | } 76 | 77 | 78 | Application::~Application() 79 | { 80 | 81 | } -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/Application.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | *************************** Application **************************** 3 | *************************************************************************/ 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace ArcSim 9 | { 10 | /********************************************************************* 11 | ************************* Application ************************** 12 | *********************************************************************/ 13 | 14 | class Application 15 | { 16 | 17 | public: 18 | 19 | Application(); 20 | ~Application(); 21 | 22 | public: 23 | 24 | void RunSimulate(std::string jsonPath, std::string savingPath = ""); 25 | 26 | private: 27 | 28 | 29 | 30 | private: 31 | 32 | bool m_IsRunning; 33 | }; 34 | } -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/Main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #include "io.hpp" 28 | #include "misc.hpp" 29 | #include "display.hpp" 30 | #include "runphysics.hpp" 31 | #include "displayreplay.hpp" 32 | #include "displayphysics.hpp" 33 | #include "displaytesting.hpp" 34 | #include 35 | 36 | #include "Application.h" 37 | 38 | using namespace std; 39 | 40 | extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; } 41 | 42 | // implement this anywhere in any .cpp file 43 | extern void debug(const vector &args); 44 | 45 | int main(int argc, char **argv) 46 | { 47 | struct Action 48 | { 49 | string name; 50 | void(*run) (const vector &args); 51 | } actions[] = { 52 | {"simulate", display_physics}, 53 | {"simulateoffline", run_physics}, 54 | {"resume", display_resume}, 55 | {"resumeoffline", resume_physics}, 56 | {"replay", display_replay}, 57 | {"merge", merge_meshes}, 58 | {"split", split_meshes}, 59 | {"test", display_testing}, 60 | {"tri2obj", tri2obj}, 61 | {"debug", debug} 62 | }; 63 | int nactions = sizeof(actions) / sizeof(Action); 64 | string name = (argc <= 1) ? "" : argv[1]; 65 | vector args; 66 | for (int a = 2; a < argc; a++) 67 | args.push_back(argv[a]); 68 | for (int i = 0; i < nactions; i++) 69 | { 70 | if (name == actions[i].name) 71 | { 72 | actions[i].run(args); 73 | exit(EXIT_SUCCESS); 74 | } 75 | } 76 | 77 | cout << "Usage: " << endl; 78 | cout << " " << argv[0] << " []" << endl; 79 | cout << "where is one of" << endl; 80 | for (int i = 0; i < nactions; i++) 81 | cout << " " << actions[i].name << endl; 82 | cout << endl; 83 | cout << "Run '" << argv[0] << " ' without extra arguments "; 84 | cout << "to get more information about a particular command." << endl; 85 | 86 | ///////////////////////////////////////////////////////// 87 | 88 | ArcSim::Application App; 89 | 90 | App.RunSimulate("Configurations\\pcb.json"); 91 | // App.RunSimulate("Configurations\\flag.json"); 92 | // App.RunSimulate("Configurations\\dress-blue.json"); 93 | // App.RunSimulate("Configurations\\dress-yellow.json"); 94 | 95 | exit(EXIT_SUCCESS); 96 | } -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/auglag.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef AUGLAG_HPP 28 | #define AUGLAG_HPP 29 | 30 | #include "sparse.hpp" 31 | #include "vectors.hpp" 32 | 33 | struct NLOpt 34 | { // nonlinear optimization problem 35 | // minimize objective s.t. constraints = or <= 0 36 | int nvar, ncon; 37 | virtual void initialize(double *x) const = 0; 38 | virtual void precompute(const double *x) const {} 39 | virtual double objective(const double *x) const = 0; 40 | virtual void obj_grad(const double *x, double *grad) const = 0; // set 41 | virtual double constraint(const double *x, int j, int &sign) const = 0; 42 | virtual void con_grad(const double *x, int j, double factor, 43 | double *grad) const = 0; // add factor*gradient 44 | virtual void finalize(const double *x) const = 0; 45 | }; 46 | 47 | void augmented_lagrangian_method(const NLOpt &problem, bool verbose = false); 48 | 49 | // convenience functions for when optimization variables are Vec3-valued 50 | 51 | inline Vec3 get_subvec(const double *x, int i) 52 | { 53 | return Vec3(x[i * 3 + 0], x[i * 3 + 1], x[i * 3 + 2]); 54 | } 55 | inline void set_subvec(double *x, int i, const Vec3 &xi) 56 | { 57 | for (int j = 0; j < 3; j++) x[i * 3 + j] = xi[j]; 58 | } 59 | inline void add_subvec(double *x, int i, const Vec3 &xi) 60 | { 61 | for (int j = 0; j < 3; j++) x[i * 3 + j] += xi[j]; 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/bah.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef BAH_HPP 28 | #define BAH_HPP 29 | 30 | // Bounding area hierarchy for triangles in 2D 31 | // based on bvh.hpp 32 | 33 | #include "mesh.hpp" 34 | #include "util.hpp" 35 | 36 | struct Box 37 | { 38 | Vec2 umin, umax; 39 | Box() : umin(Vec2(infinity)), umax(Vec2(-infinity)) {} 40 | Box(const Vec2 &u) : umin(u), umax(u) {} 41 | Box &operator+= (const Vec2 &u); 42 | Box &operator+= (const Box &box); 43 | bool overlaps(const Box &box) const; 44 | Vec2 size() const; 45 | Vec2 center() const; 46 | }; 47 | 48 | struct BahNode 49 | { 50 | Box box; 51 | Face *face; 52 | BahNode *parent; 53 | BahNode *left; 54 | BahNode *right; 55 | BahNode(); 56 | BahNode(BahNode*, Face*, const Box&); 57 | BahNode(BahNode*, Face**, unsigned int, Box*, Vec2*); 58 | ~BahNode(); 59 | }; 60 | 61 | BahNode *new_bah_tree(const Mesh &mesh); 62 | void delete_bah_tree(BahNode *root); 63 | 64 | typedef void(*BahCallback) (Face *face0, const Face *face1); 65 | void for_overlapping_faces(Face *face, const BahNode *node, 66 | BahCallback callback); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/blockvectors.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef BLOCKVECTORS_HPP 28 | #define BLOCKVECTORS_HPP 29 | 30 | #include "vectors.hpp" 31 | 32 | template 33 | Vec mat_to_vec(const Mat &A) 34 | { 35 | Vec a; 36 | for (int i = 0; i < m; i++) 37 | for (int j = 0; j < n; j++) 38 | a[i + j * m] = A(i, j); 39 | return a; 40 | } 41 | 42 | template 43 | Mat vec_to_mat(const Vec &a) 44 | { 45 | Mat A; 46 | for (int i = 0; i < m; i++) 47 | for (int j = 0; j < n; j++) 48 | A(i, j) = a[i + j * m]; 49 | return A; 50 | } 51 | 52 | template Mat blockdiag(const Mat &A) 53 | { 54 | Mat B = 0; 55 | for (int b = 0; b < bn; b++) 56 | for (int i = 0; i < m; i++) 57 | for (int j = 0; j < n; j++) 58 | B(b*m + i, b*n + j) = A(i, j); 59 | return B; 60 | } 61 | 62 | template Mat transpose() 63 | { 64 | Mat T = 0; 65 | for (int i = 0; i < m; i++) 66 | for (int j = 0; j < n; j++) 67 | T(n*i + j, i + j * m) = 1; 68 | return T; 69 | } 70 | 71 | template Mat symmetrize(); 72 | 73 | template <> inline Mat<3, 4> symmetrize<2>() 74 | { 75 | Mat<3, 4> S = Mat<3, 4>(0); 76 | S(0, 0) = 1.f; 77 | S(1, 3) = 1.f; 78 | S(2, 1) = S(2, 2) = 1 / 2.f; 79 | return S; 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/cloth.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #include "cloth.hpp" 28 | 29 | void compute_masses(Cloth & cloth) 30 | { 31 | for (int v = 0; v < cloth.mesh.verts.size(); v++) 32 | cloth.mesh.verts[v]->mass = 0.0f; 33 | 34 | for (int n = 0; n < cloth.mesh.nodes.size(); n++) 35 | cloth.mesh.nodes[n]->mass = 0.0f; 36 | 37 | for (int f = 0; f < cloth.mesh.faces.size(); f++) 38 | { 39 | Face * pFace = cloth.mesh.faces[f]; 40 | 41 | pFace->mass = pFace->restArea * cloth.materials[pFace->label]->density; 42 | 43 | for (int v = 0; v < 3; v++) 44 | { 45 | pFace->v[v]->mass += pFace->mass / 3.0f; 46 | 47 | pFace->v[v]->node->mass += pFace->mass / 3.0f; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/cloth.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "dde.hpp" 30 | #include "mesh.hpp" 31 | 32 | struct Cloth 33 | { 34 | Mesh mesh; 35 | 36 | struct Material 37 | { 38 | double density; // area density 39 | StretchingSamples stretching; 40 | BendingData bending; 41 | PrincipalCurvatureBasedBendingData pcb_bending; 42 | double damping; // stiffness-proportional damping coefficient 43 | double strain_min, strain_max; // strain limits 44 | double yield_curv, weakening; // plasticity parameters 45 | }; 46 | 47 | std::vector materials; 48 | 49 | struct Remeshing 50 | { 51 | double refine_angle, refine_compression, refine_velocity; 52 | double size_min, size_max; // size limits 53 | double aspect_min; // aspect ratio control 54 | } remeshing; 55 | }; 56 | 57 | void compute_masses(Cloth &cloth); -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/collision.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | struct Mesh; 32 | struct Constraint; 33 | 34 | void collision_response (std::vector & meshes, 35 | const std::vector & cons, 36 | const std::vector & obs_meshes); -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/collisionutil.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef COLLISIONUTIL_HPP 28 | #define COLLISIONUTIL_HPP 29 | 30 | #include "bvh.hpp" 31 | 32 | typedef DeformBVHNode BVHNode; 33 | typedef DeformBVHTree BVHTree; 34 | 35 | struct AccelStruct 36 | { 37 | BVHTree tree; 38 | BVHNode *root; 39 | std::vector leaves; 40 | AccelStruct(const Mesh &mesh, bool ccd); 41 | }; 42 | 43 | void update_accel_struct(AccelStruct &acc); 44 | 45 | void mark_all_inactive(AccelStruct &acc); 46 | void mark_active(AccelStruct &acc, const Face *face); 47 | 48 | // callback must be safe to parallelize via OpenMP 49 | typedef void(*BVHCallback) (const Face *face0, const Face *face1); 50 | 51 | void for_overlapping_faces(BVHNode *node, float thickness, 52 | BVHCallback callback); 53 | void for_overlapping_faces(BVHNode *node0, BVHNode *node1, float thickness, 54 | BVHCallback callback); 55 | void for_overlapping_faces(const std::vector &accs, 56 | const std::vector &obs_accs, 57 | double thickness, BVHCallback callback, 58 | bool parallel = true); 59 | void for_faces_overlapping_obstacles(const std::vector &accs, 60 | const std::vector &obs_accs, 61 | double thickness, BVHCallback callback, 62 | bool parallel = true); 63 | 64 | std::vector create_accel_structs 65 | (const std::vector &meshes, bool ccd); 66 | void destroy_accel_structs(std::vector &accs); 67 | 68 | // find index of mesh containing specified element 69 | template 70 | int find_mesh(const Prim *p, const std::vector &meshes); 71 | 72 | extern const std::vector *meshes; // to check if element is cloth or obs 73 | extern const std::vector *obs_meshes; 74 | template bool is_free(const Primitive *p) 75 | { 76 | return find_mesh(p, *::meshes) != -1; 77 | } 78 | 79 | #endif -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/conf.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef CONF_HPP 28 | #define CONF_HPP 29 | 30 | #include "simulation.hpp" 31 | 32 | void load_json(const std::string &filename, Simulation &sim); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/constraint.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef CONSTRAINT_HPP 28 | #define CONSTRAINT_HPP 29 | 30 | #include 31 | #include 32 | #include "mesh.hpp" 33 | #include "util.hpp" 34 | #include "sparse.hpp" 35 | #include "spline.hpp" 36 | #include "vectors.hpp" 37 | 38 | typedef std::map MeshGrad; 39 | typedef std::map, Mat3x3> MeshHess; 40 | 41 | struct Constraint 42 | { 43 | virtual ~Constraint() {}; 44 | virtual double value(int *sign = NULL) = 0; 45 | virtual MeshGrad gradient() = 0; 46 | virtual MeshGrad project() = 0; 47 | // energy function 48 | virtual double energy(double value) = 0; 49 | virtual double energy_grad(double value) = 0; 50 | virtual double energy_hess(double value) = 0; 51 | // frictional force 52 | virtual MeshGrad friction(double dt, MeshHess &jac) = 0; 53 | }; 54 | 55 | struct EqCon : public Constraint 56 | { 57 | // n . (node->x - x) = 0 58 | Node *node; 59 | Vec3 x, n; 60 | double stiff; 61 | double value(int *sign = NULL); 62 | MeshGrad gradient(); 63 | MeshGrad project(); 64 | double energy(double value); 65 | double energy_grad(double value); 66 | double energy_hess(double value); 67 | MeshGrad friction(double dt, MeshHess &jac); 68 | }; 69 | 70 | struct GlueCon : public Constraint 71 | { 72 | Node *nodes[2]; 73 | Vec3 n; 74 | double stiff; 75 | double value(int *sign = NULL); 76 | MeshGrad gradient(); 77 | MeshGrad project(); 78 | double energy(double value); 79 | double energy_grad(double value); 80 | double energy_hess(double value); 81 | MeshGrad friction(double dt, MeshHess &jac); 82 | }; 83 | 84 | struct IneqCon : public Constraint 85 | { 86 | // n . sum(w[i] verts[i]->x) >= 0 87 | Node *nodes[4]; 88 | double w[4]; 89 | bool free[4]; 90 | Vec3 n; 91 | double a; // area 92 | double mu; // friction 93 | double stiff; 94 | double value(int *sign = NULL); 95 | MeshGrad gradient(); 96 | MeshGrad project(); 97 | double energy(double value); 98 | double energy_grad(double value); 99 | double energy_hess(double value); 100 | MeshGrad friction(double dt, MeshHess &jac); 101 | }; 102 | 103 | #endif -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/dde.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef DDE_HPP 28 | #define DDE_HPP 29 | 30 | #include "sparse.hpp" 31 | #include "util.hpp" 32 | 33 | typedef Vec<4> Vec4; 34 | 35 | struct StretchingData { Vec4 d[2][5]; }; 36 | 37 | struct StretchingSamples { Vec4 s[40][40][40]; }; 38 | 39 | struct BendingData { double d[3][5]; }; 40 | 41 | struct PrincipalCurvatureBasedBendingData 42 | { 43 | double weft[2]; 44 | double warp[2]; 45 | double bias[2]; 46 | }; 47 | 48 | void evaluate_stretching_samples(StretchingSamples &samples, 49 | const StretchingData &data); 50 | 51 | Vec4 stretching_stiffness(const Mat2x2 &G, const StretchingSamples &samples); 52 | 53 | double bending_stiffness(const Edge *edge, int side, const BendingData &data, 54 | double initial_angle = 0); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/display.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef DISPLAY_HPP 28 | #define DISPLAY_HPP 29 | 30 | #include "simulation.hpp" 31 | #include "timer.hpp" 32 | 33 | extern Simulation sim; 34 | extern Timer fps; 35 | extern int frame; 36 | 37 | extern int subwindows[3]; 38 | 39 | struct GlutCallbacks 40 | { 41 | void(*idle) (); 42 | void(*keyboard) (unsigned char, int, int); 43 | void(*special) (int, int, int); 44 | GlutCallbacks() : idle(NULL), keyboard(NULL), special(NULL) {} 45 | }; 46 | 47 | void run_glut(const GlutCallbacks&); 48 | 49 | void redisplay(); 50 | 51 | #endif -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/displayphysics.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #include "displayphysics.hpp" 28 | 29 | #include "display.hpp" 30 | #include "io.hpp" 31 | #include "opengl.hpp" 32 | #include "misc.hpp" 33 | #include "runphysics.hpp" 34 | #include "simulation.hpp" 35 | #include "timer.hpp" 36 | #include "util.hpp" 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | using namespace std; 44 | 45 | #ifndef NO_OPENGL 46 | 47 | extern string outprefix; 48 | extern fstream timingfile; 49 | 50 | static bool running = false; 51 | 52 | static void idle() 53 | { 54 | if (!::running) 55 | return; 56 | sim_step(); 57 | redisplay(); 58 | } 59 | 60 | extern void zoom(bool in); 61 | 62 | static void keyboard(unsigned char key, int x, int y) 63 | { 64 | unsigned char esc = 27, space = ' '; 65 | if (key == esc) 66 | { 67 | exit(EXIT_SUCCESS); 68 | } 69 | else if (key == space) 70 | { 71 | ::running = !::running; 72 | } 73 | else if (key == 's') 74 | { 75 | ::running = !::running; 76 | idle(); 77 | ::running = !::running; 78 | } 79 | else if (key == 'z') 80 | { 81 | zoom(true); 82 | } 83 | else if (key == 'x') 84 | { 85 | zoom(false); 86 | } 87 | } 88 | 89 | void display_physics(const vector &args) 90 | { 91 | if (args.size() != 1 && args.size() != 2) 92 | { 93 | cout << "Runs the simulation with an OpenGL display." << endl; 94 | cout << "Arguments:" << endl; 95 | cout << " : JSON file describing the simulation setup" 96 | << endl; 97 | cout << " (optional): Directory to save output in" << endl; 98 | exit(EXIT_FAILURE); 99 | } 100 | string json_file = args[0]; 101 | string outprefix = args.size() > 1 ? args[1] : ""; 102 | if (!outprefix.empty()) 103 | ensure_existing_directory(outprefix); 104 | init_physics(json_file, outprefix, false); 105 | if (!outprefix.empty()) 106 | save(sim, 0); 107 | GlutCallbacks cb; 108 | cb.idle = idle; 109 | cb.keyboard = keyboard; 110 | run_glut(cb); 111 | } 112 | 113 | void display_resume(const vector &args) 114 | { 115 | if (args.size() != 2) 116 | { 117 | cout << "Resumes an incomplete simulation." << endl; 118 | cout << "Arguments:" << endl; 119 | cout << " : Directory containing simulation output files" 120 | << endl; 121 | cout << " : Frame number to resume from" << endl; 122 | exit(EXIT_FAILURE); 123 | } 124 | init_resume(args); 125 | GlutCallbacks cb; 126 | cb.idle = idle; 127 | cb.keyboard = keyboard; 128 | run_glut(cb); 129 | } 130 | 131 | #else 132 | 133 | void display_physics(const vector &args) { opengl_fail(); } 134 | 135 | void display_resume(const vector &args) { opengl_fail(); } 136 | 137 | #endif // NO_OPENGL 138 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/displayphysics.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef DISPLAYPHYSICS_HPP 28 | #define DISPLAYPHYSICS_HPP 29 | 30 | #include 31 | #include 32 | 33 | void display_physics (const std::vector &args); 34 | void display_resume (const std::vector &args); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/displayreplay.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef DISPLAYREPLAY_HPP 28 | #define DISPLAYREPLAY_HPP 29 | 30 | #include 31 | #include 32 | 33 | void display_replay (const std::vector &args); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/displaytesting.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #include "displaytesting.hpp" 28 | #include "conf.hpp" 29 | #include "display.hpp" 30 | #include "dynamicremesh.hpp" 31 | #include "geometry.hpp" 32 | #include "io.hpp" 33 | #include "opengl.hpp" 34 | #include "plasticity.hpp" 35 | #include "runphysics.hpp" 36 | #include "util.hpp" 37 | #include 38 | using namespace std; 39 | 40 | #ifndef NO_OPENGL 41 | 42 | template Vec random() 43 | { 44 | Vec v; 45 | for (int i = 0; i < n; i++) 46 | v[i] = (double)rand() / RAND_MAX * 2 - 1; 47 | return v; 48 | } 49 | 50 | static void recover_plasticity(Mesh &mesh) 51 | { 52 | for (int f = 0; f < mesh.faces.size(); f++) 53 | mesh.faces[f]->S_plastic = curvature(mesh.faces[f]); 54 | } 55 | 56 | static void remeshing_step(Cloth &cloth) 57 | { 58 | // copy old meshes 59 | Mesh old_mesh = deep_copy(cloth.mesh); 60 | // back up residuals 61 | vector res = back_up_residuals(cloth.mesh); 62 | // remesh 63 | dynamic_remesh(cloth, vector(), false); 64 | // restore residuals 65 | restore_residuals(cloth.mesh, old_mesh, res); 66 | // delete old meshes 67 | delete_mesh(old_mesh); 68 | } 69 | 70 | static void keyboard(unsigned char key, int x, int y) 71 | { 72 | unsigned char esc = 27, enter = 13; 73 | if (key == esc) 74 | exit(0); 75 | if (key == ' ') 76 | { 77 | recover_plasticity(sim.cloths[0].mesh); 78 | } 79 | if (key == enter) 80 | { 81 | remeshing_step(sim.cloths[0]); 82 | } 83 | redisplay(); 84 | } 85 | 86 | void display_testing(const vector &args) 87 | { 88 | if (args.size() == 0) 89 | { 90 | cout << "Placeholder command for interactively testing stuff." << endl; 91 | cout << "Edit src/displaytesting.cpp and make it do whatever you like!" 92 | << endl; 93 | exit(EXIT_FAILURE); 94 | } 95 | string conf = args[0]; 96 | string meshfile = args[1]; 97 | load_json(conf, sim); 98 | prepare(sim); 99 | load_obj(*sim.cloth_meshes[0], meshfile); 100 | GlutCallbacks cb; 101 | cb.keyboard = keyboard; 102 | run_glut(cb); 103 | } 104 | 105 | #else 106 | 107 | void display_testing(const vector &args) { opengl_fail(); } 108 | 109 | #endif // NO_OPENGL 110 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/displaytesting.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef DISPLAYTESTING_HPP 28 | #define DISPLAYTESTING_HPP 29 | 30 | #include 31 | #include 32 | 33 | void display_testing (const std::vector &args); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/dynamicremesh.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include "cloth.hpp" 31 | #include "nearobs.hpp" 32 | 33 | void static_remesh(Cloth &cloth); 34 | 35 | void dynamic_remesh(Cloth &cloth, const std::vector &planes, bool plasticity); -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/geometry.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef GEOMETRY_HPP 28 | #define GEOMETRY_HPP 29 | 30 | #include "mesh.hpp" 31 | #include "util.hpp" 32 | 33 | double signed_vf_distance (const Vec3 &x, 34 | const Vec3 &y0, const Vec3 &y1, const Vec3 &y2, 35 | Vec3 *n, double *w); 36 | 37 | double signed_ee_distance (const Vec3 &x0, const Vec3 &x1, 38 | const Vec3 &y0, const Vec3 &y1, 39 | Vec3 *n, double *w); 40 | 41 | double unsigned_vf_distance (const Vec3 &x, 42 | const Vec3 &y0, const Vec3 &y1, const Vec3 &y2, 43 | Vec3 *n, double *w); 44 | 45 | double unsigned_ee_distance (const Vec3 &x0, const Vec3 &x1, 46 | const Vec3 &y0, const Vec3 &y1, 47 | Vec3 *n, double *w); 48 | 49 | Vec3 get_barycentric_coords (const Vec2 &point, const Face *face); 50 | 51 | Face* get_enclosing_face (const Mesh& mesh, const Vec2& u, 52 | Face *starting_face_hint = NULL); 53 | 54 | enum Space {PS, WS}; // plastic space, world space 55 | 56 | template const Vec3 &pos (const Node *node); 57 | template Vec3 &pos (Node *node); 58 | template Vec3 nor (const Face *face); 59 | template double dihedral_angle (const Edge *edge); 60 | template Mat2x2 curvature (const Face *face); 61 | 62 | double unwrap_angle (double theta, double theta_ref); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/handle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #define _USE_MATH_DEFINES 28 | 29 | #include 30 | #include "handle.hpp" 31 | #include "magic.hpp" 32 | 33 | using namespace std; 34 | 35 | static Vec3 directions[3] = { Vec3(1,0,0), Vec3(0,1,0), Vec3(0,0,1) }; 36 | 37 | void add_position_constraints(const Node *node, const Vec3 &x, double stiff, 38 | vector &cons); 39 | 40 | Transformation normalize(const Transformation &T) 41 | { 42 | Transformation T1 = T; 43 | T1.rotation = normalize(T1.rotation); 44 | return T1; 45 | } 46 | 47 | vector NodeHandle::get_constraints(double t) 48 | { 49 | double s = strength(t); 50 | if (!s) 51 | return vector(); 52 | if (!activated) 53 | { 54 | // handle just got started, fill in its original position 55 | x0 = motion ? inverse(normalize(motion->pos(t))).apply(node->x) : node->x; 56 | activated = true; 57 | } 58 | Vec3 x = motion ? normalize(motion->pos(t)).apply(x0) : x0; 59 | vector cons; 60 | add_position_constraints(node, x, s*::magic.handle_stiffness, cons); 61 | return cons; 62 | } 63 | 64 | vector CircleHandle::get_constraints(double t) 65 | { 66 | double s = strength(t); 67 | if (!s) 68 | return vector(); 69 | vector cons; 70 | for (int n = 0; n < mesh->nodes.size(); n++) 71 | { 72 | Node *node = mesh->nodes[n]; 73 | if (node->label != label) 74 | continue; 75 | double theta = 2 * M_PI*dot(node->verts[0]->u, u) / c; 76 | Vec3 x = xc + (dx0*cos(theta) + dx1 * sin(theta))*c / (2 * M_PI); 77 | if (motion) 78 | x = motion->pos(t).apply(x); 79 | double l = 0; 80 | for (int e = 0; e < node->adje.size(); e++) 81 | { 82 | const Edge *edge = node->adje[e]; 83 | if (edge->nodes[0]->label != label || edge->nodes[1]->label != label) 84 | continue; 85 | l += edge->l; 86 | } 87 | add_position_constraints(node, x, s*::magic.handle_stiffness*l, cons); 88 | } 89 | return cons; 90 | } 91 | 92 | vector GlueHandle::get_constraints(double t) 93 | { 94 | double s = strength(t); 95 | if (!s) 96 | return vector(); 97 | vector cons; 98 | for (int i = 0; i < 3; i++) 99 | { 100 | GlueCon *con = new GlueCon; 101 | con->nodes[0] = nodes[0]; 102 | con->nodes[1] = nodes[1]; 103 | con->n = directions[i]; 104 | con->stiff = s * ::magic.handle_stiffness; 105 | cons.push_back(con); 106 | } 107 | return cons; 108 | } 109 | 110 | void add_position_constraints(const Node *node, const Vec3 &x, double stiff, 111 | vector &cons) 112 | { 113 | for (int i = 0; i < 3; i++) 114 | { 115 | EqCon *con = new EqCon; 116 | con->node = (Node*)node; 117 | con->x = x; 118 | con->n = directions[i]; 119 | con->stiff = stiff; 120 | cons.push_back(con); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/handle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef HANDLE_HPP 28 | #define HANDLE_HPP 29 | 30 | #include "constraint.hpp" 31 | #include "mesh.hpp" 32 | #include 33 | 34 | struct Handle 35 | { 36 | double start_time, end_time, fade_time; 37 | virtual ~Handle() {}; 38 | virtual std::vector get_constraints(double t) = 0; 39 | virtual std::vector get_nodes() = 0; 40 | bool active(double t) { return t >= start_time && t <= end_time; } 41 | double strength(double t) 42 | { 43 | if (t < start_time || t > end_time + fade_time) return 0; 44 | if (t <= end_time) return 1; 45 | double s = 1 - (t - end_time) / (fade_time + 1e-6); 46 | return sq(sq(s)); 47 | } 48 | }; 49 | 50 | struct NodeHandle : public Handle 51 | { 52 | Node *node; 53 | const Motion *motion; 54 | bool activated; 55 | Vec3 x0; 56 | NodeHandle() : activated(false) {} 57 | std::vector get_constraints(double t); 58 | std::vector get_nodes() { return std::vector(1, node); } 59 | }; 60 | 61 | struct CircleHandle : public Handle 62 | { 63 | Mesh *mesh; 64 | int label; 65 | const Motion *motion; 66 | double c; // circumference 67 | Vec2 u; 68 | Vec3 xc, dx0, dx1; 69 | std::vector get_constraints(double t); 70 | std::vector get_nodes() { return std::vector(); } 71 | }; 72 | 73 | struct GlueHandle : public Handle 74 | { 75 | Node* nodes[2]; 76 | std::vector get_constraints(double t); 77 | std::vector get_nodes() 78 | { 79 | std::vector ns; 80 | ns.push_back(nodes[0]); 81 | ns.push_back(nodes[1]); 82 | return ns; 83 | } 84 | }; 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/io.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef IO_HPP 28 | #define IO_HPP 29 | 30 | #include "mesh.hpp" 31 | 32 | void triangle_to_obj (const std::string &infile, const std::string &outfile); 33 | 34 | void load_obj (Mesh &mesh, const std::string &filename); 35 | void load_objs (std::vector &meshes, const std::string &prefix); 36 | 37 | void save_obj (const Mesh &mesh, const std::string &filename); 38 | void save_objs (const std::vector &meshes, const std::string &prefix); 39 | 40 | void save_transformation (const Transformation &tr, 41 | const std::string &filename); 42 | 43 | // w_crop and h_crop specify a multiplicative crop window 44 | void save_screenshot (const std::string &filename); 45 | 46 | // check that output directory exists; if not, create it 47 | void ensure_existing_directory (const std::string &path); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/lbfgs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #include "optimization.hpp" 28 | 29 | #include "alglib/optimization.h" 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | using namespace alglib; 35 | 36 | static const NLOpt *problem; 37 | 38 | static void lbfgs_value_and_grad(const real_1d_array &x, double &value, 39 | real_1d_array &grad, void *ptr = NULL); 40 | 41 | void l_bfgs_method(const NLOpt &problem, OptOptions opt, bool verbose) 42 | { 43 | ::problem = &problem; 44 | real_1d_array x; 45 | x.setlength(::problem->nvar); 46 | ::problem->initialize(&x[0]); 47 | minlbfgsstate state; 48 | minlbfgsreport rep; 49 | int m = 10; 50 | minlbfgscreate(m, x, state); 51 | minlbfgssetcond(state, opt.eps_g(), opt.eps_f(), opt.eps_x(), 52 | opt.max_iter()); 53 | minlbfgsoptimize(state, lbfgs_value_and_grad); 54 | minlbfgsresults(state, x, rep); 55 | if (verbose) 56 | cout << rep.iterationscount << " iterations" << endl; 57 | ::problem->finalize(&x[0]); 58 | } 59 | 60 | static void add(real_1d_array &x, const vector &y) 61 | { 62 | for (int i = 0; i < y.size(); i++) 63 | x[i] += y[i]; 64 | } 65 | 66 | static void lbfgs_value_and_grad(const real_1d_array &x, double &value, 67 | real_1d_array &grad, void *ptr) 68 | { 69 | ::problem->precompute(&x[0]); 70 | value = ::problem->objective(&x[0]); 71 | ::problem->gradient(&x[0], &grad[0]); 72 | } 73 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/magic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #include "magic.hpp" 28 | 29 | Magic magic; -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/magic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #pragma once 28 | 29 | // Magic numbers and other hacks 30 | 31 | struct Magic 32 | { 33 | bool fixed_high_res_mesh; 34 | double handle_stiffness, collision_stiffness; 35 | double repulsion_thickness, projection_thickness; 36 | double edge_flip_threshold; 37 | double rib_stiffening; 38 | bool combine_tensors; 39 | bool preserve_creases; 40 | bool use_princinpal_curvature_based_bending; 41 | 42 | Magic() : 43 | fixed_high_res_mesh(false), 44 | use_princinpal_curvature_based_bending(false), 45 | handle_stiffness(1e3), 46 | collision_stiffness(1e9), 47 | repulsion_thickness(1e-3), 48 | projection_thickness(1e-4), 49 | edge_flip_threshold(1e-2), 50 | rib_stiffening(1), 51 | combine_tensors(true), 52 | preserve_creases(false) 53 | { 54 | } 55 | }; 56 | 57 | extern Magic magic; -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/misc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef MISC_HPP 28 | #define MISC_HPP 29 | 30 | #include 31 | #include 32 | 33 | // Converts Shewchuck's triangle output (.node/.ele) to a .obj 34 | void tri2obj (const std::vector &args); 35 | 36 | // Combines two meshes into a single obj 37 | void merge_meshes (const std::vector &args); 38 | 39 | // Does the opposite of merge_meshes 40 | void split_meshes (const std::vector &args); 41 | 42 | // This function can exist anywhere and the linker will find it 43 | void debug (const std::vector &args); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/morph.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "morph.hpp" 3 | #include "geometry.hpp" 4 | 5 | using namespace std; 6 | 7 | Vec3 blend(const vector & targets, const vector & w, const Vec2 & u) 8 | { 9 | Vec3 x = Vec3(0); 10 | 11 | for (int m = 0; m < targets.size(); m++) 12 | { 13 | if (w[m] == 0) continue; 14 | 15 | Face *face = get_enclosing_face(targets[m], u); 16 | 17 | if (!face) continue; 18 | 19 | Vec3 b = get_barycentric_coords(u, face); 20 | 21 | x += w[m] * (b[0] * face->v[0]->node->x + b[1] * face->v[1]->node->x + b[2] * face->v[2]->node->x); 22 | } 23 | 24 | return x; 25 | } 26 | 27 | Vec3 Morph::pos(double t, const Vec2 &u) const 28 | { 29 | return blend(targets, weights.pos(t), u); 30 | } 31 | 32 | void apply(const Morph & morph, double t) 33 | { 34 | for (int n = 0; n < morph.mesh->nodes.size(); n++) 35 | { 36 | Node * pNode = morph.mesh->nodes[n]; 37 | 38 | Vec3 x = Vec3(0); 39 | 40 | for (int v = 0; v < pNode->verts.size(); v++) 41 | x += morph.pos(t, pNode->verts[v]->u); 42 | 43 | pNode->x = x / (double)pNode->verts.size(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/morph.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "mesh.hpp" 5 | 6 | struct Morph 7 | { 8 | Mesh *mesh; 9 | std::vector targets; 10 | typedef std::vector Weights; 11 | Spline weights; 12 | Spline log_stiffness; 13 | Vec3 pos(double t, const Vec2 &u) const; 14 | }; 15 | 16 | void apply(const Morph &morph, double t); -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/mot_parser.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef MOT_PARSER_HPP 28 | #define MOT_PARSER_HPP 29 | 30 | #include "obstacle.hpp" 31 | #include "util.hpp" 32 | #include "vectors.hpp" 33 | #include 34 | #include 35 | #include 36 | 37 | std::vector load_mot(const std::string &filename, double fps); 38 | 39 | // I think I'm going to ignore all the rest down here 40 | 41 | typedef Vec<4> Vec4; 42 | 43 | class mot_parser_exception 44 | { 45 | public: 46 | mot_parser_exception(const std::string& error) : error(error) {} 47 | std::string error; 48 | }; 49 | 50 | struct BodyFrame 51 | { 52 | Vec3 pos; 53 | Vec4 orient; 54 | }; 55 | 56 | typedef std::vector BodyFrameVector; 57 | typedef std::vector BodyVector; 58 | 59 | BodyVector read_motion_file(const std::string& filename); 60 | BodyVector read_motion_file(std::istream& istr); 61 | 62 | void write_motion_file(BodyVector& bodies, const std::string& filename); 63 | void write_motion_file(BodyVector& bodies, std::ostream& ostr); 64 | 65 | BodyFrame& get_body_frame(BodyVector& bodies, size_t body_index, size_t frame); 66 | BodyFrameVector& get_body_frames(BodyVector& bodies, size_t body_index); 67 | //BodyFrameVector& get_body_frames(size_t body_index); 68 | 69 | std::vector > mot_to_spline(std::string motion_file, 70 | const Transformation& tr, double fps, double start_time, double pause_time); 71 | 72 | std::vector mot_to_obs(std::string motion_file, 73 | const Transformation& tr, std::string obj_basename, double fps, 74 | double start_time, double pause_time); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/nearobs.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef NEAROBS_HPP 28 | #define NEAROBS_HPP 29 | 30 | #include "mesh.hpp" 31 | 32 | typedef std::pair Plane; 33 | 34 | std::vector nearest_obstacle_planes(const Mesh &mesh, const std::vector &obs_meshes); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/nlcg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #include "optimization.hpp" 28 | 29 | #include "alglib/optimization.h" 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | using namespace alglib; 35 | 36 | static const NLOpt *problem; 37 | 38 | static void nlcg_value_and_grad(const real_1d_array &x, double &value, 39 | real_1d_array &grad, void *ptr = NULL); 40 | 41 | void nonlinear_conjugate_gradients(const NLOpt &problem, OptOptions opt, 42 | bool verbose) 43 | { 44 | ::problem = &problem; 45 | real_1d_array x; 46 | x.setlength(::problem->nvar); 47 | ::problem->initialize(&x[0]); 48 | mincgstate state; 49 | mincgreport rep; 50 | mincgcreate(x, state); 51 | mincgsetcond(state, opt.eps_g(), opt.eps_f(), opt.eps_x(), opt.max_iter()); 52 | mincgsuggeststep(state, 1e-6*::problem->nvar); 53 | mincgoptimize(state, nlcg_value_and_grad); 54 | mincgresults(state, x, rep); 55 | if (verbose) 56 | cout << rep.iterationscount << " iterations" << endl; 57 | ::problem->finalize(&x[0]); 58 | } 59 | 60 | static void add(real_1d_array &x, const vector &y) 61 | { 62 | for (int i = 0; i < y.size(); i++) 63 | x[i] += y[i]; 64 | } 65 | 66 | static void nlcg_value_and_grad(const real_1d_array &x, double &value, 67 | real_1d_array &grad, void *ptr) 68 | { 69 | ::problem->precompute(&x[0]); 70 | value = ::problem->objective(&x[0]); 71 | ::problem->gradient(&x[0], &grad[0]); 72 | } 73 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/obstacle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #include "io.hpp" 28 | #include "obstacle.hpp" 29 | #include "util.hpp" 30 | #include 31 | 32 | using namespace std; 33 | 34 | Mesh& Obstacle::get_mesh() 35 | { 36 | return curr_state_mesh; 37 | } 38 | 39 | const Mesh& Obstacle::get_mesh() const 40 | { 41 | return curr_state_mesh; 42 | } 43 | 44 | Mesh& Obstacle::get_mesh(double time) 45 | { 46 | if (time > end_time) 47 | delete_mesh(curr_state_mesh); 48 | if (time < start_time || time > end_time) 49 | return curr_state_mesh; 50 | if (!activated) 51 | curr_state_mesh = deep_copy(base_mesh); 52 | if (transform_spline) 53 | { 54 | DTransformation dtrans = get_dtrans(*transform_spline, time); 55 | Mesh &mesh = curr_state_mesh; 56 | for (int n = 0; n < curr_state_mesh.nodes.size(); n++) 57 | mesh.nodes[n]->x = apply_dtrans(dtrans, base_mesh.nodes[n]->x, 58 | &mesh.nodes[n]->v); 59 | compute_ws_data(mesh); 60 | } 61 | if (!activated) 62 | update_x0(curr_state_mesh); 63 | activated = true; 64 | return curr_state_mesh; 65 | } 66 | 67 | void Obstacle::blend_with_previous(double t, double dt, double blend) 68 | { 69 | const Motion *spline = transform_spline; 70 | Transformation trans = (spline) 71 | ? get_trans(*spline, t) 72 | * inverse(get_trans(*spline, t - dt)) 73 | : ::identity(); 74 | Mesh &mesh = curr_state_mesh; 75 | for (int n = 0; n < mesh.nodes.size(); n++) 76 | { 77 | Node *node = mesh.nodes[n]; 78 | Vec3 x0 = trans.apply(node->x0); 79 | node->x = x0 + blend * (node->x - x0); 80 | } 81 | compute_ws_data(mesh); 82 | } 83 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/obstacle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "mesh.hpp" 30 | #include "spline.hpp" 31 | #include "util.hpp" 32 | 33 | // A class which holds both moving and static meshes. 34 | // Note that moving meshes MUST retain their structure across frames with only 35 | // positions changing. 36 | struct Obstacle 37 | { 38 | 39 | public: 40 | 41 | double start_time, end_time; 42 | bool activated; 43 | // Gets the last-returned mesh or its transformation 44 | Mesh& get_mesh(); 45 | const Mesh& get_mesh() const; 46 | 47 | // Gets the state of the mesh at a given time, and updates the internal 48 | // meshes 49 | Mesh& get_mesh(double time_sec); 50 | 51 | // lerp with previous mesh at time t - dt 52 | void blend_with_previous(double t, double dt, double blend); 53 | 54 | const Motion *transform_spline; 55 | 56 | // A mesh containing the original, untransformed object 57 | Mesh base_mesh; 58 | // A mesh containing the correct mesh structure 59 | Mesh curr_state_mesh; 60 | 61 | Obstacle() : start_time(0), end_time(infinity), activated(false) {} 62 | }; 63 | 64 | // // Default arguments imply it's a static obstacle 65 | // // An obstacle mesh may have multiple parts, so when you read one in, 66 | // // you get a vector of obstacles back, each representing one part. 67 | // std::vector make_obstacle 68 | // (std::string filename, Transformation overall_transform = identity(), 69 | // std::vector global_transforms = std::vector(), 70 | // double fps = 1, double start_time = 0, double pause_time = 0); -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/opengl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef OPENGL_HPP 28 | #define OPENGL_HPP 29 | 30 | #ifndef NO_OPENGL 31 | 32 | #define GL_GLEXT_PROTOTYPES 33 | 34 | #if __APPLE__ & __MACH__ 35 | #include 36 | #include 37 | #include 38 | #include 39 | #elif defined(_WIN32) 40 | #include 41 | #include 42 | #include 43 | //#include 44 | //#include 45 | //#include 46 | #include 47 | #else 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #endif 54 | 55 | #else 56 | 57 | #include 58 | #include 59 | inline void opengl_fail() 60 | { 61 | std::cout << "Error: OpenGL is disabled in this build." << std::endl; 62 | std::exit(EXIT_FAILURE); 63 | } 64 | 65 | #endif // NO_OPENGL 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/physics.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include "cloth.hpp" 31 | #include "geometry.hpp" 32 | #include "simulation.hpp" 33 | 34 | template double internal_energy(const Cloth &cloth); 35 | 36 | double constraint_energy(const std::vector &cons); 37 | 38 | // A += dt^2 dF/dx; b += dt F + dt^2 dF/dx v 39 | // also adds damping terms 40 | // if dt == 0, just does A += dF/dx; b += F instead, no damping 41 | template 42 | void add_internal_forces(const Cloth &cloth, SpMat &A, 43 | std::vector &b, double dt); 44 | 45 | void add_constraint_forces(const Cloth &cloth, 46 | const std::vector &cons, 47 | SpMat &A, std::vector &b, double dt); 48 | 49 | void add_external_forces(const Cloth &cloth, const Vec3 &gravity, 50 | const Wind &wind, std::vector &fext, 51 | std::vector &Jext); 52 | 53 | void add_morph_forces(const Cloth &cloth, const Morph &morph, double t, 54 | double dt, 55 | std::vector &fext, std::vector &Jext); 56 | 57 | void implicit_update(Cloth &cloth, const std::vector &fext, 58 | const std::vector &Jext, 59 | const std::vector &cons, double dt, 60 | bool update_positions = true); -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/plasticity.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef PLASTICITY_HPP 28 | #define PLASTICITY_HPP 29 | 30 | #include "cloth.hpp" 31 | 32 | void reset_plasticity (Cloth &cloth); 33 | 34 | void plastic_update (Cloth &cloth); 35 | 36 | void optimize_plastic_embedding (Cloth &cloth); 37 | 38 | struct Residual {Mat2x2 S_res; double damage;}; 39 | std::vector back_up_residuals (Mesh &mesh); 40 | void restore_residuals (Mesh &mesh, const Mesh &old_mesh, 41 | const std::vector &res); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/popfilter.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "cloth.hpp" 30 | #include "constraint.hpp" 31 | 32 | void apply_pop_filter (Cloth & cloth, const std::vector & cons, double regularization = 1e3); -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/proximity.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #pragma 28 | 29 | #include 30 | 31 | struct Mesh; 32 | struct Constraint; 33 | 34 | std::vector proximity_constraints(const std::vector & meshes, 35 | const std::vector & obs_meshes, 36 | double friction, double obs_friction); -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/remesh.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "mesh.hpp" 30 | 31 | // Pointers are owned by the RemeshOp. 32 | // Use done() and/or inverse().done() to free. 33 | 34 | struct RemeshOp 35 | { 36 | std::vector added_verts, removed_verts; 37 | std::vector added_nodes, removed_nodes; 38 | std::vector added_edges, removed_edges; 39 | std::vector added_faces, removed_faces; 40 | bool empty() { return added_faces.empty() && removed_faces.empty(); } 41 | RemeshOp inverse() const; 42 | void apply(Mesh &mesh) const; 43 | void done() const; // frees removed data 44 | }; 45 | 46 | std::ostream &operator<< (std::ostream &out, const RemeshOp &op); 47 | 48 | RemeshOp compose(const RemeshOp &op1, const RemeshOp &op2); 49 | 50 | // These do not change the mesh directly, 51 | // they return a RemeshOp that you can apply() to the mesh 52 | 53 | RemeshOp split_edge(Edge *edge); 54 | 55 | RemeshOp collapse_edge(Edge *edge, int which); // which end to delete 56 | 57 | RemeshOp flip_edge(Edge *edge); -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/runphysics.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include "simulation.hpp" 31 | 32 | void sim_step(); 33 | void save(const Simulation &sim, int frame); 34 | void init_physics (const std::string &json_file, std::string outprefix, bool is_reloading); 35 | void init_resume(const std::vector &args); 36 | void run_physics (const std::vector &args); 37 | void resume_physics (const std::vector &args); -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/separate.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef SEPARATE_HPP 28 | #define SEPARATE_HPP 29 | 30 | #include "mesh.hpp" 31 | 32 | void separate (std::vector &meshes, const std::vector &old_meshes, 33 | const std::vector &obs_meshes); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/separateobs.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef SEPARATEOBS_HPP 28 | #define SEPARATEOBS_HPP 29 | 30 | #include "mesh.hpp" 31 | 32 | void separate_obstacles (std::vector &obs_meshes, 33 | const std::vector &meshes); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/simulation.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef SIMULATION_HPP 28 | #define SIMULATION_HPP 29 | 30 | #include "cloth.hpp" 31 | #include "constraint.hpp" 32 | #include "handle.hpp" 33 | #include "morph.hpp" 34 | #include "obstacle.hpp" 35 | #include "spline.hpp" 36 | #include "timer.hpp" 37 | #include 38 | #include 39 | 40 | struct Wind 41 | { 42 | double density; 43 | Vec3 velocity; 44 | double drag; 45 | }; 46 | 47 | struct Simulation 48 | { 49 | // variables 50 | double time; 51 | int frame, step; 52 | std::vector cloths; 53 | // constants 54 | int frame_steps; 55 | double frame_time, step_time; 56 | double end_time, end_frame; 57 | std::vector motions; 58 | std::vector handles; 59 | std::vector obstacles; 60 | std::vector morphs; 61 | Vec3 gravity; 62 | Wind wind; 63 | double friction, obs_friction; 64 | enum 65 | { 66 | Proximity, Physics, StrainLimiting, Collision, Remeshing, Separation, 67 | PopFilter, Plasticity, nModules 68 | }; 69 | bool enabled[nModules]; 70 | Timer timers[nModules]; 71 | // handy pointers 72 | std::vector cloth_meshes, obstacle_meshes; 73 | }; 74 | 75 | void prepare(Simulation &sim); 76 | 77 | void relax_initial_state(Simulation &sim); 78 | 79 | void advance_frame(Simulation &sim); 80 | 81 | void advance_step(Simulation &sim); 82 | 83 | // Helper functions 84 | 85 | template int size(const std::vector &meshes); 86 | template int get_index(const Prim *p, 87 | const std::vector &meshes); 88 | template Prim *get(int i, const std::vector &meshes); 89 | 90 | std::vector node_positions(const std::vector &meshes); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/spline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #include "spline.hpp" 28 | #include "util.hpp" 29 | 30 | using namespace std; 31 | 32 | // binary search, returns keyframe immediately *after* given time 33 | // range of output: 0 to a.keyfs.size() inclusive 34 | template 35 | static int find(const Spline &s, double t) 36 | { 37 | int l = 0, u = s.points.size(); 38 | while (l != u) 39 | { 40 | int m = (l + u) / 2; 41 | if (t < s.points[m].t) u = m; 42 | else l = m + 1; 43 | } 44 | return l; // which is equal to u 45 | } 46 | 47 | template 48 | T Spline::pos(double t) const 49 | { 50 | int i = find(*this, t); 51 | if (i == 0) 52 | { 53 | const Point &p1 = points[i]; 54 | return p1.x; 55 | } 56 | else if (i == points.size()) 57 | { 58 | const Point &p0 = points[i - 1]; 59 | return p0.x; 60 | } 61 | else 62 | { 63 | const Point &p0 = points[i - 1], &p1 = points[i]; 64 | double s = (t - p0.t) / (p1.t - p0.t), s2 = s * s, s3 = s2 * s; 65 | return p0.x*(2 * s3 - 3 * s2 + 1) + p1.x*(-2 * s3 + 3 * s2) 66 | + (p0.v*(s3 - 2 * s2 + s) + p1.v*(s3 - s2))*(p1.t - p0.t); 67 | } 68 | } 69 | 70 | template 71 | T Spline::vel(double t) const 72 | { 73 | int i = find(*this, t); 74 | if (i == 0 || i == points.size()) 75 | { 76 | return T(0); 77 | } 78 | else 79 | { 80 | const Point &p0 = points[i - 1], &p1 = points[i]; 81 | double s = (t - p0.t) / (p1.t - p0.t), s2 = s * s; 82 | return (p0.x*(6 * s2 - 6 * s) + p1.x*(-6 * s2 + 6 * s)) / (p1.t - p0.t) 83 | + p0.v*(3 * s2 - 4 * s + 1) + p1.v*(3 * s2 - 2 * s); 84 | } 85 | } 86 | 87 | vector operator+ (const vector &x, const vector &y) 88 | { 89 | vector z(min(x.size(), y.size())); 90 | for (int i = 0; i < z.size(); i++) z[i] = x[i] + y[i]; 91 | return z; 92 | } 93 | vector operator- (const vector &x, const vector &y) 94 | { 95 | vector z(min(x.size(), y.size())); 96 | for (int i = 0; i < z.size(); i++) z[i] = x[i] - y[i]; 97 | return z; 98 | } 99 | vector operator* (const vector &x, double a) 100 | { 101 | vector y(x.size()); 102 | for (int i = 0; i < y.size(); i++) y[i] = x[i] * a; 103 | return y; 104 | } 105 | vector operator/ (const vector &x, double a) { return x * (1 / a); } 106 | 107 | template class Spline; 108 | template class Spline; 109 | template class Spline; 110 | template class Spline< vector >; 111 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/spline.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef SPLINE_HPP 28 | #define SPLINE_HPP 29 | 30 | #include "vectors.hpp" 31 | #include 32 | 33 | template 34 | class Spline 35 | { 36 | public: 37 | // cubic Hermite spline with linear extrapolation 38 | struct Point { double t; T x, v; }; 39 | std::vector points; 40 | T pos(double t) const; 41 | T vel(double t) const; 42 | }; 43 | 44 | std::vector operator+ (const std::vector &x, 45 | const std::vector &y); 46 | std::vector operator- (const std::vector &x, 47 | const std::vector &y); 48 | std::vector operator* (const std::vector &x, double a); 49 | std::vector operator/ (const std::vector &x, double a); 50 | 51 | template void fill_in_velocity(Spline &s, int i) 52 | { 53 | if (i - 1 < 0 || i + 1 >= s.points.size()) 54 | s.points[i].v = s.points[i].x * 0.; 55 | else 56 | s.points[i].v = (s.points[i + 1].x - s.points[i - 1].x) 57 | / (s.points[i + 1].t - s.points[i - 1].t); 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/strainlimiting.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef STRAINLIMITING_HPP 28 | #define STRAINLIMITING_HPP 29 | 30 | #include "cloth.hpp" 31 | #include "constraint.hpp" 32 | 33 | std::vector get_strain_limits (const std::vector &cloths); 34 | 35 | void strain_limiting (std::vector &meshes, 36 | const std::vector &strain_limits, 37 | const std::vector &cons); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/taucs.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef TAUCS_HPP 28 | #define TAUCS_HPP 29 | 30 | #include "sparse.hpp" 31 | #include "vectors.hpp" 32 | 33 | std::vector taucs_linear_solve(const SpMat & A, const std::vector & b); 34 | 35 | template std::vector< Vec > taucs_linear_solve(const SpMat< Mat > & A, const std::vector< Vec > & b); 36 | 37 | #endif -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/tensormax.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef TENSORMAX_HPP 28 | #define TENSORMAX_HPP 29 | 30 | #include "vectors.hpp" 31 | #include 32 | 33 | Mat2x2 tensor_max (const std::vector &Ms); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #include 28 | #include "timer.hpp" 29 | #include "simulation.hpp" 30 | 31 | using namespace std; 32 | using namespace boost::posix_time; 33 | 34 | Timer::Timer() : last(0), total(0) 35 | { 36 | tick(); 37 | } 38 | 39 | void Timer::tick() 40 | { 41 | then = microsec_clock::local_time(); 42 | } 43 | 44 | void Timer::tock() 45 | { 46 | ptime now = microsec_clock::local_time(); 47 | last = (now - then).total_microseconds()*1e-6; 48 | total += last; 49 | then = now; 50 | } -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/timer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | // Armin's timer class 28 | #ifndef __TIMER_H 29 | #define __TIMER_H 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | struct Timer 37 | { 38 | boost::posix_time::ptime then; 39 | double last, total; 40 | Timer(); 41 | void tick(), tock(); 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/transformation.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef TRANSFORMATION_HPP 28 | #define TRANSFORMATION_HPP 29 | 30 | #include "spline.hpp" 31 | #include "vectors.hpp" 32 | #include 33 | 34 | // Transform the mesh 35 | struct Quaternion 36 | { 37 | double s; 38 | Vec3 v; 39 | Vec3 rotate(const Vec3 &point) const; 40 | static Quaternion from_axisangle(const Vec3 &axis, double angle); 41 | std::pair to_axisangle() const; 42 | Quaternion operator+(const Quaternion& q) const; 43 | Quaternion operator-(const Quaternion& q) const; 44 | Quaternion operator-() const; 45 | Quaternion operator*(const Quaternion& q) const; 46 | Quaternion operator*(double scalar) const; 47 | Quaternion operator/(double scalar) const; 48 | }; 49 | 50 | Quaternion normalize(const Quaternion &q); 51 | Quaternion inverse(const Quaternion &q); 52 | double norm2(const Quaternion &q); 53 | inline std::ostream &operator<< (std::ostream &out, const Quaternion &q) { out << "(" << q.s << ", " << q.v << ")"; return out; } 54 | 55 | struct Transformation 56 | { 57 | Vec3 translation; 58 | double scale; 59 | Quaternion rotation; 60 | Transformation(double factor = 1); 61 | Vec3 apply(const Vec3 &point) const; 62 | Vec3 apply_vec(const Vec3 &vec) const; 63 | Transformation operator+(const Transformation& t) const; 64 | Transformation operator-(const Transformation& t) const; 65 | Transformation operator*(const Transformation& t) const; 66 | Transformation operator*(double scalar) const; 67 | Transformation operator/(double scalar) const; 68 | }; 69 | 70 | Transformation identity(); 71 | Transformation inverse(const Transformation &tr); 72 | inline std::ostream &operator<< (std::ostream &out, const Transformation &t) { out << "(translation: " << t.translation << ", rotation: " << t.rotation << ", scale: " << t.scale << ")"; return out; } 73 | 74 | typedef Spline Motion; 75 | typedef std::pair DTransformation; 76 | 77 | void clean_up_quaternions(Motion &motion); // remove sign flips 78 | 79 | Transformation get_trans(const Motion &motion, double t); 80 | DTransformation get_dtrans(const Motion &motion, double t); 81 | Vec3 apply_dtrans(const DTransformation &dT, const Vec3 &x0, Vec3 *vel = NULL); 82 | Vec3 apply_dtrans_vec(const DTransformation &dT, const Vec3 &v0); 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /arcsim/AdaptiveCloth/winport.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ©2013 The Regents of the University of California 3 | (Regents). All Rights Reserved. Permission to use, copy, modify, and 4 | distribute this software and its documentation for educational, 5 | research, and not-for-profit purposes, without fee and without a 6 | signed licensing agreement, is hereby granted, provided that the 7 | above copyright notice, this paragraph and the following two 8 | paragraphs appear in all copies, modifications, and 9 | distributions. Contact The Office of Technology Licensing, UC 10 | Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, 11 | (510) 643-7201, for commercial licensing opportunities. 12 | 13 | IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, 14 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY 17 | OF SUCH DAMAGE. 18 | 19 | REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING 22 | DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 23 | IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | */ 26 | 27 | #ifndef WINPORT_HPP 28 | #define WINPORT_HPP 29 | // MS Windows bindings, etc 30 | 31 | #if defined(_WIN32) && !defined(__CYGWIN__) 32 | 33 | #pragma warning(disable:4018) // signed/unsigned mismatch 34 | #pragma warning(disable:4244) // conversion from 'double' to 'float', possible loss of data 35 | #pragma warning(disable:4996) // this function or variable may be unsafe 36 | #pragma warning(disable:4251) // class needs to have dll-interface to be used by clients 37 | #pragma warning(disable:4800) // forcing value to bool 'true' or 'false' 38 | #pragma warning(disable:161) // unrecognized #pragma 39 | 40 | #define _USE_MATH_DEFINES // just to have M_PI 41 | #include 42 | 43 | #include 44 | #undef min 45 | #undef max 46 | #include 47 | //#define snprintf _snprintf 48 | 49 | #include 50 | template inline bool isfinite(const T& number) { return boost::math::isfinite(number); } 51 | template inline bool finite(const T& number) { return boost::math::isfinite(number); } 52 | 53 | inline double sqrt(int n) { return sqrt(double(n)); } 54 | 55 | template inline T log2(const T& number) { return log(number)/log(T(2)); } 56 | 57 | extern std::ostream cdbg; 58 | 59 | #endif 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /arcsim/Configurations/crumple-pnas.json: -------------------------------------------------------------------------------- 1 | // Aluminium foil disk crumpled in a shrinking sphere 2 | // Narain et al. 2013, Figure 8 3 | { 4 | "frame_time": 0.01, 5 | "frame_steps": 10, 6 | "duration": 5, 7 | "cloths": [{ 8 | "mesh": "meshes/disk.obj", 9 | "transform": {"scale": 50e-3}, 10 | // "transform": {"translate": [0.5, 0, 0.5]}, 11 | "materials": [{ 12 | "data": "materials/aluminium.json", 13 | "yield_curv": 150 14 | }], 15 | "remeshing": { 16 | "refine_angle": 0.2, 17 | "refine_compression": 10e-6, 18 | "size": [1e-3, 20e-3], 19 | "aspect_min": 0.2 20 | } 21 | }], 22 | "motions": [[ 23 | {"time": 0, "transform": {"scale": 51e-3}}, 24 | {"time": 2.5, "transform": {"scale": 20e-3}}, 25 | {"time": 5, "transform": {"scale": 8.2e-3}} 26 | ]], 27 | "obstacles": [{ 28 | "mesh": "meshes/sphere-inv.obj", 29 | "motion": 0 30 | }], 31 | "magic": {"collision_stiffness": 1e10, "repulsion_thickness": 2.5e-4} 32 | } 33 | -------------------------------------------------------------------------------- /arcsim/Configurations/crumple.json: -------------------------------------------------------------------------------- 1 | // Sheet of letter paper crumpled in a shrinking sphere 2 | // Narain et al. 2013, Figure 1 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 40, 6 | "end_time": 10, 7 | "cloths": [{ 8 | "mesh": "meshes/letter.obj", 9 | "transform": {"translate": [-0.1, 0, -0.15], "rotate": [90, 1,0,0]}, 10 | // "transform": {"translate": [0.5, 0, 0.5]}, 11 | "materials": [{ 12 | "data": "materials/paper.json", 13 | "damping": 1e-3, 14 | "yield_curv": 200, 15 | "weakening": 2 16 | }], 17 | "remeshing": { 18 | "refine_angle": 0.3, 19 | "refine_compression": 1e-4, 20 | "size": [3e-3, 100e-3], 21 | "aspect_min": 0.2 22 | } 23 | }], 24 | "motions": [[ 25 | {"time": 1, "transform": {"scale": 0.2}}, 26 | {"time": 5, "transform": {"scale": 0.05}}, 27 | {"time": 9, "transform": {"scale": 0.2}} 28 | ]], 29 | "obstacles": [{ 30 | "mesh": "meshes/sphere-inv.obj", 31 | "motion": 0 32 | }], 33 | "gravity": [0, 0, -9.8], 34 | "disable": ["strainlimiting"], 35 | "magic": {"collision_stiffness": 1e12} 36 | } 37 | -------------------------------------------------------------------------------- /arcsim/Configurations/crush.json: -------------------------------------------------------------------------------- 1 | // Test for robustness to intersecting obstacles 2 | { 3 | "frame_time": 0.04, 4 | "frame_steps": 8, 5 | "duration": 2, 6 | "cloths": [{ 7 | "mesh": "meshes/square4.obj", 8 | "transform": {"translate": [-0.5,0,0.5], "rotate": [45, 1,0,0]}, 9 | // "transform": {"translate": [0.5, 0, 0.5]}, 10 | "materials": [{ 11 | "data": "materials/gray-interlock.json", 12 | "density_mult": 5, 13 | "stretching_mult": 5, 14 | "bending_mult": 5 15 | }], 16 | "remeshing": { 17 | "refine_angle": 0.15, 18 | "refine_compression": 0.005, 19 | "refine_velocity": 0.5, 20 | "size": [50e-3, 200e-3], 21 | "aspect_min": 0.1 22 | } 23 | }], 24 | "motions": [[ 25 | {"time": 0, "transform": {"scale": 0.5, "translate": [0,-0.55,0]}}, 26 | {"time": 1, "transform": {"scale": 0.5, "translate": [0,-0.45,0]}}, 27 | {"time": 2, "transform": {"scale": 0.5, "translate": [0,-0.55,0]}} 28 | ], [ 29 | {"time": 0, "transform": {"scale": 0.5, "translate": [0,0.55,0]}}, 30 | {"time": 1, "transform": {"scale": 0.5, "translate": [0,0.45,0]}}, 31 | {"time": 2, "transform": {"scale": 0.5, "translate": [0,0.55,0]}} 32 | ]], 33 | "obstacles": [{ 34 | "mesh": "meshes/sphere.obj", 35 | "motion": 0 36 | }, { 37 | "mesh": "meshes/sphere.obj", 38 | "motion": 1 39 | }], 40 | "gravity": [0, 0, -9.8], 41 | "obs_friction": 0, 42 | "magic": {"fixed_high_res_mesh": true} 43 | } 44 | -------------------------------------------------------------------------------- /arcsim/Configurations/crush2.json: -------------------------------------------------------------------------------- 1 | // Test for robustness to initialization inside obstacle 2 | { 3 | "frame_time": 0.04, 4 | "frame_steps": 8, 5 | "duration": 2, 6 | "cloths": [{ 7 | "mesh": "meshes/square4.obj", 8 | "transform": {"translate": [-0.5,-0.1,-0.1], "rotate": [60, 1,0,0]}, 9 | // "transform": {"translate": [0.5, 0, 0.5]}, 10 | "materials": [{ 11 | "data": "materials/gray-interlock.json", 12 | "density_mult": 5, 13 | "stretching_mult": 5, 14 | "bending_mult": 5 15 | }], 16 | "remeshing": { 17 | "refine_angle": 0.15, 18 | "refine_compression": 0.005, 19 | "refine_velocity": 0.5, 20 | "size": [50e-3, 200e-3], 21 | "aspect_min": 0.1 22 | } 23 | }], 24 | "motions": [[ 25 | {"time": 0, "transform": {"scale": 0.5, "translate": [0,-0.45,0]}}, 26 | {"time": 1, "transform": {"scale": 0.5, "translate": [0,-0.55,0]}}, 27 | {"time": 2, "transform": {"scale": 0.5, "translate": [0,-0.45,0]}} 28 | ], [ 29 | {"time": 0, "transform": {"scale": 0.5, "translate": [0,0.45,0]}}, 30 | {"time": 1, "transform": {"scale": 0.5, "translate": [0,0.55,0]}}, 31 | {"time": 2, "transform": {"scale": 0.5, "translate": [0,0.45,0]}} 32 | ]], 33 | "obstacles": [{ 34 | "mesh": "meshes/sphere.obj", 35 | "motion": 0 36 | }, { 37 | "mesh": "meshes/sphere.obj", 38 | "motion": 1 39 | }], 40 | "gravity": [0, 0, -9.8], 41 | "magic": {"fixed_high_res_mesh": true} 42 | } 43 | -------------------------------------------------------------------------------- /arcsim/Configurations/cylinder.json: -------------------------------------------------------------------------------- 1 | // Cylinder subjected to axial compression 2 | // Narain et al. 2013, Figure 3 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 40, 6 | "end_time": 7, 7 | "cloths": [{ 8 | "mesh": "meshes/cylinder.obj", 9 | "materials": [{ 10 | "data": "materials/paper.json", 11 | "yield_curv": 200, 12 | "weakening": 1, 13 | "stretching_mult": 1.0e-2 14 | }], 15 | "remeshing": { 16 | "refine_angle": 0.2, 17 | "refine_compression": 3.0e-4, 18 | "size": [3e-3, 100e-3], 19 | "aspect_min": 0.2 20 | } 21 | }], 22 | "motions": [[ 23 | {"time": 0, "transform": {"translate": [0, 0, 0]}}, 24 | {"time": 5, "transform": {"translate": [0, 0, -0.15]}}, 25 | {"time": 10, "transform": {"translate": [0, 0, 0]}} 26 | ]], 27 | "obstacles": [{ 28 | "mesh": "meshes/square.obj", 29 | "transform": {"translate": [-0.5,-0.5,-2e-3]} 30 | }, { 31 | "mesh": "meshes/square.obj", 32 | "transform": {"translate": [-0.5,0.5,0.218], "rotate": [180, 1,0,0]}, 33 | "motion": 0, 34 | "end_time": 5 35 | }], 36 | "handles": [{ 37 | "type": "circle", 38 | "label": 1, 39 | "circumference": 0.280, 40 | "u": [1,0], 41 | "center": [0, 0, 0], 42 | "axis0": [1,0,0], 43 | "axis1": [0,1,0] 44 | }, { 45 | "type": "circle", 46 | "label": 2, 47 | "motion": 0, 48 | "circumference": 0.280, 49 | "u": [1,0], 50 | "center": [0, 0, 0.216], 51 | "axis0": [1,0,0], 52 | "axis1": [0,1,0], 53 | "end_time": 5 54 | }], 55 | "gravity": [0, 0, -9.8], 56 | "disable": ["strainlimiting"], 57 | "magic": { 58 | "handle_stiffness": 1e6 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /arcsim/Configurations/dart.json: -------------------------------------------------------------------------------- 1 | // "Dart" style paper airplane crashing into a wall 2 | // Narain et al. 2013, Figure 6 3 | { 4 | "frame_time": 0.0004, 5 | "frame_steps": 40, 6 | "end_time": 0.2, 7 | "cloths": [{ 8 | "mesh": "meshes/dart.obj", 9 | "transform": {"rotate": [-2, 1,0,0], "translate": [0,-0.75,0]}, 10 | "velocity": {"linear": [0,15,0]}, 11 | "materials": [{ 12 | "data": "materials/paper.json", 13 | "yield_curv": 200, 14 | "weakening": 0.5 15 | }], 16 | "remeshing": { 17 | "refine_angle": 0.3, 18 | "refine_compression": 2e-4, 19 | "size": [3e-3, 100e-3], 20 | "aspect_min": 0.2 21 | } 22 | }], 23 | "obstacles": [{ 24 | "mesh": "meshes/square.obj", 25 | "transform": {"rotate": [90, 1,0,0], "translate": [-0.5,-0,-0.5]} 26 | }], 27 | "gravity": [0, 0, -9.8], 28 | "disable": ["strainlimiting"], 29 | "magic": { 30 | "preserve_creases": true, 31 | "repulsion_thickness": 0.2e-3, 32 | "collision_stiffness": 1e11 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /arcsim/Configurations/dress-blue.json: -------------------------------------------------------------------------------- 1 | // Dress on female character 2 | // Narain et al. 2012, Figure 10(a) 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 8, 6 | "end_time": 20, 7 | "cloths": [{ 8 | "mesh": "meshes/dress4.obj", 9 | "transform": {"rotate": [90, 1, 0, 0]}, 10 | "materials": [{"data": "materials/navy-sparkle-sweat.json", "bending_mult": 0.1}], 11 | "remeshing": { 12 | "refine_angle": 0.3, 13 | "refine_compression": 0.01, 14 | "refine_velocity": 0.5, 15 | "size": [10e-3, 200e-3], 16 | "aspect_min": 0.2 17 | } 18 | }], 19 | "motions": { 20 | "motfile": "meshes/dance-paused.mot", 21 | "fps": 30, 22 | "transform": { 23 | "translate": [0, 0, -1], 24 | "rotate": [-90, 0, 0, 1] 25 | } 26 | }, 27 | "obstacles": "meshes/female-objs/body%04d.obj", 28 | "gravity": [0, 0, -9.8], 29 | "magic": {"repulsion_thickness": 5e-3, "collision_stiffness": 1e6} 30 | } 31 | -------------------------------------------------------------------------------- /arcsim/Configurations/dress-yellow.json: -------------------------------------------------------------------------------- 1 | // Dress on female character 2 | // Narain et al. 2012, Figure 10(b) 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 8, 6 | "end_time": 20, 7 | "cloths": [{ 8 | "mesh": "meshes/dress3.obj", 9 | "transform": { 10 | "translate": [0, 0.02, -0.84], 11 | "rotate": [-90, 0, 0, 1] 12 | }, 13 | "materials": [{"data": "materials/gray-interlock.json"}], 14 | "remeshing": { 15 | "refine_angle": 0.3, 16 | "refine_compression": 0.01, 17 | "refine_velocity": 0.5, 18 | "size": [10e-3, 200e-3], 19 | "aspect_min": 0.2 20 | } 21 | }], 22 | "motions": { 23 | "motfile": "meshes/dance-paused.mot", 24 | "fps": 30, 25 | "transform": { 26 | "translate": [0, 0, -1], 27 | "rotate": [-90, 0, 0, 1] 28 | } 29 | }, 30 | "obstacles": "meshes/female-objs/body%04d.obj", 31 | "gravity": [0, 0, -9.8], 32 | "magic": {"repulsion_thickness": 5e-3, "collision_stiffness": 1e6} 33 | } 34 | -------------------------------------------------------------------------------- /arcsim/Configurations/flag.json: -------------------------------------------------------------------------------- 1 | // Flag blowing in the wind 2 | // Narain et al. 2012, Figure 8 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 8, 6 | "duration": 20, 7 | "cloths": [{ 8 | "mesh": "meshes/flag.obj", 9 | "transform": {"translate": [0, 0, 0], "rotate": [120, 1, 1, 1]}, 10 | "materials": [{ 11 | "data": "materials/camel-ponte-roma.json", 12 | "thicken": 2, 13 | "strain_limits": [0.95, 1.05] 14 | }], 15 | "remeshing": { 16 | "refine_angle": 0.3, 17 | "refine_compression": 0.01, 18 | "refine_velocity": 1, 19 | "size": [20e-3, 500e-3], 20 | "aspect_min": 0.2 21 | } 22 | }], 23 | "handles": [{"nodes": [0,3]}], 24 | "gravity": [0, 0, -9.8], 25 | "wind": {"velocity": [10, 0, 0]}, 26 | "magic": {"repulsion_thickness": 10e-3, "collision_stiffness": 1e6} 27 | } 28 | -------------------------------------------------------------------------------- /arcsim/Configurations/fold.json: -------------------------------------------------------------------------------- 1 | // Sheet of letter paper folded twice 2 | // Narain et al. 2013, Figure 5 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 40, 6 | "end_time": 14, 7 | "cloths": [{ 8 | "mesh": "meshes/letter-with-midpoints.obj", 9 | "transform": {"translate": [-0.1, -0.15, 1e-3]}, 10 | // "transform": {"translate": [0.5, 0, 0.5]}, 11 | "materials": [{ 12 | "data": "materials/paper.json", 13 | "yield_curv": 200, 14 | "weakening": 1 15 | }], 16 | "remeshing": { 17 | "refine_angle": 0.2, 18 | "refine_compression": 0.1e-3, 19 | "size": [3e-3, 100e-3], 20 | "aspect_min": 0.2 21 | } 22 | }], 23 | "motions": [[ 24 | {"time": 0, "transform": {"translate": [0, 0, 0]}}, 25 | {"time": 1, "transform": {"translate": [-0.108, -0.140, 0.160]}, 26 | "velocity": {"translate": [-0.32, -0.42, 0]} 27 | }, 28 | {"time": 2, "transform": {"translate": [-0.216, -0.280, 1e-3]}} 29 | ], [ 30 | {"time": 2, "transform": {"translate": [0, 0, 0]}}, 31 | {"time": 6, "transform": {"translate": [0.3,0.6,0]}} 32 | ], [ 33 | {"time": 5, "transform": {"translate": [0, 0, 0]}}, 34 | {"time": 6, "transform": {"translate": [-0.14, 0.100, 0.160]}, 35 | "velocity": {"translate": [-0.42, 0.3, 0]} 36 | }, 37 | {"time": 7, "transform": {"translate": [-0.280, 0.200, 3e-3]}} 38 | ], [ 39 | {"time": 8, "transform": {"translate": [0, 0, 0]}}, 40 | {"time": 12, "transform": {"translate": [0.3,-0.6,0]}} 41 | ], [ 42 | {"time": 5, "transform": {"translate": [0,0,0]}}, 43 | {"time": 6, "transform": {"translate": [0,0,-5e-3]}} 44 | ]], 45 | "handles": [ 46 | {"nodes": [0], "end_time": 9, "fade_time": 1}, 47 | {"nodes": [1], "motion": 2, "start_time": 5, "end_time": 11, "fade_time": 0.5}, 48 | {"nodes": [2], "motion": 0, "end_time": 9, "fade_time": 1}, 49 | {"nodes": [3], "motion": 4, "start_time": 5, "end_time": 11, "fade_time": 0.5}, 50 | {"nodes": [8], "start_time": 5, "end_time": 9, "fade_time": 1} 51 | ], 52 | "obstacles": [{ 53 | "mesh": "meshes/square.obj", 54 | "transform": {"translate": [-0.5,-0.5,0]} 55 | }, { 56 | "mesh": "meshes/roller.obj", 57 | "transform": {"translate": [-0.15,-0.3,0.057], "rotate": [90, 1,2,0], "scale": 0.05}, 58 | "motion": 1 59 | }, { 60 | "mesh": "meshes/roller.obj", 61 | "transform": {"translate": [-0.3,0.3,0.060], "rotate": [90, 1,-2,0], "scale": 0.05}, 62 | "motion": 3 63 | }], 64 | "gravity": [0, 0, -9.8], 65 | // "obs_friction": 0.2, 66 | "disable": ["strainlimiting"], 67 | "magic": {"collision_stiffness": 1e11, "handle_stiffness": 1e4} 68 | } 69 | -------------------------------------------------------------------------------- /arcsim/Configurations/karate.json: -------------------------------------------------------------------------------- 1 | // Layered clothing on male character performing martial arts moves 2 | // Narain et al. 2012, Figure 1 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 8, 6 | "end_time": 20, 7 | "cloths": [{ 8 | "mesh": "meshes/pants3.obj", 9 | "transform": {"translate": [0, 0, 0.5]}, 10 | "materials": [{ 11 | "data": "materials/11oz-black-denim.json", 12 | "strain_limits": [0.95, 1.05] 13 | }], 14 | "remeshing": { 15 | "refine_angle": 0.3, 16 | "refine_compression": 0.01, 17 | "refine_velocity": 0.5, 18 | "size": [10e-3, 200e-3], 19 | "aspect_min": 0.2 20 | } 21 | }, { 22 | "mesh": "meshes/tshirt.obj", 23 | "transform": {"translate": [0, 0, 0.5]}, 24 | "materials": [{ 25 | "data": "materials/gray-interlock.json", 26 | "strain_limits": [0.95, 1.05] 27 | }], 28 | "remeshing": { 29 | "refine_angle": 0.3, 30 | "refine_compression": 0.01, 31 | "refine_velocity": 0.5, 32 | "size": [10e-3, 200e-3], 33 | "aspect_min": 0.2 34 | } 35 | }, { 36 | "mesh": "meshes/jacket.obj", 37 | "transform": {"translate": [0, 0, 0.5]}, 38 | "materials": [{ 39 | "data": "materials/camel-ponte-roma.json", 40 | "strain_limits": [0.95, 1.05], 41 | "thicken": 2 42 | }], 43 | "remeshing": { 44 | "refine_angle": 0.3, 45 | "refine_compression": 0.01, 46 | "refine_velocity": 0.5, 47 | "size": [10e-3, 200e-3], 48 | "aspect_min": 0.2 49 | } 50 | }], 51 | "handles": [{ 52 | "cloth": 0, 53 | "nodes": [4, 5, 7, 8, 9, 19, 21, 22, 54 | 41, 93, 94, 95, 100, 103, 104, 105], 55 | "motion": 7, 56 | "start_time": 0.08 57 | }], 58 | "obstacles": "meshes/guy_shrunk/body%04d.obj", 59 | "motions": { 60 | "motfile": "meshes/karate-smooth.mot", 61 | "fps": 120, 62 | "transform": { 63 | "translate": [3, -0.85, -0.7], 64 | "rotate": [180, 0, 0, 1] 65 | } 66 | }, 67 | "gravity": [0, 0, -9.8], 68 | "magic": {"repulsion_thickness": 5e-3, "collision_stiffness": 1e6} 69 | } 70 | -------------------------------------------------------------------------------- /arcsim/Configurations/pcb.json: -------------------------------------------------------------------------------- 1 | // Flag blowing in the wind 2 | // Narain et al. 2012, Figure 8 3 | // Narain et al. 2012, Figure 2(b) 4 | { 5 | "frame_time": 0.04, 6 | "frame_steps": 4, 7 | "end_time": 1000, 8 | "cloths": [{ 9 | "mesh": "meshes/new_plane.obj", 10 | "transform": {"scale":1,"translate": [0, 0, 0]}, 11 | "materials": [{"data": "materials/PcbBending.json", 12 | "thicken": 2}], 13 | "remeshing": { 14 | "refine_angle": 0.3, 15 | "refine_compression": 0.1, 16 | "refine_velocity": 1, 17 | "size": [1e-3, 10e-3], 18 | "aspect_min": 0.2 19 | } 20 | }], 21 | "obstacles": [{ 22 | "mesh": "meshes/new_clinder.obj" 23 | }], 24 | "gravity": [0, 0, -9.8], 25 | "magic": {"repulsion_thickness": 3e-3, "collision_stiffness": 1e5, "use_principal_curvature_based_bending": true} 26 | } -------------------------------------------------------------------------------- /arcsim/Configurations/pcb_flag.json: -------------------------------------------------------------------------------- 1 | // Flag blowing in the wind 2 | // Narain et al. 2012, Figure 8 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 8, 6 | "duration": 20, 7 | "cloths": [{ 8 | "mesh": "meshes/flag.obj", 9 | "transform": {"translate": [0, 0, 0], "rotate": [120, 1, 1, 1]}, 10 | "materials": [{ 11 | "data": "materials/PcbBending.json", 12 | "thicken": 2, 13 | "strain_limits": [0.95, 1.05] 14 | }], 15 | "remeshing": { 16 | "refine_angle": 0.3, 17 | "refine_compression": 0.01, 18 | "refine_velocity": 1, 19 | "size": [20e-3, 500e-3], 20 | "aspect_min": 0.2 21 | } 22 | }], 23 | "handles": [{"nodes": [0,3]}], 24 | "gravity": [0, 0, -9.8], 25 | "wind": {"velocity": [10, 0, 0]}, 26 | "magic": {"repulsion_thickness": 10e-3, "collision_stiffness": 1e6, "use_principal_curvature_based_bending": true } 27 | } 28 | -------------------------------------------------------------------------------- /arcsim/Configurations/sleeve.json: -------------------------------------------------------------------------------- 1 | // Test for wrinkle anticipation, diamond buckling, coarsening 2 | // Narain et al. 2012, Figure 9 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 4, 6 | "end_time": 15, 7 | "cloths": [{ 8 | "mesh": "meshes/sleeve.obj", 9 | "transform": {"translate": [-0.5, -0.125, -0.125]}, 10 | // "transform": {"translate": [0.5, 0, 0.5]}, 11 | "materials": [{"data": "materials/ivory-rib-knit.json"}], 12 | "remeshing": { 13 | "refine_angle": 0.2, 14 | "refine_compression": 0.005, 15 | "refine_velocity": 0.5, 16 | "size": [10e-3, 200e-3], 17 | "aspect_min": 0.2 18 | } 19 | }], 20 | "motions": [[ 21 | {"time": 1, "transform": {"rotate": [0, 0, 1, 0]}}, 22 | {"time": 3, "transform": {"rotate": [-10, 0, 1, 0]}}, 23 | {"time": 5, "transform": {"rotate": [0, 0, 1, 0]}}, 24 | {"time": 7, "transform": {"rotate": [-10, 0, 1, 0]}}, 25 | {"time": 9, "transform": {"rotate": [0, 0, 1, 0]}}, 26 | {"time": 11, "transform": {"rotate": [-10, 0, 1, 0]}}, 27 | {"time": 13, "transform": {"rotate": [0, 0, 1, 0]}} 28 | ], [ 29 | {"time": 1, "transform": {"rotate": [0, 0, 1, 0]}}, 30 | {"time": 3, "transform": {"rotate": [10, 0, 1, 0]}}, 31 | {"time": 5, "transform": {"rotate": [0, 0, 1, 0]}}, 32 | {"time": 7, "transform": {"rotate": [10, 0, 1, 0]}}, 33 | {"time": 9, "transform": {"rotate": [0, 0, 1, 0]}}, 34 | {"time": 11, "transform": {"rotate": [10, 0, 1, 0]}}, 35 | {"time": 13, "transform": {"rotate": [0, 0, 1, 0]}} 36 | ]], 37 | "obstacles": [{ 38 | "mesh": "meshes/pole.obj", 39 | "transform": {"scale": 0.12}, 40 | "motion": 0 41 | }, { 42 | "mesh": "meshes/pole.obj", 43 | "transform": {"scale": 0.12, "rotate": [180, 0, 1, 0]}, 44 | "motion": 1 45 | }], 46 | "gravity": [0, 0, -9.8], 47 | "magic": {"repulsion_thickness": 5e-3, "collision_stiffness": 1e6} 48 | } 49 | -------------------------------------------------------------------------------- /arcsim/Configurations/sphere.json: -------------------------------------------------------------------------------- 1 | // Square sheet of cloth interacting with moving sphere 2 | // Narain et al. 2012, Figure 2(b) 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 8, 6 | "end_time": 10, 7 | "cloths": [{ 8 | "mesh": "meshes/square4.obj", 9 | "transform": {"translate": [-0.5, -1, 0.5]}, 10 | // "transform": {"translate": [0.5, 0, 0.5]}, 11 | "materials": [{"data": "materials/gray-interlock.json", 12 | "thicken": 2}], 13 | "remeshing": { 14 | "refine_angle": 0.3, 15 | "refine_compression": 0.005, 16 | "refine_velocity": 0.5, 17 | "size": [10e-3, 200e-3], 18 | "aspect_min": 0.2 19 | } 20 | }], 21 | "handles": [{"nodes": [2,3], "end_time": 7}], 22 | "motions": [[ 23 | {"time": 0, "transform": {"scale": 0.1, "translate": [0,0,0]}}, 24 | {"time": 1, "transform": {"scale": 0.1, "translate": [0,0,0]}}, 25 | {"time": 2, "transform": {"scale": 0.1, "translate": [0,0,0]}}, 26 | {"time": 3, "transform": {"scale": 0.1, "translate": [0,-1.5,0]}}, 27 | {"time": 4, "transform": {"scale": 0.1, "translate": [0,0,0]}}, 28 | {"time": 5, "transform": {"scale": 0.1, "translate": [0,1.5,0]}}, 29 | {"time": 6, "transform": {"scale": 0.1, "translate": [0,0,0]}}, 30 | {"time": 7, "transform": {"scale": 0.1, "translate": [0,-0.4,0]}} 31 | ]], 32 | "obstacles": [{ 33 | "mesh": "meshes/sphere.obj", 34 | "motion": 0 35 | }], 36 | "gravity": [0, 0, -9.8], 37 | "magic": {"repulsion_thickness": 5e-3, "collision_stiffness": 1e6} 38 | } 39 | -------------------------------------------------------------------------------- /arcsim/Configurations/square-pop.json: -------------------------------------------------------------------------------- 1 | // Test of popping/jittering artifacts without post-remeshing projection 2 | { 3 | "frame_time": 0.04, 4 | "frame_steps": 8, 5 | "end_time": 13, 6 | "cloths": [{ 7 | "mesh": "meshes/square4.obj", 8 | "transform": {"translate": [-0.5, -0.5, 0]}, 9 | "materials": [{ 10 | "data": "materials/paper.json" 11 | }], 12 | "remeshing": { 13 | "refine_angle": 0.5, 14 | "refine_compression": 0.5e-3, 15 | "size": [10e-3, 200e-3], 16 | "aspect_min": 0.2 17 | } 18 | }], 19 | "motions": [[ 20 | {"time": 1, "transform": {"translate": [0,0,0]}}, 21 | {"time": 6, "transform": {"translate": [0.45,0,0]}, 22 | "velocity": {"translate": [0,0,0]}}, 23 | {"time": 7, "transform": {"translate": [0.45,0,0]}, 24 | "velocity": {"translate": [0,0,0]}}, 25 | {"time": 12, "transform": {"translate": [0,0,0]}} 26 | ], [ 27 | {"time": 1, "transform": {"translate": [0,0,0]}}, 28 | {"time": 6, "transform": {"translate": [-0.45,0,0]}, 29 | "velocity": {"translate": [0,0,0]}}, 30 | {"time": 7, "transform": {"translate": [-0.45,0,0]}, 31 | "velocity": {"translate": [0,0,0]}}, 32 | {"time": 12, "transform": {"translate": [0,0,0]}} 33 | ]], 34 | // "motions": [[ 35 | // {"time": 1, "transform": {"translate": [0,0,0]}}, 36 | // {"time": 5, "transform": {"translate": [0.45,0,0]}}, 37 | // {"time": 9, "transform": {"translate": [0,0,0]}} 38 | // ], [ 39 | // {"time": 1, "transform": {"translate": [0,0,0]}}, 40 | // {"time": 5, "transform": {"translate": [-0.45,0,0]}}, 41 | // {"time": 9, "transform": {"translate": [0,0,0]}} 42 | // ]], 43 | "handles": [ 44 | {"nodes": [0,3], "motion": 0}, 45 | {"nodes": [1,2], "motion": 1} 46 | ], 47 | "gravity": [0, 0, -9.8], 48 | "disable": ["strainlimiting", "popfilter"] 49 | } 50 | -------------------------------------------------------------------------------- /arcsim/Configurations/square.json: -------------------------------------------------------------------------------- 1 | // Test of lack of popping/jittering artifacts due to post-remeshing projection 2 | { 3 | "frame_time": 0.04, 4 | "frame_steps": 8, 5 | "end_time": 13, 6 | "cloths": [{ 7 | "mesh": "meshes/square4.obj", 8 | "transform": {"translate": [-0.5, -0.5, 0]}, 9 | "materials": [{ 10 | "data": "materials/paper.json" 11 | }], 12 | "remeshing": { 13 | "refine_angle": 0.5, 14 | "refine_compression": 0.5e-3, 15 | "size": [10e-3, 200e-3], 16 | "aspect_min": 0.2 17 | } 18 | }], 19 | "motions": [[ 20 | {"time": 1, "transform": {"translate": [0,0,0]}}, 21 | {"time": 6, "transform": {"translate": [0.45,0,0]}, 22 | "velocity": {"translate": [0,0,0]}}, 23 | {"time": 7, "transform": {"translate": [0.45,0,0]}, 24 | "velocity": {"translate": [0,0,0]}}, 25 | {"time": 12, "transform": {"translate": [0,0,0]}} 26 | ], [ 27 | {"time": 1, "transform": {"translate": [0,0,0]}}, 28 | {"time": 6, "transform": {"translate": [-0.45,0,0]}, 29 | "velocity": {"translate": [0,0,0]}}, 30 | {"time": 7, "transform": {"translate": [-0.45,0,0]}, 31 | "velocity": {"translate": [0,0,0]}}, 32 | {"time": 12, "transform": {"translate": [0,0,0]}} 33 | ]], 34 | // "motions": [[ 35 | // {"time": 1, "transform": {"translate": [0,0,0]}}, 36 | // {"time": 5, "transform": {"translate": [0.45,0,0]}}, 37 | // {"time": 9, "transform": {"translate": [0,0,0]}} 38 | // ], [ 39 | // {"time": 1, "transform": {"translate": [0,0,0]}}, 40 | // {"time": 5, "transform": {"translate": [-0.45,0,0]}}, 41 | // {"time": 9, "transform": {"translate": [0,0,0]}} 42 | // ]], 43 | "handles": [ 44 | {"nodes": [0,3], "motion": 0}, 45 | {"nodes": [1,2], "motion": 1} 46 | ], 47 | "gravity": [0, 0, -9.8], 48 | "disable": ["strainlimiting"] 49 | } 50 | -------------------------------------------------------------------------------- /arcsim/Configurations/tshirt.json: -------------------------------------------------------------------------------- 1 | // Stuffing a T-shirt into a small box 2 | // Narain et al. 2013, Figure 7 3 | { 4 | "frame_time": 0.04, 5 | "frame_steps": 8, 6 | "end_time": 8.5, 7 | "cloths": [{ 8 | "mesh": "meshes/tshirt.obj", 9 | "transform": {"translate": [0,0,0.5]}, 10 | "materials": [{ 11 | "data": "materials/gray-interlock.json", 12 | "yield_curv": 200, 13 | "damping": 1e-3 14 | }], 15 | "remeshing": { 16 | "refine_angle": 0.3, 17 | "refine_compression": 0.01, 18 | "refine_velocity": 0.5, 19 | "size": [10e-3, 200e-3], 20 | "aspect_min": 0.2 21 | } 22 | }], 23 | "motions": [[ 24 | {"time": 4.5}, 25 | {"time": 5.5, "transform": {"translate": [-0.19,0,0.792], "scale": 0}} 26 | ], [ 27 | {"time": 4.5}, 28 | {"time": 5.5, "transform": {"translate": [0.20,0,0.786], "scale": 0}} 29 | ], [ 30 | {"time": 1.5, "transform": {"translate": [0,0,0]}}, 31 | {"time": 3.0, "transform": {"translate": [0,0.9,0]}, 32 | "velocity": {"translate": [0,0,0]}}, 33 | {"time": 3.5, "transform": {"translate": [0,0.9,0]}, 34 | "velocity": {"translate": [0,0,0]}}, 35 | {"time": 4.5, "transform": {"translate": [0,0,0]}} 36 | ], [ 37 | {"time": 1.5, "transform": {"translate": [0,0,0]}}, 38 | {"time": 3.0, "transform": {"translate": [0,-0.9,0]}, 39 | "velocity": {"translate": [0,0,0]}}, 40 | {"time": 3.5, "transform": {"translate": [0,-0.9,0]}, 41 | "velocity": {"translate": [0,0,0]}}, 42 | {"time": 4.5, "transform": {"translate": [0,0,0]}} 43 | ], [ 44 | {"time": 1.5, "transform": {"translate": [0,0,0]}}, 45 | {"time": 3.0, "transform": {"translate": [0.9,0,0]}, 46 | "velocity": {"translate": [0,0,0]}}, 47 | {"time": 3.5, "transform": {"translate": [0.9,0,0]}, 48 | "velocity": {"translate": [0,0,0]}}, 49 | {"time": 4.5, "transform": {"translate": [0,0,0]}} 50 | ], [ 51 | {"time": 1.5, "transform": {"translate": [0,0,0]}}, 52 | {"time": 3.0, "transform": {"translate": [-0.9,0,0]}, 53 | "velocity": {"translate": [0,0,0]}}, 54 | {"time": 3.5, "transform": {"translate": [-0.9,0,0]}, 55 | "velocity": {"translate": [0,0,0]}}, 56 | {"time": 4.5, "transform": {"translate": [0,0,0]}} 57 | ], [ 58 | {"time": 1.5, "transform": {"translate": [0,0,0]}}, 59 | {"time": 3.0, "transform": {"translate": [0,0,-0.9]}, 60 | "velocity": {"translate": [0,0,0]}}, 61 | {"time": 3.5, "transform": {"translate": [0,0,-0.9]}, 62 | "velocity": {"translate": [0,0,0]}}, 63 | {"time": 4.5, "transform": {"translate": [0,0.0,0]}} 64 | ]], 65 | "obstacles": [{ 66 | "mesh": "meshes/square.obj", 67 | "transform": {"translate": [-1,-1,0], "scale": 2} 68 | }, { 69 | "mesh": "meshes/square.obj", 70 | "transform": {"translate": [-0.5,-1,0.5], "rotate": [-90, 1,0,0]}, 71 | "motion": 2 72 | }, { 73 | "mesh": "meshes/square.obj", 74 | "transform": {"translate": [-0.5,1,-0.5], "rotate": [90, 1,0,0]}, 75 | "motion": 3 76 | }, { 77 | "mesh": "meshes/square.obj", 78 | "transform": {"translate": [-1,-0.5,0.5], "rotate": [90, 0,1,0]}, 79 | "motion": 4 80 | }, { 81 | "mesh": "meshes/square.obj", 82 | "transform": {"translate": [1,-0.5,-0.5], "rotate": [-90, 0,1,0]}, 83 | "motion": 5 84 | }, { 85 | "mesh": "meshes/square.obj", 86 | "transform": {"translate": [-0.5,0.5,1.0], "rotate": [180, 1,0,0]}, 87 | "motion": 6, 88 | "start_time": 1.5, 89 | "end_time": 4 90 | }], 91 | "handles": [ 92 | {"nodes": [29, 91], "end_time": 1}, 93 | {"nodes": [29], "motion": 0, "start_time": 4.5}, 94 | {"nodes": [91], "motion": 1, "start_time": 4.5} 95 | ], 96 | "gravity": [0, 0, -9.8], 97 | "disable": ["popfilter"], 98 | "magic": {"repulsion_thickness": 5e-3, "collision_stiffness": 1e6} 99 | } 100 | -------------------------------------------------------------------------------- /arcsim/Materials/11oz-black-denim.json: -------------------------------------------------------------------------------- 1 | { 2 | "density": 0.324, 3 | "stretching": [ 4 | [205.352005, 10.234077, 1013.88629, 53.387184], 5 | [232.027634, 40.646339, 1052.84289, 64.980499], 6 | [224.592209, 40.384563, 1054.43444, 67.184807], 7 | [225.951050, 62.095657, 1059.59741, 83.992020], 8 | [226.039566, 40.502792, 1058.27771, 75.118423], 9 | [225.767487, 40.917892, 1051.55712, 71.810631] 10 | ], 11 | "bending": [ 12 | [64.196457e-6, 60.286175e-6, 60.943428e-6, 62.433697e-6, 19.824701e-6], 13 | [73.384567e-6, 59.671982e-6, 61.080757e-6, 68.242569e-6, 36.033474e-6], 14 | [96.951576e-6, 107.848228e-6, 113.060738e-6, 120.569740e-6, 79.781021e-6] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /arcsim/Materials/PcbBending.json: -------------------------------------------------------------------------------- 1 | // thickness: h = 0.1e-3 m 2 | // elastic modulus E = 5 GPa = 5 GN/m^2 3 | // stretching stiffness = Eh = 0.5 MN/m 4 | // bending stiffness ~= E(h^3)/12 = 0.4 mNm 5 | { 6 | "density": 0.3, 7 | "stretching": [ 8 | [0.1e3, 0, 0.1e3, 0.1e3], 9 | [0.1e3, 0, 0.1e3, 0.1e3], 10 | [0.1e3, 0, 0.1e3, 0.1e3], 11 | [0.1e3, 0, 0.1e3, 0.1e3], 12 | [0.1e3, 0, 0.1e3, 0.1e3], 13 | [0.1e3, 0, 0.1e3, 0.1e3] 14 | ], 15 | "bending": [ 16 | [0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3], 17 | [0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3], 18 | [0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3] 19 | ], 20 | "pcb_bending_weft": [5e-4, 0.0], 21 | "pcb_bending_warp": [1e-5, 0.0], 22 | "pcb_bending_bias": [3e-5, 0.0] 23 | } -------------------------------------------------------------------------------- /arcsim/Materials/aluminium.json: -------------------------------------------------------------------------------- 1 | // thickness: h = 25.4e-6 m 2 | // elastic modulus E = 70 GPa = 70e9 N/m^2 3 | // stretching stiffness = E h = 1.8e6 N/m 4 | // bending stiffness ~= E (h^3) / 12 = 96e-6 mNm 5 | // density = 2.8 g/cc = 2.8e3 kg/m^3 6 | // yield strength ~= 350 MPa => yield strain ~= 5e-3 => yield curvature ~= 400 7 | { 8 | "density": 0.071, 9 | "stretching": [ 10 | [1.8e6, 0, 1.8e6, 1.8e6], 11 | [1.8e6, 0, 1.8e6, 1.8e6], 12 | [1.8e6, 0, 1.8e6, 1.8e6], 13 | [1.8e6, 0, 1.8e6, 1.8e6], 14 | [1.8e6, 0, 1.8e6, 1.8e6], 15 | [1.8e6, 0, 1.8e6, 1.8e6] 16 | ], 17 | "bending": [ 18 | [96e-6, 96e-6, 96e-6, 96e-6, 96e-6], 19 | [96e-6, 96e-6, 96e-6, 96e-6, 96e-6], 20 | [96e-6, 96e-6, 96e-6, 96e-6, 96e-6] 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /arcsim/Materials/camel-ponte-roma.json: -------------------------------------------------------------------------------- 1 | { 2 | "density": 0.284, 3 | "stretching": [ 4 | [31.146198, -12.802702, 44.028667, 31.896357], 5 | [78.707756, 26.754574, 268.680725, 27.743423], 6 | [67.368431, 77.767944, 182.273407, -14.661531], 7 | [113.367035, 54.802021, 175.126572, 44.657330], 8 | [144.294830, 111.404854, 138.422150, -29.861851], 9 | [143.933365, 49.654823, 191.777588, 39.491055] 10 | ], 11 | "bending": [ 12 | [36.348366e-6, 49.585537e-6, 45.744080e-6, 47.413387e-6, 20.726685e-6], 13 | [33.013252e-6, 29.744385e-6, 35.103642e-6, 34.041019e-6, 14.439938e-6], 14 | [37.157593e-6, 34.107452e-6, 33.229435e-6, 34.685535e-6, 10.439938e-6] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /arcsim/Materials/gray-interlock.json: -------------------------------------------------------------------------------- 1 | { 2 | "density": 0.187, 3 | "stretching": [ 4 | [16.593832, -14.695990, 34.477123, 36.860302], 5 | [46.364765, 53.694656, 261.013855, -29.691301], 6 | [49.285110, 87.596100, 206.373993, 22.768457], 7 | [123.989220, 105.181770, 365.966217, 44.217571], 8 | [139.686325, 73.592560, 413.553162, -174.43853], 9 | [127.443810, 85.848587, 405.872833, 32.238411] 10 | ], 11 | "bending": [ 12 | [23.191698e-6, 32.932217e-6, 34.406498e-6, 39.014420e-6, 23.382786e-6], 13 | [24.749964e-6, 18.651314e-6, 16.370552e-6, 25.095791e-6, 8.860165e-6], 14 | [14.267624e-6, 7.052906e-6, 14.515154e-6, 24.665127e-6, 19.383726e-6] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /arcsim/Materials/ivory-rib-knit.json: -------------------------------------------------------------------------------- 1 | { 2 | "density": 0.276, 3 | "stretching": [ 4 | [42.871021, -0.234556, 65.166023, 83.175644], 5 | [52.422512, 7.219094, 245.337158, -31.129513], 6 | [29.482058, -5.146112, 127.130753, 13.068157], 7 | [91.209549, 4.940307, 109.746452, 27.609430], 8 | [48.973385, -0.967226, 147.696823, -49.282963], 9 | [105.649139, 0.416488, 254.593491, 3.472504] 10 | ], 11 | "bending": [ 12 | [46.237591e-6, 63.086697e-6, 83.192772e-6, 97.574425e-6, 80.726685e-6], 13 | [30.015930e-6, 30.097424e-6, 30.172081e-6, 30.648300e-6, 24.726685e-6], 14 | [32.243889e-6, 37.341282e-6, 38.817448e-6, 39.812527e-6, 30.437820e-6] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /arcsim/Materials/navy-sparkle-sweat.json: -------------------------------------------------------------------------------- 1 | { 2 | "density": 0.224, 3 | "stretching": [ 4 | [12.486332, -19.875324, 3.272434, 17.616289], 5 | [32.172089, 56.012760, 283.466370, -2.438436], 6 | [48.565407, 94.126335, 180.101227, 4.439080], 7 | [77.093796, 2.958664, 91.251160, 6.107700], 8 | [126.205986, 84.471718, 305.131531, 38.495132], 9 | [92.343170, 117.527084, 243.264908, 47.338436] 10 | ], 11 | "bending": [ 12 | [59.469658e-6, 37.500004e-6, 35.787308e-6, 35.737106e-6, 21.033506e-6], 13 | [40.072277e-6, 37.446949e-6, 35.206612e-6, 24.871773e-6, 9.033506e-6], 14 | [45.625023e-6, 39.520981e-6, 30.734119e-6, 23.301662e-6, 13.033506e-6] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /arcsim/Materials/paper.json: -------------------------------------------------------------------------------- 1 | // thickness: h = 0.1e-3 m 2 | // elastic modulus E = 5 GPa = 5 GN/m^2 3 | // stretching stiffness = Eh = 0.5 MN/m 4 | // bending stiffness ~= E(h^3)/12 = 0.4 mNm 5 | { 6 | "density": 0.1, 7 | "stretching": [ 8 | [0.5e6, 0, 0.5e6, 0.5e6], 9 | [0.5e6, 0, 0.5e6, 0.5e6], 10 | [0.5e6, 0, 0.5e6, 0.5e6], 11 | [0.5e6, 0, 0.5e6, 0.5e6], 12 | [0.5e6, 0, 0.5e6, 0.5e6], 13 | [0.5e6, 0, 0.5e6, 0.5e6] 14 | ], 15 | "bending": [ 16 | [0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3], 17 | [0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3], 18 | [0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3, 0.4e-3] 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /arcsim/Materials/pink-ribbon-brown.json: -------------------------------------------------------------------------------- 1 | { 2 | "density": 0.228, 3 | "stretching": [ 4 | [151.503906, 106.028160, 244.830673, 30.250183], 5 | [164.124344, 33.689709, 268.195221, 30.074625], 6 | [152.584641, 107.251373, 210.614838, -62.760571], 7 | [209.604172, 175.223465, 220.198120, 129.643188], 8 | [98.879021, 107.085518, 326.209442, 44.475986], 9 | [96.805817, 54.626881, 359.792633, 30.340616] 10 | ], 11 | "bending": [ 12 | [117.070122e-6, 202.682922e-6, 298.615936e-6, 244.588867e-6, 238.437820e-6], 13 | [87.509773e-6, 36.396919e-6, 103.628098e-6, 91.630119e-6, 97.175949e-6], 14 | [59.774277e-6, 59.260632e-6, 64.199661e-6, 55.017326e-6, 59.221714e-6] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /arcsim/Materials/royal-target.json: -------------------------------------------------------------------------------- 1 | { 2 | "density": 0.220, 3 | "stretching": [ 4 | [2016.55456, 9.170511, 2034.97644, 104.759674], 5 | [2109.51684, 38.604588, 2173.93969, 19.129177], 6 | [2109.78002, 60.165310, 2155.51367, 27.817890], 7 | [2110.33349, 30.987429, 2135.07910, 121.482445], 8 | [2109.16015, 72.393326, 2124.13525, 40.810982], 9 | [2109.52612, 63.424015, 2152.73852, 39.885654] 10 | ], 11 | "bending": [ 12 | [125.409805e-6, 167.284561e-6, 215.412750e-6, 215.090790e-6, 223.861038e-6], 13 | [107.997696e-6, 120.583267e-6, 144.141678e-6, 140.606689e-6, 153.048309e-6], 14 | [125.409805e-6, 167.284561e-6, 215.412750e-6, 215.090790e-6, 227.861038e-6] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /arcsim/Materials/tango-red-jet-set.json: -------------------------------------------------------------------------------- 1 | { 2 | "density": 0.113, 3 | "stretching": [ 4 | [43.067627, 54.373299, 171.424835, 14.314700], 5 | [75.151695, 82.195221, 236.163773, -7.230383], 6 | [57.548206, 89.637825, 224.553848, 3.932043], 7 | [107.244377, 124.801788, 364.583557, 41.386868], 8 | [178.734039, 178.488907, 371.764618, -30.898058], 9 | [227.028687, -21.865427, 404.867188, 62.636021] 10 | ], 11 | "bending": [ 12 | [14.293814e-6, 8.949391e-6, 30.011126e-6, 36.081490e-6, 18.363136e-6], 13 | [21.951700e-6, 22.446325e-6, 18.408735e-6, 19.598495e-6, 12.071854e-6], 14 | [20.345654e-6, 22.696880e-6, 15.698071e-6, 13.466827e-6, 7.556618e-6] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /arcsim/Materials/white-dots-on-blk.json: -------------------------------------------------------------------------------- 1 | { 2 | "density": 0.128, 3 | "stretching": [ 4 | [2002.08618, 0.345588, 2027.48559, 19.189022], 5 | [2107.22753, 36.371597, 2171.73339, 16.904713], 6 | [2107.29882, 57.936157, 2153.30712, 24.392872], 7 | [2107.73291, 28.389059, 2132.72607, 101.462021], 8 | [2106.93750, 70.149529, 2121.87353, 38.054455], 9 | [2107.30786, 61.216290, 2150.47680, 37.668823] 10 | ], 11 | "bending": [ 12 | [51.713814e-6, 36.506981e-6, 66.360748e-6, 52.729267e-6, 15.221714e-6], 13 | [40.659470e-6, 10.401686e-6, 20.847820e-6, 30.993469e-6, 12.726685e-6], 14 | [31.282822e-6, 22.910311e-6, 26.350384e-6, 30.637762e-6, 16.726685e-6] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /arcsim/Materials/white-swim-solid.json: -------------------------------------------------------------------------------- 1 | { 2 | "density": 0.204, 3 | "stretching": [ 4 | [47.971176, 6.834521, 104.615456, 60.773663], 5 | [40.369045, 23.092957, 169.666290, -24.681890], 6 | [40.291599, 48.142597, 138.261612, 9.002558], 7 | [51.393467, -32.966949, 79.881721, 35.973194], 8 | [51.500938, 1.868910, 63.693932, -37.540417], 9 | [68.621185, 40.131950, 124.468513, 36.199604] 10 | ], 11 | "bending": [ 12 | [60.237942e-6, 56.357208e-6, 69.698593e-6, 55.305969e-6, 34.705532e-6], 13 | [58.803211e-6, 63.121964e-6, 61.379181e-6, 47.971302e-6, 19.383726e-6], 14 | [51.018833e-6, 50.741455e-6, 50.570576e-6, 50.006001e-6, 24.556618e-6] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /arcsim/Meshes/female-objs/shrink.hs: -------------------------------------------------------------------------------- 1 | main = interact $ unlines . map shrink . lines 2 | 3 | shrink ('v':' ':xs) = ("v "++) . unwords . map (show . (/100) . read) . words $ xs 4 | shrink line = line 5 | -------------------------------------------------------------------------------- /arcsim/Meshes/locking-clinder.mtl: -------------------------------------------------------------------------------- 1 | #### 2 | # 3 | # MTL File Generated by Style3D V0.0.0 4 | # 5 | #### 6 | newmtl 圆柱200-body 7 | Ka 0.257132 0.257132 0.257132 8 | Kd 1 1 1 9 | Ks 0.48 0.48 0.48 10 | Ns 128 11 | illum 2 12 | d 1 13 | Pr 0.2 14 | Pm 0 15 | -------------------------------------------------------------------------------- /arcsim/Meshes/locking-square.mtl: -------------------------------------------------------------------------------- 1 | #### 2 | # 3 | # MTL File Generated by Style3D V0.0.0 4 | # 5 | #### 6 | newmtl Cotton_Checks_front 7 | Ka 0.257132 0.257132 0.257132 8 | Kd 1 1 1 9 | Ks 0.075 0.075 0.075 10 | Ns 29.2256 11 | illum 2 12 | d 1 13 | Pr 0.5 14 | Pm 0 15 | map_Ka C:/Users/25809/AppData/Local/Style3D/Project/57848/1009/Cotton_Checks_C.jpg 16 | map_Kd C:/Users/25809/AppData/Local/Style3D/Project/57848/1009/Cotton_Checks_C.jpg 17 | bump -bm 0.5 C:/Users/25809/AppData/Local/Style3D/Project/57848/1009/Cotton_Checks_N.jpg 18 | map_Bump C:/Users/25809/AppData/Local/Style3D/Project/57848/1009/Cotton_Checks_N.jpg 19 | -------------------------------------------------------------------------------- /arcsim/Meshes/locking-square.obj.mtl: -------------------------------------------------------------------------------- 1 | # 2 | # Wavefront material file 3 | # Converted by Meshlab Group 4 | # 5 | 6 | newmtl material_0 7 | Ka 0.200000 0.200000 0.200000 8 | Kd 1.000000 1.000000 1.000000 9 | Ks 1.000000 1.000000 1.000000 10 | Tr 1.000000 11 | illum 2 12 | Ns 0.000000 13 | map_Kd C:/Users/25809/AppData/Local/Style3D/Project/57848/1009/Cotton_Checks_C.jpg 14 | 15 | -------------------------------------------------------------------------------- /arcsim/Meshes/nodefiles/flag.node: -------------------------------------------------------------------------------- 1 | 4 2 0 0 2 | 0 0 0 3 | 1 3 0 4 | 2 3 2 5 | 3 0 2 6 | -------------------------------------------------------------------------------- /arcsim/Meshes/nodefiles/mktablecloth.py: -------------------------------------------------------------------------------- 1 | from math import sqrt 2 | numVerts = 24*4 + 1 3 | print numVerts, "2 0 0" 4 | print "0 0 0" 5 | for i in xrange(1, 25): 6 | num=sqrt(i/25.0); 7 | print (i-1)*4+1, num, num 8 | print (i-1)*4+2, -num, num 9 | print (i-1)*4+3, -num, -num 10 | print (i-1)*4+4, num, -num 11 | -------------------------------------------------------------------------------- /arcsim/Meshes/nodefiles/square.node: -------------------------------------------------------------------------------- 1 | 4 2 0 0 2 | 0 0 0 3 | 1 1 0 4 | 2 1 1 5 | 3 0 1 6 | -------------------------------------------------------------------------------- /arcsim/Meshes/pants.mtl: -------------------------------------------------------------------------------- 1 | newmtl initialShadingGroup 2 | illum 4 3 | Kd 0.50 0.50 0.50 4 | Ka 0.00 0.00 0.00 5 | Tf 1.00 1.00 1.00 6 | Ni 1.00 7 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/Obj.hs: -------------------------------------------------------------------------------- 1 | module Obj (Obj, ObjLine(..), readObj, showObj) where 2 | 3 | import Data.List (intercalate) 4 | import Data.List.Split (splitOn) 5 | import Data.Maybe (mapMaybe) 6 | 7 | data ObjLine = VU [Double] | VL Int 8 | | NX [Double] | NY [Double] | NV [Double] | NL Int 9 | | E [Int] | EA Double | EL Int 10 | | F [[Int]] | FL Int 11 | deriving Show 12 | 13 | type Obj = [ObjLine] 14 | 15 | readObj :: String -> Obj 16 | readObj = mapMaybe readLine . lines 17 | 18 | readLine :: String -> Maybe ObjLine 19 | readLine ('v':'t':' ':us) = Just . VU . map read . words $ us 20 | readLine ('v':'l':' ':l) = Just . VL . read $ l 21 | readLine ('v':' ':xs) = Just . NX . map read . words $ xs 22 | readLine ('n':'y':' ':ys) = Just . NY . map read . words $ ys 23 | readLine ('n':'v':' ':vs) = Just . NV . map read . words $ vs 24 | readLine ('n':'l':' ':l) = Just . NL . read $ l 25 | readLine ('e':' ':vs) = Just . E . map read . words $ vs 26 | readLine ('e':'a':' ':a) = Just . EA . read $ a 27 | readLine ('e':'l':' ':l) = Just . EL . read $ l 28 | readLine ('f':' ':vs) = Just . F . map readTriplet . words $ vs 29 | readLine ('f':'l':' ':l) = Just . FL . read $ l 30 | readLine _ = Nothing 31 | 32 | readTriplet :: String -> [Int] 33 | readTriplet = map read . splitOn "/" 34 | 35 | showObj :: Obj -> String 36 | showObj = unlines . map showLine 37 | 38 | showLine :: ObjLine -> String 39 | showLine (VU us) = ("vt "++) . unwords . map show $ us 40 | showLine (VL l) = ("vl "++) . show $ l 41 | showLine (NX xs) = ("v "++) . unwords . map show $ xs 42 | showLine (NY ys) = ("ny "++) . unwords . map show $ ys 43 | showLine (NV vs) = ("nv "++) . unwords . map show $ vs 44 | showLine (NL l) = ("nl "++) . show $ l 45 | showLine (E vs) = ("e "++) . unwords . map show $ vs 46 | showLine (EA a) = ("ea "++) . show $ a 47 | showLine (EL l) = ("el "++) . show $ l 48 | showLine (F vs) = ("f "++) . unwords . map showTriplet $ vs 49 | showLine (FL l) = ("fl "++) . show $ l 50 | 51 | showTriplet :: [Int] -> String 52 | showTriplet = intercalate "/" . map show 53 | 54 | -- if (keyword == "vt") { 55 | -- Vec2 u; 56 | -- linestream >> u[0] >> u[1]; 57 | -- mesh.add(new Vert(u)); 58 | -- } else if (keyword == "vl") { 59 | -- linestream >> mesh.verts.back()->label; 60 | -- } else if (keyword == "v") { 61 | -- Vec3 x; 62 | -- linestream >> x[0] >> x[1] >> x[2]; 63 | -- mesh.add(new Node(x, Vec3(0))); 64 | -- } else if (keyword == "ny") { 65 | -- Vec3 &y = mesh.nodes.back()->y; 66 | -- linestream >> y[0] >> y[1] >> y[2]; 67 | -- } else if (keyword == "nv") { 68 | -- Vec3 &v = mesh.nodes.back()->v; 69 | -- linestream >> v[0] >> v[1] >> v[2]; 70 | -- } else if (keyword == "nl") { 71 | -- linestream >> mesh.nodes.back()->label; 72 | -- } else if (keyword == "e") { 73 | -- int v0, v1; 74 | -- linestream >> v0 >> v1; 75 | -- mesh.add(new Edge(mesh.verts[v0-1], mesh.verts[v1-1])); 76 | -- } else if (keyword == "ea") { 77 | -- linestream >> mesh.edges.back()->theta_ideal; 78 | -- } else if (keyword == "el") { 79 | -- linestream >> mesh.edges.back()->label; 80 | -- } else if (keyword == "f") { 81 | -- vector verts; 82 | -- vector nodes; 83 | -- string w; 84 | -- while (linestream >> w) { 85 | -- stringstream wstream(w); 86 | -- int v, n; 87 | -- char c; 88 | -- wstream >> n >> c >> v; 89 | -- nodes.push_back(mesh.nodes[n-1]); 90 | -- if (wstream) 91 | -- verts.push_back(mesh.verts[v-1]); 92 | -- else if (!nodes.back()->verts.empty()) 93 | -- verts.push_back(nodes.back()->verts[0]); 94 | -- else { 95 | -- verts.push_back(new Vert(project<2>(nodes.back()->x))); 96 | -- mesh.add(verts.back()); 97 | -- } 98 | -- } 99 | -- for (int v = 0; v < verts.size(); v++) 100 | -- connect(verts[v], nodes[v]); 101 | -- vector faces = triangulate(verts); 102 | -- for (int f = 0; f < faces.size(); f++) 103 | -- mesh.add(faces[f]); 104 | -- } else if (keyword == "fl") { 105 | -- linestream >> mesh.faces.back()->label; 106 | -- } 107 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/count.hs: -------------------------------------------------------------------------------- 1 | import Data.List 2 | 3 | main = interact $ (++"\n") . show . length . filter ("f " `isPrefixOf`) . lines 4 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/cylinder.hs: -------------------------------------------------------------------------------- 1 | import Obj 2 | 3 | main = interact $ showObj . concatMap label . map roll . readObj 4 | 5 | roll (NX [x,y,z]) = NX [r*cos theta, r*sin theta, y] 6 | where theta = 2*pi*x/c 7 | roll line = line 8 | 9 | c = 0.280 -- circumference 10 | s = 1 -- scaling factor 11 | r = s*c/(2*pi) 12 | 13 | label (NX [x,y,z]) | z < 0+eps = [NX [x,y,z], NL 1] 14 | label (NX [x,y,z]) | z > h-eps = [NX [x,y,z], NL 2] 15 | label line = [line] 16 | 17 | h = 0.216 -- height 18 | eps = 1e-3 19 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/ffwd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | runhaskell fold.hs 0 280 0 0 90 < ../ffwd0.obj > ../ffwd1.obj 4 | runhaskell fold.hs 0 280 0 0 180 < ../ffwd0.obj > ../ffwd2.obj 5 | runhaskell fold.hs 108 108 0 0 90 < ../ffwd0.obj > ~/tmp/ffwd.obj 6 | runhaskell fold.hs 0 0 -108 108 90 < ~/tmp/ffwd.obj > ../ffwd3.obj 7 | runhaskell fold.hs 108 108 0 0 180 < ../ffwd0.obj > ~/tmp/ffwd.obj 8 | runhaskell fold.hs 0 0 -108 108 180 < ~/tmp/ffwd.obj > ../ffwd4.obj 9 | runhaskell fold.hs 108 261 0 0 90 < ../ffwd4.obj > ~/tmp/ffwd.obj 10 | runhaskell fold.hs 0 0 -108 261 90 < ~/tmp/ffwd.obj > ../ffwd5.obj 11 | runhaskell fold.hs 108 261 0 0 180 < ../ffwd4.obj > ~/tmp/ffwd.obj 12 | runhaskell fold.hs 0 0 -108 261 180 < ~/tmp/ffwd.obj > ../ffwd6.obj 13 | runhaskell fold.hs 0 280 0 0 90 < ../ffwd6.obj > ../ffwd7.obj 14 | runhaskell fold.hs 0 280 0 0 180 < ../ffwd6.obj > ../ffwd8.obj 15 | runhaskell fold.hs 0 0 -56 280 90 < ../ffwd8.obj > ../ffwd9.obj 16 | runhaskell fold.hs 0 0 -56 280 180 < ../ffwd8.obj > ../ffwd10.obj 17 | $EDITOR ../ffwd8.obj ../ffwd9.obj ../ffwd10.obj 18 | runhaskell fold.hs 0 0 0 280 90 < ../ffwd10.obj > ~/tmp/ffwd.obj 19 | runhaskell translate.hs < ~/tmp/ffwd.obj > ../ffwd11.obj 20 | runhaskell fold.hs 0 0 0 280 180 < ../ffwd10.obj > ../ffwd12.obj 21 | runhaskell fold.hs 56 280 0 0 90 < ../ffwd12.obj > ../ffwd13.obj 22 | runhaskell fold.hs 56 280 0 0 180 < ../ffwd12.obj > ../ffwd14.obj 23 | runhaskell fold.hs 0 280 0 0 90 < ../ffwd14.obj > ../ffwd15.obj 24 | runhaskell fold.hs 0 0 -56 280 45 < ../ffwd8.obj > ~/tmp/ffwd.obj 25 | runhaskell rotate.hs < ~/tmp/ffwd.obj > ../ffwd16.obj 26 | runhaskell fold.hs 0 0 -56 280 90 < ../ffwd8.obj > ~/tmp/ffwd.obj 27 | runhaskell rotate.hs < ~/tmp/ffwd.obj > ../ffwd17.obj 28 | $EDITOR ../ffwd16.obj ../ffwd17.obj 29 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/flip.hs: -------------------------------------------------------------------------------- 1 | main = interact $ unlines . map Main.flip . lines 2 | 3 | flip ('f':' ':vs) = ("f "++) . unwords . reverse . words $ vs 4 | flip line = line 5 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/fold.hs: -------------------------------------------------------------------------------- 1 | import Control.Monad 2 | import Obj 3 | import System.Environment 4 | 5 | main = do 6 | args <- liftM (map read) getArgs 7 | interact $ showObj . map (fold args) . readObj 8 | 9 | fold [x0,y0,x1,y1,theta] (NX [x,y,z]) = NX $ rotate (x0,y0) (x1,y1) theta (x,y) z 10 | fold _ line = line 11 | 12 | rotate p0@(x0,y0) p1@(x1,y1) theta p@(x,y) z = 13 | let dp = (x-x0, y-y0) 14 | u = normalize (x1-x0, y1-y0) 15 | v = perp u 16 | pu = p <.> u 17 | pv = p <.> v 18 | rad = theta*pi/180 19 | p2@(x2,y2) = (pu <*> u) <+> ((pv * cos rad) <*> v) 20 | in 21 | if pv < 0 22 | then [x, y, z] 23 | else [x2, y2, pv * sin rad] 24 | 25 | normalize (x, y) = (x/n, y/n) where n = sqrt (x*x + y*y) 26 | perp (x, y) = (-y, x) 27 | (x1,y1) <.> (x2,y2) = x1*x2 + y1*y2 28 | a <*> (x,y) = (a*x, a*y) 29 | (x1,y1) <+> (x2,y2) = (x1+x2, y1+y2) 30 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/pause.hs: -------------------------------------------------------------------------------- 1 | import Control.Monad 2 | import Data.List 3 | import System.Environment 4 | 5 | type Vec = [Double] 6 | data Block = Block String [Vec] 7 | data Mot = Mot Int [Block] 8 | 9 | main :: IO () 10 | main = do 11 | [sf, pf] <- liftM (map read) getArgs 12 | interact $ unlines . writeMot . pauseMot pf . shiftMot sf . readMot . lines 13 | 14 | readMot :: [String] -> Mot 15 | readMot (l:ls) = Mot (readFrames l) (readBlocks ls) 16 | 17 | readFrames :: String -> Int 18 | readFrames = read . (!! 1) . words 19 | 20 | readBlocks :: [String] -> [Block] 21 | readBlocks = map readBlock . split "" 22 | 23 | split :: Eq a => a -> [a] -> [[a]] 24 | split a [] = [[]] 25 | split a (b:bs) | a==b = [] : split a bs 26 | split a (b:bs) = let ss = split a bs in (b : head ss) : tail ss 27 | 28 | readBlock :: [String] -> Block 29 | readBlock (h:d) = Block h (readData d) 30 | 31 | readData :: [String] -> [Vec] 32 | readData = map (map read . words) 33 | 34 | writeMot :: Mot -> [String] 35 | writeMot (Mot f bs) = writeFrames f : writeBlocks bs 36 | 37 | writeFrames :: Int -> String 38 | writeFrames f = "NumFrames: " ++ show f 39 | 40 | writeBlocks :: [Block] -> [String] 41 | writeBlocks = intercalate [""] . map writeBlock 42 | 43 | writeBlock :: Block -> [String] 44 | writeBlock (Block h d) = h : writeData d 45 | 46 | writeData :: [Vec] -> [String] 47 | writeData = map (unwords . map show) 48 | 49 | shiftMot :: Int -> Mot -> Mot 50 | shiftMot n (Mot f bs) = Mot (f - n) (map (shiftBlock n) bs) 51 | 52 | shiftBlock :: Int -> Block -> Block 53 | shiftBlock n (Block h d) = Block h (drop n d) 54 | 55 | pauseMot :: Int -> Mot -> Mot 56 | pauseMot n (Mot f bs) = Mot (f + n) (map (pauseBlock n) bs) 57 | 58 | pauseBlock :: Int -> Block -> Block 59 | pauseBlock n (Block h d) = Block h (replicate n (head d) ++ d) 60 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/plastic.hs: -------------------------------------------------------------------------------- 1 | import Obj 2 | import Data.Maybe (mapMaybe) 3 | 4 | main = interact $ showObj . mapMaybe plastic . readObj 5 | 6 | plastic (NX _) = Nothing 7 | plastic (NY y) = Just $ NX y 8 | plastic line = Just line 9 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/rotate.hs: -------------------------------------------------------------------------------- 1 | import Obj 2 | 3 | main = interact $ showObj . map rotate . readObj 4 | 5 | rotate (NX [x,y,z]) = NX [z,y,-x] 6 | rotate l = l 7 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/shrink.hs: -------------------------------------------------------------------------------- 1 | main = interact $ unlines . map shrink . lines 2 | 3 | shrink ('v':' ':xs) = ("v "++) . unwords . map (show . (/100) . read) . words $ xs 4 | shrink line = line 5 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/svg2poly.hs: -------------------------------------------------------------------------------- 1 | import Control.Arrow 2 | import Data.List 3 | import Data.Maybe 4 | import Debug.Trace 5 | 6 | type Point = (Double, Double) 7 | type Polygon = [Point] 8 | 9 | main :: IO () 10 | main = interact $ writePoly . readSvg 11 | 12 | readSvg :: String -> [Polygon] 13 | readSvg = map svgToPoints . findBetween " d=\"m" "\"" 14 | 15 | findBetween :: String -> String -> String -> [String] 16 | findBetween start end = unfoldr go 17 | where go s = do 18 | (_, s') <- splitAround start s 19 | (w, s'') <- splitAround end s' 20 | return (w, s'') 21 | 22 | splitAround :: Eq a => [a] -> [a] -> Maybe ([a], [a]) 23 | splitAround p s = do 24 | let ss = splits s 25 | sa <- find ((p `isPrefixOf`) . snd) ss 26 | let pre = fst sa 27 | post <- stripPrefix p (snd sa) 28 | return (pre, post) 29 | 30 | splits :: [a] -> [([a],[a])] 31 | splits s = map (\n -> splitAt n s) [0 .. length s] 32 | 33 | svgToPoints :: String -> [Point] 34 | svgToPoints = runningSum (0,0) . map svgToPoint . words 35 | where svgToPoint = (read *** read) . fromJust . splitAround "," 36 | runningSum _ [] = [] 37 | runningSum p0 (p:ps) = p1 : runningSum p1 ps 38 | where p1 = (fst p0 + fst p, snd p0 + snd p) 39 | 40 | newtype Counter a = Counter (Int -> (Int, a)) 41 | instance Monad Counter where 42 | return x = Counter (\n -> (n,x)) 43 | (Counter c) >>= f = Counter (\n -> let (n',x) = c n; Counter c' = f x in c' n') 44 | 45 | get :: Counter Int 46 | get = Counter (\n -> (n, n)) 47 | 48 | increment :: Counter () 49 | increment = Counter (\n -> (n+1, ())) 50 | 51 | run :: Int -> Counter a -> a 52 | run n (Counter c) = snd (c n) 53 | 54 | writePoly :: [Polygon] -> String 55 | writePoly polys = concat [writeVerts (concat ps) (concat polys), writeSegs ps, "0\n"] 56 | where ps = run 0 (enumerate' polys) 57 | 58 | enumerate :: [a] -> Counter [Int] 59 | enumerate [] = return [] 60 | enumerate (x:xs) = do n <- get; increment; ns <- enumerate xs; return (n:ns) 61 | 62 | enumerate' :: [[a]] -> Counter [[Int]] 63 | enumerate' [] = return [] 64 | enumerate' (xs:xss) = do ns <- enumerate xs; nss <- enumerate' xss; return (ns:nss) 65 | 66 | counting :: (a -> Counter b) -> [a] -> Counter [b] 67 | counting c [] = return [] 68 | counting c (x:xs) = do y <- c x; ys <- counting c xs; return (y:ys) 69 | 70 | incrementing :: (Int -> a -> b) -> a -> Counter b 71 | incrementing f x = do n <- get; let {y = f n x}; increment; return y 72 | 73 | writeVerts :: [Int] -> [Point] -> String 74 | writeVerts ps points = unlines . (header:) $ zipWith vert ps points 75 | where vert n (x,y) = unwords [show n, show x, show y] 76 | header = unwords [show . length $ ps, "2", "0", "0"] 77 | 78 | writeSegs :: [[Int]] -> String 79 | writeSegs pss = unlines . (header:) $ run 0 (go segs) 80 | where go = counting (incrementing (\n (x,y) -> unwords [show n, show x, show y])) 81 | header = unwords [show . length . concat $ pss, "0"] 82 | rotate xs = tail xs ++ [head xs] 83 | segs = concatMap (\ps -> zip ps (rotate ps)) pss 84 | 85 | trace' :: Show a => a -> a 86 | trace' x = trace (show x) x 87 | -------------------------------------------------------------------------------- /arcsim/Meshes/scripts/translate.hs: -------------------------------------------------------------------------------- 1 | import Obj 2 | 3 | main = interact $ showObj . map translate . readObj 4 | 5 | translate (NX [x,y,z]) = NX [x,y,z+0.02] 6 | translate l = l 7 | -------------------------------------------------------------------------------- /arcsim/Meshes/shrinkobj.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Usage: python shrinkobj.py > outfile 3 | # This script takes a .obj file and shrinks all the vertices by the specified 4 | # amount, and then shifts it down on the y-axis by the specified amount. 5 | import sys 6 | 7 | if(len(sys.argv) == 1): 8 | print("Usage: python shrinkobj.py > outfile"); 9 | sys.exit(1); 10 | filename = sys.argv[1] 11 | 12 | shrinkfactor = sys.argv[2] if len(sys.argv) >= 3 else 30 13 | movedown = sys.argv[3] if len(sys.argv) >= 4 else .5 14 | 15 | fd = open( filename ) 16 | content = fd.readline() 17 | while (content != "" ): 18 | parts = content.split(" "); 19 | if parts[0] != 'v': 20 | print content; 21 | content = fd.readline().strip() 22 | continue 23 | for i in range(1,4): 24 | parts[i] = float(parts[i]) / shrinkfactor 25 | parts[3] = parts[3] - movedown 26 | print parts[0], parts[1], parts[2], parts[3]; 27 | content = fd.readline() 28 | -------------------------------------------------------------------------------- /arcsim/Meshes/sphere.mot: -------------------------------------------------------------------------------- 1 | NumFrames: 8 2 | body[0] position 3 | 0 0 0 4 | 0 0 0 5 | 0 0 0 6 | 0 -8 0 7 | 0 0 0 8 | 0 8 0 9 | 0 4 0 10 | 0 -2 0 11 | 12 | body[0] orientation 13 | 0 0 0 1 14 | 0 0 0 1 15 | 0 0 0 1 16 | 0 0 0 1 17 | 0 0 0 1 18 | 0 0 0 1 19 | 0 0 0 1 20 | 0 0 0 1 21 | -------------------------------------------------------------------------------- /bending_validation/AssembleMatrix.m: -------------------------------------------------------------------------------- 1 | function [H, F] = AssembleMatrix(x, vdt, vertMass, edges, faces, edgeAdjFaces, edgeRestLen, isFixedVert, gravity, youngsModulus, lexuralModulus, timeStep) 2 | 3 | dim = length(x); 4 | numVerts = length(x) / 3; 5 | numEdges = length(edges); 6 | 7 | F = zeros(dim, 1); 8 | H = sparse(dim, dim); 9 | dt2 = timeStep * timeStep; 10 | 11 | for i = 1 : numEdges 12 | idx1 = 3 * edges(i,1) - 2 : 3 * edges(i,1); 13 | idx2 = 3 * edges(i,2) - 2 : 3 * edges(i,2); 14 | idx = [idx1, idx2]; 15 | 16 | x1 = x(idx1); 17 | x2 = x(idx2); 18 | restLen = edgeRestLen(i); 19 | [H1, F1] = SpringHessianForce(x1, x2, youngsModulus, restLen); 20 | H(idx, idx) = H(idx, idx) + H1; 21 | F(idx) = F(idx) + F1; 22 | 23 | if (length(edgeAdjFaces{i}) == 2) 24 | vIdx3 = sum(faces(edgeAdjFaces{i}(1),:)) - sum(edges(i,:)); 25 | vIdx4 = sum(faces(edgeAdjFaces{i}(2),:)) - sum(edges(i,:)); 26 | idx3 = 3 * vIdx3 - 2 : 3 * vIdx3; 27 | idx4 = 3 * vIdx4 - 2 : 3 * vIdx4; 28 | idx = [idx1, idx2, idx3, idx4]; 29 | 30 | [H2, F2] = DihedralBendingHessianForce(x1, x2, x(idx3), x(idx4), lexuralModulus, restLen); 31 | H(idx, idx) = H(idx, idx) + H2; 32 | F(idx) = F(idx) + F2; 33 | end 34 | end 35 | 36 | %% Implicit euler diagonal term. 37 | for i = 1 : numVerts 38 | idx = 3 * i - 2 : 3 * i; 39 | if (isFixedVert(i) == 1) 40 | F(idx) = [0; 0; 0]; 41 | H(idx, idx) = H(idx, idx) + eye(3) * 1e8; 42 | else 43 | massWeight = vertMass(i) / dt2; 44 | F(3*i-1) = F(3*i-1) - vertMass(i) * gravity; 45 | H(idx, idx) = H(idx, idx) + eye(3) * massWeight; 46 | F(idx) = F(idx) + massWeight * vdt(idx); 47 | end 48 | end 49 | end -------------------------------------------------------------------------------- /bending_validation/BendingCurve.m: -------------------------------------------------------------------------------- 1 | function [x, y, s] = BendingCurve(theta0, rho_g_len3_invAlpha, numSamples) 2 | 3 | guessXc = 0.25; 4 | 5 | [x, y, s, delta] = NumericalIntegrate(theta0, rho_g_len3_invAlpha, numSamples, guessXc); 6 | 7 | step = 0.25; 8 | epslion = delta; 9 | 10 | while (epslion ~= 0) 11 | 12 | step = sign(delta) * abs(step) / 2.0; 13 | guessXc = guessXc + step; 14 | 15 | [x, y, s, newDelta] = NumericalIntegrate(theta0, rho_g_len3_invAlpha, numSamples, guessXc); 16 | 17 | epslion = newDelta - delta; 18 | delta = newDelta; 19 | end 20 | end 21 | 22 | 23 | function [x, y, s, delta] = NumericalIntegrate(theta0, rho_g_len3_invAlpha, numSamples, guessXc) 24 | 25 | s = linspace(0, 1, numSamples); 26 | 27 | ds = s(2) - s(1); 28 | x = zeros(1, length(s)); 29 | y = zeros(1, length(s)); 30 | K = guessXc * rho_g_len3_invAlpha; 31 | dKdx = rho_g_len3_invAlpha * (s(1) - 1); 32 | dydx = tan(theta0 * pi / 180.0); 33 | ddydxds = -K * (1 + dydx^2); 34 | 35 | for i = 1:length(s) - 1 36 | 37 | dx = ds / sqrt(1 + dydx^2); 38 | dy = sign(dydx) * ds * sqrt(1 - 1 / (1 + dydx^2)); 39 | 40 | x(i + 1) = x(i) + dx; 41 | y(i + 1) = y(i) + dy; 42 | 43 | K = max(0, K + dKdx * dx); 44 | dydx = dydx + ddydxds * ds; 45 | dKdx = rho_g_len3_invAlpha * (s(i + 1) - 1); 46 | ddydxds = -K * (1 + dydx^2); 47 | end 48 | 49 | delta = sum(x * ds) - guessXc; 50 | end -------------------------------------------------------------------------------- /bending_validation/BuildTopo.m: -------------------------------------------------------------------------------- 1 | function meshTopo = BuildTopo(faces, numVerts) 2 | % 3 | % fname - file name 4 | % mesh - output mesh 5 | % 6 | % mesh.v - vertices positions 7 | % mesh.vt - uv coordinates 8 | % mesh.vn - normals 9 | % 10 | % mesh.f - faces 11 | % mesh.f.v - vertex indices for mesh.v 12 | % mesh.f.vt - vertex indices for mesh.vt 13 | % mesh.f.vt - vertex indices for mesh.vn 14 | % 15 | 16 | meshTopo.numEdges = 0; 17 | meshTopo.numVerts = numVerts; 18 | meshTopo.numFaces = size(faces,1); 19 | meshTopo.vertAdjVerts = cell(numVerts, 1); 20 | meshTopo.vertAdjEdges = cell(numVerts, 1); 21 | meshTopo.vertAdjFaces = cell(numVerts, 1); 22 | meshTopo.edgeAdjFaces = cell(0,1); 23 | meshTopo.edges = zeros(0); 24 | meshTopo.isBoundaryEdge = zeros(0); 25 | meshTopo.isBoundaryVert = zeros(numVerts, 1); 26 | 27 | % Build mesh topo. 28 | for i = 1 : meshTopo.numFaces 29 | for j = 1 : 3 30 | v0 = faces(i, j); 31 | v1 = faces(i, mod(j, 3) + 1); 32 | n0 = length(meshTopo.vertAdjFaces{v0}); 33 | meshTopo.vertAdjFaces{v0}(n0 + 1) = i; 34 | 35 | isFound = false; 36 | for k = 1 : length(meshTopo.vertAdjVerts{v0}) 37 | if meshTopo.vertAdjVerts{v0}(k) == v1 38 | edgeIdx = meshTopo.vertAdjEdges{v0}(k); 39 | meshTopo.edgeAdjFaces{edgeIdx}(2) = i; 40 | isFound = true; 41 | end 42 | end 43 | 44 | if ~isFound 45 | meshTopo.numEdges = meshTopo.numEdges + 1; 46 | meshTopo.edges(meshTopo.numEdges, 1) = v0; 47 | meshTopo.edges(meshTopo.numEdges, 2) = v1; 48 | num0 = length(meshTopo.vertAdjVerts{v0}); 49 | num1 = length(meshTopo.vertAdjVerts{v1}); 50 | meshTopo.vertAdjVerts{v0}(num0 + 1) = v1; 51 | meshTopo.vertAdjVerts{v1}(num1 + 1) = v0; 52 | meshTopo.vertAdjEdges{v0}(num0 + 1) = meshTopo.numEdges; 53 | meshTopo.vertAdjEdges{v1}(num1 + 1) = meshTopo.numEdges; 54 | meshTopo.edgeAdjFaces{meshTopo.numEdges}(1) = i; 55 | end 56 | end 57 | end 58 | 59 | % Find all boundary verts. 60 | for i = 1 : meshTopo.numEdges 61 | if length(meshTopo.edgeAdjFaces{i}) < 2 62 | meshTopo.isBoundaryVert(meshTopo.edges(i, 1)) = true; 63 | meshTopo.isBoundaryVert(meshTopo.edges(i, 2)) = true; 64 | meshTopo.isBoundaryEdge(i) = true; 65 | end 66 | end -------------------------------------------------------------------------------- /bending_validation/CreateCloth.m: -------------------------------------------------------------------------------- 1 | function cloth = CreateCloth(v, edges, faces, edgeAdjFaces, density) 2 | 3 | cloth.totalArea = 0; 4 | cloth.numVerts = size(v, 1); 5 | cloth.numEdges = size(edges, 1); 6 | cloth.numFaces = size(faces, 1); 7 | cloth.vertMass = zeros(1, cloth.numVerts); 8 | cloth.faceArea = zeros(1, cloth.numFaces); 9 | cloth.edgeRestLen = zeros(1, cloth.numEdges); 10 | cloth.edgeRestHeight = cell(1, cloth.numEdges); 11 | 12 | for i = 1 : cloth.numFaces 13 | face = faces(i,:); 14 | A = v(face(1),:); 15 | B = v(face(2),:); 16 | C = v(face(3),:); 17 | cloth.faceArea(i) = norm(cross(B - A, C - B)) / 2; 18 | cloth.totalArea = cloth.totalArea + cloth.faceArea(i); 19 | cloth.vertMass(face(1)) = cloth.vertMass(face(1)) + density * cloth.faceArea(i) / 3; 20 | cloth.vertMass(face(2)) = cloth.vertMass(face(2)) + density * cloth.faceArea(i) / 3; 21 | cloth.vertMass(face(3)) = cloth.vertMass(face(3)) + density * cloth.faceArea(i) / 3; 22 | end 23 | 24 | for i = 1 : cloth.numEdges 25 | A = v(edges(i,1),:); 26 | B = v(edges(i,2),:); 27 | restLen = norm(A - B); 28 | cloth.edgeRestLen(i) = restLen; 29 | cloth.edgeRestHeight{i} = zeros(size(edgeAdjFaces{i})); 30 | for j = 1 : length(edgeAdjFaces{i}) 31 | fIdx = edgeAdjFaces{i}(j); 32 | faceArea = cloth.faceArea(fIdx); 33 | cloth.edgeRestHeight{i}(j) = 2 * faceArea / restLen; 34 | end 35 | end -------------------------------------------------------------------------------- /bending_validation/DihedralBendingHessianForce.m: -------------------------------------------------------------------------------- 1 | function [H, F] = DihedralBendingHessianForce(x1, x2, x3, x4, lexuralModulus, restLen) 2 | 3 | x12 = x2 - x1; 4 | x13 = x3 - x1; 5 | x14 = x4 - x1; 6 | n1 = cross(x12, x13); 7 | n2 = cross(x14, x12); 8 | 9 | currLen = norm(x12); 10 | h1 = norm(n1) / currLen; 11 | h2 = norm(n2) / currLen; 12 | 13 | e = x12 / currLen; 14 | n1 = n1 / norm(n1); 15 | n2 = n2 / norm(n2); 16 | w1 = dot(e, x13) / currLen; 17 | w2 = dot(e, x14) / currLen; 18 | 19 | dAdx = [(w1 - 1) * n1 / h1 + (w2 - 1) * n2 / h2; 20 | -(w1 * n1 / h1 + w2 * n2 / h2); 21 | n1 / h1; 22 | n2 / h2]; 23 | 24 | angle = DihedralAngle(e, n1, n2); 25 | kappa = SignedCurveture(angle, h1, h2); 26 | bendingRigidity = lexuralModulus * restLen; 27 | 28 | F = bendingRigidity * kappa * dAdx; 29 | H = bendingRigidity * (2 / (h1 + h2)) * (dAdx * dAdx'); 30 | end 31 | 32 | function kappa = SignedCurveture(angle, h1, h2) 33 | kappa = 2 * angle / (h1 + h2); 34 | end 35 | 36 | function angle = DihedralAngle(e, n1, n2) 37 | cosAngle = dot(n1, n2); 38 | sinAngle = dot(e, cross(n1, n2)); 39 | angle = atan2(sinAngle, cosAngle); 40 | end -------------------------------------------------------------------------------- /bending_validation/GenerateModulusForSampling.m: -------------------------------------------------------------------------------- 1 | function [modulus_lst] = GenerateModulusForSampling(rho, L, g, samples) 2 | log10_gamma_st = -2; 3 | log10_gamma_ed = 2; 4 | 5 | log10_gamma_lst = linspace(log10_gamma_st, log10_gamma_ed, samples); 6 | gamma_lst = 10.^(log10_gamma_lst); 7 | modulus_lst = rho * g * L^3 ./ gamma_lst; 8 | 9 | end 10 | -------------------------------------------------------------------------------- /bending_validation/GetHW.m: -------------------------------------------------------------------------------- 1 | function [ratio] = GetHW(pos) 2 | numOfVertices = length(pos) / 3; 3 | min_y = 1e3; 4 | max_x = -1e3; 5 | for i = 0:numOfVertices-1 6 | cur_pos = pos(3 * i + 1: 3 * i + 3); 7 | 8 | cur_y = cur_pos(2); 9 | cur_x = cur_pos(1); 10 | 11 | max_x = max(cur_x, max_x); 12 | min_y = min(cur_y, min_y); 13 | end 14 | ratio = abs(min_y) / abs(max_x); 15 | end 16 | -------------------------------------------------------------------------------- /bending_validation/LICENSE: -------------------------------------------------------------------------------- 1 | This code is distributed under CC-BY-NC-ND 4.0 license. -------------------------------------------------------------------------------- /bending_validation/LoadMasterCurve.m: -------------------------------------------------------------------------------- 1 | function [master_x, master_y] = LoadMasterCurve(pos) 2 | data = load("master_curve_data"); 3 | master_x = data.master_x; 4 | master_y = data.master_y; 5 | end -------------------------------------------------------------------------------- /bending_validation/PlotMasterCurve.m: -------------------------------------------------------------------------------- 1 | function PlotMasterCurve(gamma, ratio) 2 | hold on 3 | set(gca, 'Box', 'on') 4 | set(gca, 'XGrid', 'on') 5 | set(gca, 'YGrid', 'on') 6 | set(gca, 'XScale', 'log') 7 | set(gca, 'YScale', 'log') 8 | plot(gamma, ratio, 'black') 9 | xlim([10^-3, 10^4]) 10 | ylim([10^-4, 10^3]) 11 | xlabel('\Gamma') 12 | ylabel('H / W') 13 | end -------------------------------------------------------------------------------- /bending_validation/README.md: -------------------------------------------------------------------------------- 1 | This folder contains `MATLAB` code to compare different bending models, such as Discrete Shell [Grinspun 2013], ARCSim bending model [Narain 2012] and Ours. 2 | 3 | Please run `main.m` to get the validation result: ![image](master_curve.png) -------------------------------------------------------------------------------- /bending_validation/ReadObj.m: -------------------------------------------------------------------------------- 1 | function mesh = ReadObj(fname) 2 | % 3 | % fname - file name 4 | % mesh - output mesh 5 | % 6 | % mesh.v - vertices positions 7 | % mesh.vt - uv coordinates 8 | % mesh.vn - normals 9 | % 10 | % mesh.f - faces 11 | % mesh.f.v - vertex indices for mesh.v 12 | % mesh.f.vt - vertex indices for mesh.vt 13 | % mesh.f.vt - vertex indices for mesh.vn 14 | % 15 | 16 | vn = 1; 17 | v_h = []; 18 | vtn = 1; 19 | vt_h = []; 20 | vnn = 1; 21 | vn_h = []; 22 | 23 | fn = 1; 24 | fv_h = []; 25 | fvt_h = []; 26 | fvn_h = []; 27 | 28 | fid = fopen(fname); 29 | 30 | while 1 31 | tline = fgetl(fid); 32 | if ~ischar(tline) % end of file 33 | break 34 | end 35 | ln = sscanf(tline,'%s',1); % type 36 | switch ln 37 | case 'v' 38 | % tline 39 | temp = sscanf(tline(2:end),'%f'); 40 | if(vn>size(v_h,1)) 41 | v_h = double_array(v_h ,temp ); 42 | else 43 | v_h (vn,:) = temp (:); 44 | end 45 | vn = vn + 1; 46 | case 'vt' 47 | temp = sscanf(tline(3:end),'%f') ; 48 | if(vtn>size(vt_h,1)) 49 | vt_h = double_array(vt_h ,temp ); 50 | else 51 | vt_h (vtn,:) = temp (:); 52 | end 53 | vtn = vtn + 1; 54 | 55 | case 'vn' 56 | temp = sscanf(tline(3:end),'%f') ; 57 | if(vnn>size(vn_h,1)) 58 | vn_h = double_array(vn_h ,temp ); 59 | else 60 | vn_h (vnn,:) = temp (:); 61 | end 62 | vnn = vnn + 1; 63 | 64 | case 'f' % face definition 65 | % ln 66 | % tline 67 | fv = []; fvt = []; fvn = []; 68 | str = tline(2:end); 69 | vertices_num = sum(str == ' '); 70 | nf = sum(str == '/') / vertices_num; 71 | nf = ceil(nf); 72 | switch(nf) 73 | case 0 74 | C = textscan(str,'%d'); 75 | fv = C{1}; 76 | case 1 77 | C = textscan(str,'%d/%d'); 78 | fv = C{1}; 79 | fvt = C{2}; 80 | case 2 81 | C = textscan(str,'%d/%d/%d'); 82 | fv = C{1}; 83 | fvt = C{2}; 84 | fvn = C{3}; 85 | end 86 | 87 | if(fn>size(fv_h,1)) 88 | fv_h = double_array(fv_h ,fv ); 89 | fvt_h = double_array(fvt_h,fvt); 90 | fvn_h = double_array(fvn_h,fvn); 91 | else 92 | fv_h (fn,:) = fv (:); 93 | fvt_h(fn,:) = fvt(:); 94 | fvn_h(fn,:) = fvn(:); 95 | end 96 | 97 | fn = fn + 1 ; 98 | otherwise 99 | % do nothing 100 | end 101 | end 102 | fclose(fid); 103 | 104 | f.v = shrink_to_fit(fv_h,fn); 105 | f.vt = shrink_to_fit(fvt_h,fn); 106 | f.vn = shrink_to_fit(fvn_h,fn); 107 | % set up matlab object 108 | 109 | mesh.v = shrink_to_fit(v_h,vn); 110 | mesh.vt = shrink_to_fit(vt_h,vtn); 111 | mesh.vn = shrink_to_fit(vn_h,vnn); 112 | mesh.f = f; 113 | end 114 | 115 | function r = shrink_to_fit(array,nv) 116 | r = array(1:nv - 1,:); 117 | end 118 | 119 | function r = double_array(array,vab) 120 | sz = size(array,1); 121 | r = zeros(sz * 2,length(vab)); 122 | r(1:sz,:) = array(1:sz,:); 123 | r(sz + 1,:) = vab(:); 124 | end -------------------------------------------------------------------------------- /bending_validation/SetFixed.m: -------------------------------------------------------------------------------- 1 | function isFixedVert = SetFixed(v) 2 | 3 | isFixedVert = zeros(1, length(v)); 4 | 5 | for i = 1 : length(v) 6 | if (v(i,1) < 0.002) 7 | isFixedVert(i) = 1; 8 | end 9 | end 10 | end -------------------------------------------------------------------------------- /bending_validation/SpringHessianForce.m: -------------------------------------------------------------------------------- 1 | function [H, F] = SpringHessianForce(x1, x2, youngsModulus, restLen) 2 | 3 | currLen = norm(x1 - x2); 4 | dir = (x1 - x2) / currLen; 5 | k = youngsModulus / restLen; 6 | force = k * (currLen - restLen) * dir; 7 | 8 | hessian = k * (dir * dir'); 9 | if (currLen > restLen) 10 | diagVal = k * (currLen - restLen) / currLen; 11 | hessian(1,1) = hessian(1,1) + diagVal; 12 | hessian(2,2) = hessian(2,2) + diagVal; 13 | hessian(3,3) = hessian(3,3) + diagVal; 14 | end 15 | 16 | F = [ -force; force ]; 17 | H = [ hessian, -hessian; 18 | -hessian, hessian ]; 19 | end -------------------------------------------------------------------------------- /bending_validation/UpdateXV.m: -------------------------------------------------------------------------------- 1 | function [x, vdt] = UpdateXV(x, vdt, dx, isFixedVert) 2 | 3 | for i = 1 : length(isFixedVert) 4 | idx = 3*i - 2 : 3*i; 5 | if isFixedVert(i) 6 | vdt(idx) = [0;0;0]; 7 | else 8 | x(idx) = x(idx) + dx(idx); 9 | end 10 | end 11 | end -------------------------------------------------------------------------------- /bending_validation/master_curve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/bending_validation/master_curve.png -------------------------------------------------------------------------------- /bending_validation/master_curve_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/bending_validation/master_curve_data.mat -------------------------------------------------------------------------------- /evaluation/backbones/base.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch 3 | torch.manual_seed(0) 4 | 5 | class BaseModel(nn.Module): 6 | def __init__(self, model_name, input_mean, input_std, output_mean, 7 | output_std, num_of_input, num_of_output): 8 | super(BaseModel, self).__init__() 9 | self.model_name = model_name 10 | self.num_of_input = num_of_input 11 | self.num_of_output = num_of_output 12 | 13 | self.input_mean = torch.from_numpy(input_mean) 14 | self.input_std = torch.from_numpy(input_std) 15 | self.output_mean = torch.from_numpy(output_mean) 16 | self.output_std = torch.from_numpy(output_std) 17 | 18 | assert len(output_mean) == len(output_std) and (num_of_output == 3 19 | or num_of_output == 6) 20 | if num_of_output == 6: 21 | self.lower_bound = torch.tensor([[0, 0, 0, -100, -100, -100]]) 22 | self.upper_bound = torch.tensor([[100, 100, 100, 100, 100, 100]]) 23 | elif num_of_output == 3: 24 | self.lower_bound = torch.tensor([[0, 0, 0]]) 25 | self.upper_bound = torch.tensor([[100, 100, 100]]) 26 | else: 27 | raise ValueError("the output size cannot be determined") 28 | 29 | def show_parameters(self): 30 | for name, param in self.named_parameters(): 31 | print( 32 | f"[debug] {name} {param.shape} , can be changed = {param.requires_grad}" 33 | ) 34 | 35 | def print_num_of_params(self): 36 | return 37 | 38 | def normalize_input(self, x): 39 | 40 | if self.input_mean is not None and self.input_std is not None: 41 | # print( 42 | # f"[normalize] {x.shape} {self.input_mean.shape} {self.input_std.shape}" 43 | # ) 44 | return (x - self.input_mean) / self.input_std 45 | else: 46 | return x 47 | 48 | def unnormalize_output(self, x): 49 | if self.output_std is not None and self.output_mean is not None: 50 | # print( 51 | # f"[unnormalize] {x.shape} {self.input_mean.shape} {self.input_std.shape}" 52 | # ) 53 | return x * self.output_std + self.output_mean 54 | else: 55 | return x 56 | 57 | def to(self, device): 58 | super(BaseModel, self).to(device) 59 | self.input_mean = self.input_mean.to(device) 60 | self.input_std = self.input_std.to(device) 61 | self.output_mean = self.output_mean.to(device) 62 | self.output_std = self.output_std.to(device) 63 | self.lower_bound = self.lower_bound.to(device) 64 | self.upper_bound = self.upper_bound.to(device) 65 | return self 66 | 67 | def clamp(self, x): 68 | if self.training == False: 69 | x = torch.max(torch.min(x, self.upper_bound), self.lower_bound) 70 | return x -------------------------------------------------------------------------------- /evaluation/depth_data/mesh0/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh0/0.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh0/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh0/1.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh0/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh0/2.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh0/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh0/3.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh0/density.txt: -------------------------------------------------------------------------------- 1 | data0 300 -------------------------------------------------------------------------------- /evaluation/depth_data/mesh1/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh1/0.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh1/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh1/1.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh1/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh1/2.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh1/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh1/3.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh1/density.txt: -------------------------------------------------------------------------------- 1 | data0 300 -------------------------------------------------------------------------------- /evaluation/depth_data/mesh2/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh2/0.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh2/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh2/1.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh2/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh2/2.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh2/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh2/3.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh2/density.txt: -------------------------------------------------------------------------------- 1 | mesh3 300 -------------------------------------------------------------------------------- /evaluation/depth_data/mesh3/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh3/0.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh3/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh3/1.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh3/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh3/2.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh3/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/depth_data/mesh3/3.png -------------------------------------------------------------------------------- /evaluation/depth_data/mesh3/density.txt: -------------------------------------------------------------------------------- 1 | mesh3 300 -------------------------------------------------------------------------------- /evaluation/network.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/evaluation/network.pth -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | This repo contains codes for SIGGRAPH Asia 2022 paper "Learning-Based Bending Stiffness Parameter Estimation by a Drape Tester". 2 | 3 | 1. `dataset`: The 618-fabric parameter dataset. 4 | 2. `bending_validation` : The MATLAB code for physical valudation of bending models based on [Romero 2021 et al]. 5 | 3. `arcsim`: ArcSim code with our coefficient-modified bending energy. 6 | 4. `evaluation`: The network weight for evaluating fabric's nonlinear bending stiffness. 7 | 5. `subspace`: The subspace VAE network weight and properties generation code. 8 | -------------------------------------------------------------------------------- /subspace/dataloader.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import numpy as np 3 | import os.path as osp 4 | from torch.utils.data import Dataset, DataLoader 5 | from operator import itemgetter 6 | 7 | 8 | def load_data(idx_file, data_dir): 9 | data_file = osp.join(data_dir, 'dataset.csv') 10 | with open(idx_file, 'r') as f: 11 | indices = [int(i) for i in f.readlines()] 12 | data_lst = [] 13 | with open(data_file, 'r') as f: 14 | for line in f.readlines()[1:]: 15 | line = line.strip() 16 | while line.find(" ") != -1: 17 | line = line.replace(" ", "") 18 | data_line = [float(i) for i in line.split(",")] 19 | data_lst.append(data_line) 20 | selected_data_lst = itemgetter(*indices)(data_lst) 21 | density_lst = [] 22 | prop_lst = [] 23 | 24 | for i in selected_data_lst: 25 | density_lst.append(i[0]) 26 | prop_lst.append(i[1:]) 27 | return density_lst, prop_lst 28 | 29 | 30 | def apply_log(scalar): 31 | return (1 if scalar > 0 else -1) * np.log(np.abs(scalar)) 32 | 33 | 34 | def apply_log_on_data(data): 35 | ''' 36 | warp, weft, bias, warp, weft, bias (nonlinear entries) 37 | ''' 38 | assert len(data) == 6 39 | for i in range(len(data)): 40 | data[i] = apply_log(data[i]) 41 | return data 42 | 43 | 44 | class FabricDataset(Dataset): 45 | def __init__(self, data_dir, phase_train, data_aug=10) -> None: 46 | train_file = "train.txt" 47 | test_file = "test.txt" 48 | self.feature_dim = 6 49 | # load data 50 | if phase_train == True: 51 | self.density_lst, self.prop_lst = load_data(train_file, data_dir) 52 | else: 53 | self.density_lst, self.prop_lst = load_data(test_file, data_dir) 54 | 55 | # data preprocess: apply log 56 | for idx in range(len(self.prop_lst)): 57 | # print(f"raw {self.prop_lst[idx]}") 58 | self.prop_lst[idx] = apply_log_on_data(self.prop_lst[idx]) 59 | # print(self.prop_lst[idx]) 60 | # exit() 61 | 62 | # data_augmentation by apply gaussian noise 63 | sigma = 0.05 64 | mu = 0 65 | num_of_old_data = len(self.prop_lst) 66 | for _ in range(data_aug): 67 | for idx in range(num_of_old_data): 68 | new_data = self.prop_lst[idx] + np.random.randn( 69 | len(self.prop_lst[idx])) * sigma + mu 70 | self.prop_lst.append(new_data) 71 | self.density_lst.append(self.density_lst[idx]) 72 | 73 | 74 | # convert to float 75 | for i in range(len(self.prop_lst)): 76 | self.prop_lst[i] = np.array(self.prop_lst[i], dtype=np.float32) 77 | self.density_lst[i] = float(self.density_lst[i]) 78 | 79 | def __len__(self): 80 | return len(self.prop_lst) 81 | 82 | def __getitem__(self, index): 83 | return self.prop_lst[index], 1 84 | 85 | def get_data(self): 86 | return self.prop_lst 87 | 88 | 89 | def get_dataloader(data_dir, batch_size=32, data_scale=10): 90 | train_set = FabricDataset(data_dir=data_dir, 91 | phase_train=True, 92 | data_aug=data_scale) 93 | test_set = FabricDataset(data_dir=data_dir, 94 | phase_train=False, 95 | data_aug=data_scale) 96 | 97 | train_loader = DataLoader(train_set, batch_size, shuffle=True) 98 | test_loader = DataLoader(test_set, batch_size, shuffle=True) 99 | return test_loader, train_loader 100 | 101 | 102 | if __name__ == "__main__": 103 | # 1. load dataset 104 | root_datadir = "..\subspace" 105 | train_loader, test_loader = get_dataloader(root_datadir) 106 | 107 | # 2. VAE structure 108 | 109 | # 3. VAE training 110 | 111 | # 4. save weight 112 | -------------------------------------------------------------------------------- /subspace/init_dataset.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | if __name__ == "__main__": 3 | with open("../dataset/dataset.csv") as f: 4 | num_of_data = len(f.readlines()[1:]) 5 | print(num_of_data) 6 | ratio = 0.8 7 | num_of_train = int(num_of_data * ratio) 8 | 9 | perm = np.random.permutation(num_of_data) 10 | train_indices = perm[:num_of_train] 11 | test_indices = perm[num_of_train:] 12 | 13 | 14 | with open("train.txt", 'w') as f: 15 | for i in train_indices: 16 | f.write(str(i)+"\n") 17 | print(f"output to train.txt") 18 | with open("test.txt", 'w') as f: 19 | for i in test_indices: 20 | f.write(str(i)+"\n") 21 | print(f"output to test.txt") -------------------------------------------------------------------------------- /subspace/test.txt: -------------------------------------------------------------------------------- 1 | 512 2 | 341 3 | 588 4 | 337 5 | 562 6 | 277 7 | 108 8 | 598 9 | 23 10 | 466 11 | 126 12 | 429 13 | 250 14 | 89 15 | 524 16 | 355 17 | 124 18 | 248 19 | 147 20 | 401 21 | 202 22 | 26 23 | 593 24 | 465 25 | 520 26 | 180 27 | 152 28 | 534 29 | 125 30 | 485 31 | 80 32 | 388 33 | 94 34 | 494 35 | 378 36 | 579 37 | 361 38 | 132 39 | 451 40 | 489 41 | 236 42 | 306 43 | 386 44 | 387 45 | 102 46 | 52 47 | 280 48 | 278 49 | 511 50 | 4 51 | 307 52 | 590 53 | 272 54 | 116 55 | 496 56 | 617 57 | 290 58 | 327 59 | 510 60 | 96 61 | 533 62 | 546 63 | 194 64 | 438 65 | 99 66 | 469 67 | 455 68 | 502 69 | 371 70 | 87 71 | 203 72 | 310 73 | 183 74 | 225 75 | 25 76 | 300 77 | 198 78 | 258 79 | 605 80 | 328 81 | 148 82 | 413 83 | 499 84 | 34 85 | 189 86 | 83 87 | 151 88 | 139 89 | 205 90 | 452 91 | 342 92 | 41 93 | 273 94 | 177 95 | 21 96 | 555 97 | 268 98 | 223 99 | 182 100 | 515 101 | 596 102 | 143 103 | 360 104 | 603 105 | 461 106 | 433 107 | 156 108 | 291 109 | 583 110 | 42 111 | 329 112 | 462 113 | 497 114 | 3 115 | 356 116 | 553 117 | 155 118 | 616 119 | 5 120 | 64 121 | 602 122 | 517 123 | 256 124 | 373 125 | -------------------------------------------------------------------------------- /subspace/vae.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | from torch.nn import functional as F 4 | 5 | K = 128 6 | bot_dim = K // 8 # 32 7 | 8 | class VAE(nn.Module): 9 | def __init__(self, feature_dim): 10 | super(VAE, self).__init__() 11 | self.feature_dim = feature_dim 12 | self.en_fc0 = nn.Linear(feature_dim, K) 13 | self.en_fc1 = nn.Linear(K, K // 2) 14 | self.en_fc2 = nn.Linear(K // 2, K // 4) 15 | self.en_fc31 = nn.Linear(K // 4, K // bot_dim) 16 | self.en_fc32 = nn.Linear(K // 4, K // bot_dim) 17 | 18 | self.de_fc0 = nn.Linear(K // bot_dim, K // 4) 19 | self.de_fc1 = nn.Linear(K // 4, K // 2) 20 | self.de_fc2 = nn.Linear(K // 2, K) 21 | self.de_fc3 = nn.Linear(K, feature_dim) 22 | 23 | def encode(self, x): 24 | x = F.selu(self.en_fc0(x)) 25 | x = F.selu(self.en_fc1(x)) 26 | x = F.selu(self.en_fc2(x)) 27 | 28 | return self.en_fc31(x), self.en_fc32(x) 29 | 30 | def reparameterize(self, mu, logvar): 31 | std = torch.exp(0.5 * logvar) 32 | eps = torch.randn_like(std) 33 | return mu + eps * std 34 | 35 | def decode(self, z): 36 | z = F.selu(self.de_fc0(z)) 37 | z = F.selu(self.de_fc1(z)) 38 | z = F.selu(self.de_fc2(z)) 39 | z = self.de_fc3(z) 40 | return z 41 | 42 | def forward(self, x): 43 | mu, logvar = self.encode(x.view(-1, self.feature_dim)) 44 | z = self.reparameterize(mu, logvar) 45 | return self.decode(z), mu, logvar 46 | -------------------------------------------------------------------------------- /subspace/vae_subspace.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrapeTester/ClothDrapeTester/24a980c0c78da5cc4af36c8b6e67326b96a1de8f/subspace/vae_subspace.pkl --------------------------------------------------------------------------------