comparison thesis/cortex.org @ 469:ae10f35022ba

completed first draft of body section.
author Robert McIntyre <rlm@mit.edu>
date Fri, 28 Mar 2014 16:34:35 -0400
parents 258078f78b33
children 3401053124b0
comparison
equal deleted inserted replaced
468:258078f78b33 469:ae10f35022ba
20 #+caption: 20 #+caption:
21 #+caption: 21 #+caption:
22 #+name: name 22 #+name: name
23 #+ATTR_LaTeX: :width 10cm 23 #+ATTR_LaTeX: :width 10cm
24 [[./images/aurellem-gray.png]] 24 [[./images/aurellem-gray.png]]
25
26
27 25
28 * COMMENT Empathy and Embodiment as problem solving strategies 26 * COMMENT Empathy and Embodiment as problem solving strategies
29 27
30 By the end of this thesis, you will have seen a novel approach to 28 By the end of this thesis, you will have seen a novel approach to
31 interpreting video using embodiment and empathy. You will have also 29 interpreting video using embodiment and empathy. You will have also
443 the simulation. The cost is that =CORTEX= can sometimes run slower 441 the simulation. The cost is that =CORTEX= can sometimes run slower
444 than real time. This can also be an advantage, however --- 442 than real time. This can also be an advantage, however ---
445 simulations of very simple creatures in =CORTEX= generally run at 443 simulations of very simple creatures in =CORTEX= generally run at
446 40x on my machine! 444 40x on my machine!
447 445
448 ** What is a sense? 446 ** COMMENT What is a sense?
449 447
450 If =CORTEX= is to support a wide variety of senses, it would help 448 If =CORTEX= is to support a wide variety of senses, it would help
451 to have a better understanding of what a ``sense'' actually is! 449 to have a better understanding of what a ``sense'' actually is!
452 While vision, touch, and hearing all seem like they are quite 450 While vision, touch, and hearing all seem like they are quite
453 different things, I was supprised to learn during the course of 451 different things, I was supprised to learn during the course of
521 #+caption: density of touch sensors at the tip. 519 #+caption: density of touch sensors at the tip.
522 #+name: finger-side-view 520 #+name: finger-side-view
523 #+ATTR_LaTeX: :width 10cm 521 #+ATTR_LaTeX: :width 10cm
524 [[./images/finger-1.png]] 522 [[./images/finger-1.png]]
525 523
526
527 ** COMMENT Video game engines are a great starting point 524 ** COMMENT Video game engines are a great starting point
528 525
529 I did not need to write my own physics simulation code or shader to 526 I did not need to write my own physics simulation code or shader to
530 build =CORTEX=. Doing so would lead to a system that is impossible 527 build =CORTEX=. Doing so would lead to a system that is impossible
531 for anyone but myself to use anyway. Instead, I use a video game 528 for anyone but myself to use anyway. Instead, I use a video game
588 I chose jMonkeyEngine3 because it because it had the most features 585 I chose jMonkeyEngine3 because it because it had the most features
589 out of all the free projects I looked at, and because I could then 586 out of all the free projects I looked at, and because I could then
590 write my code in clojure, an implementation of =LISP= that runs on 587 write my code in clojure, an implementation of =LISP= that runs on
591 the JVM. 588 the JVM.
592 589
593 ** =CORTEX= uses Blender to create creature models 590 ** COMMENT =CORTEX= uses Blender to create creature models
594 591
595 For the simple worm-like creatures I will use later on in this 592 For the simple worm-like creatures I will use later on in this
596 thesis, I could define a simple API in =CORTEX= that would allow 593 thesis, I could define a simple API in =CORTEX= that would allow
597 one to create boxes, spheres, etc., and leave that API as the sole 594 one to create boxes, spheres, etc., and leave that API as the sole
598 way to create creatures. However, for =CORTEX= to truly be useful 595 way to create creatures. However, for =CORTEX= to truly be useful
625 #+caption: of muscles, ears, eyes, or joints. 622 #+caption: of muscles, ears, eyes, or joints.
626 #+name: sense-nodes 623 #+name: sense-nodes
627 #+ATTR_LaTeX: :width 10cm 624 #+ATTR_LaTeX: :width 10cm
628 [[./images/empty-sense-nodes.png]] 625 [[./images/empty-sense-nodes.png]]
629 626
630 627 ** COMMENT Bodies are composed of segments connected by joints
631 ** Bodies are composed of segments connected by joints
632 628
633 Blender is a general purpose animation tool, which has been used in 629 Blender is a general purpose animation tool, which has been used in
634 the past to create high quality movies such as Sintel 630 the past to create high quality movies such as Sintel
635 \cite{sintel}. Though Blender can model and render even complicated 631 \cite{sintel}. Though Blender can model and render even complicated
636 things like water, it is crucual to keep models that are meant to 632 things like water, it is crucual to keep models that are meant to
688 stay as one piece forever; they can be dynamically replaced with 684 stay as one piece forever; they can be dynamically replaced with
689 multiple sections to simulate splitting in two. This could be used 685 multiple sections to simulate splitting in two. This could be used
690 to simulate retractable claws or =EVE='s hands, which are able to 686 to simulate retractable claws or =EVE='s hands, which are able to
691 coalesce into one object in the movie. 687 coalesce into one object in the movie.
692 688
693 *** Solidifying/Connecting the body 689 *** Solidifying/Connecting a body
694 690
695 #+caption: View of the hand model in Blender showing the main ``joints'' 691 =CORTEX= creates a creature in two steps: first, it traverses the
696 #+caption: node (highlighted in yellow) and its children which each 692 nodes in the blender file and creates physical representations for
697 #+caption: represent a joint in the hand. Each joint node has metadata 693 any of them that have mass defined in their blender meta-data.
698 #+caption: specifying what sort of joint it is.
699 #+name: blender-hand
700 #+ATTR_LaTeX: :width 10cm
701 [[./images/hand-screenshot1.png]]
702
703 =CORTEX= creates a creature in two steps: first, it traverses the
704 nodes in the blender file and creates physical representations for
705 any of them that have mass defined.
706 694
707 #+caption: Program for iterating through the nodes in a blender file 695 #+caption: Program for iterating through the nodes in a blender file
708 #+caption: and generating physical jMonkeyEngine3 objects with mass 696 #+caption: and generating physical jMonkeyEngine3 objects with mass
709 #+caption: and a matching physics shape. 697 #+caption: and a matching physics shape.
710 #+name: name 698 #+name: name
727 (filter #(isa? (class %) Geometry ) 715 (filter #(isa? (class %) Geometry )
728 (node-seq creature))))) 716 (node-seq creature)))))
729 #+end_src 717 #+end_src
730 #+end_listing 718 #+end_listing
731 719
732 The next step to making a proper body is to connect those pieces 720 The next step to making a proper body is to connect those pieces
733 together with joints. jMonkeyEngine has a large array of joints 721 together with joints. jMonkeyEngine has a large array of joints
734 available via =bullet=, such as Point2Point, Cone, Hinge, and a 722 available via =bullet=, such as Point2Point, Cone, Hinge, and a
735 generic Six Degree of Freedom joint, with or without spring 723 generic Six Degree of Freedom joint, with or without spring
736 restitution. =CORTEX='s procedure for binding the creature together 724 restitution.
737 with joints is as follows: 725
738 726 Joints are treated a lot like proper senses, in that there is a
739 - Find the children of the "joints" node. 727 top-level empty node named ``joints'' whose children each
740 - Determine the two spatials the joint is meant to connect. 728 represent a joint.
741 - Create the joint based on the meta-data of the empty node. 729
742 730 #+caption: View of the hand model in Blender showing the main ``joints''
743 The higher order function =sense-nodes= from =cortex.sense= 731 #+caption: node (highlighted in yellow) and its children which each
744 simplifies finding the joints based on their parent ``joints'' 732 #+caption: represent a joint in the hand. Each joint node has metadata
745 node. 733 #+caption: specifying what sort of joint it is.
734 #+name: blender-hand
735 #+ATTR_LaTeX: :width 10cm
736 [[./images/hand-screenshot1.png]]
737
738
739 =CORTEX='s procedure for binding the creature together with joints
740 is as follows:
741
742 - Find the children of the ``joints'' node.
743 - Determine the two spatials the joint is meant to connect.
744 - Create the joint based on the meta-data of the empty node.
745
746 The higher order function =sense-nodes= from =cortex.sense=
747 simplifies finding the joints based on their parent ``joints''
748 node.
746 749
747 #+caption: Retrieving the children empty nodes from a single 750 #+caption: Retrieving the children empty nodes from a single
748 #+caption: named empty node is a common pattern in =CORTEX= 751 #+caption: named empty node is a common pattern in =CORTEX=
749 #+caption: further instances of this technique for the senses 752 #+caption: further instances of this technique for the senses
750 #+caption: will be omitted 753 #+caption: will be omitted
767 joints 770 joints
768 (sense-nodes "joints")) 771 (sense-nodes "joints"))
769 #+end_src 772 #+end_src
770 #+end_listing 773 #+end_listing
771 774
772 To find a joint's targets targets, =CORTEX= creates a small cube, 775 To find a joint's targets, =CORTEX= creates a small cube, centered
773 centered around the empty-node, and grows the cube exponentially 776 around the empty-node, and grows the cube exponentially until it
774 until it intersects two /physical/ objects. The objects are ordered 777 intersects two physical objects. The objects are ordered according
775 according to the joint's rotation, with the first one being the 778 to the joint's rotation, with the first one being the object that
776 object that has more negative coordinates in the joint's reference 779 has more negative coordinates in the joint's reference frame.
777 frame. Since the objects must be physical, the empty-node itself 780 Since the objects must be physical, the empty-node itself escapes
778 escapes detection. Because the objects must be physical, 781 detection. Because the objects must be physical, =joint-targets=
779 =joint-targets= must be called /after/ =physical!= is called. 782 must be called /after/ =physical!= is called.
780 783
781 #+caption: Program to find the targets of a joint node by 784 #+caption: Program to find the targets of a joint node by
782 #+caption: exponentiallly growth of a search cube. 785 #+caption: exponentiallly growth of a search cube.
783 #+name: joint-targets 786 #+name: joint-targets
784 #+begin_listing clojure 787 #+begin_listing clojure
785 #+begin_src clojure 788 #+begin_src clojure
786 (defn joint-targets 789 (defn joint-targets
787 "Return the two closest two objects to the joint object, ordered 790 "Return the two closest two objects to the joint object, ordered
788 from bottom to top according to the joint's rotation." 791 from bottom to top according to the joint's rotation."
789 [#^Node parts #^Node joint] 792 [#^Node parts #^Node joint]
790 (loop [radius (float 0.01)] 793 (loop [radius (float 0.01)]
805 (.subtract (.getWorldTranslation %) 808 (.subtract (.getWorldTranslation %)
806 (.getWorldTranslation joint))))] 809 (.getWorldTranslation joint))))]
807 (.dot (Vector3f. 1 1 1) joint-ref-frame-position)) 810 (.dot (Vector3f. 1 1 1) joint-ref-frame-position))
808 (take 2 targets)) 811 (take 2 targets))
809 (recur (float (* radius 2)))))))) 812 (recur (float (* radius 2))))))))
810 #+end_src 813 #+end_src
811 #+end_listing 814 #+end_listing
812 815
813 Once =CORTEX= finds all joints and targets, it creates them using a 816 Once =CORTEX= finds all joints and targets, it creates them using
814 simple dispatch on the metadata of the joint node. 817 a dispatch on the metadata of each joint node.
815 818
816 #+caption: Program to dispatch on blender metadata and create joints 819 #+caption: Program to dispatch on blender metadata and create joints
817 #+caption: sutiable for physical simulation. 820 #+caption: sutiable for physical simulation.
818 #+name: joint-dispatch 821 #+name: joint-dispatch
819 #+begin_listing clojure 822 #+begin_listing clojure
820 #+begin_src clojure 823 #+begin_src clojure
821 (defmulti joint-dispatch 824 (defmulti joint-dispatch
822 "Translate blender pseudo-joints into real JME joints." 825 "Translate blender pseudo-joints into real JME joints."
823 (fn [constraints & _] 826 (fn [constraints & _]
824 (:type constraints))) 827 (:type constraints)))
825 828
845 twist (:twist constraints)] 848 twist (:twist constraints)]
846 (doto (ConeJoint. control-a control-b pivot-a pivot-b 849 (doto (ConeJoint. control-a control-b pivot-a pivot-b
847 rotation rotation) 850 rotation rotation)
848 (.setLimit (float limit-xz) (float limit-xy) 851 (.setLimit (float limit-xz) (float limit-xy)
849 (float twist))))) 852 (float twist)))))
850 #+end_src 853 #+end_src
851 #+end_listing 854 #+end_listing
852 855
853 All that is left for joints it to combine the above pieces into a 856 All that is left for joints it to combine the above pieces into a
854 something that can operate on the collection of nodes that a 857 something that can operate on the collection of nodes that a
855 blender file represents. 858 blender file represents.
856 859
857 #+caption: Program to completely create a joint given information 860 #+caption: Program to completely create a joint given information
858 #+caption: from a blender file. 861 #+caption: from a blender file.
859 #+name: connect 862 #+name: connect
860 #+begin_listing clojure 863 #+begin_listing clojure
861 #+begin_src clojure 864 #+begin_src clojure
862 (defn connect 865 (defn connect
863 "Create a joint between 'obj-a and 'obj-b at the location of 866 "Create a joint between 'obj-a and 'obj-b at the location of
864 'joint. The type of joint is determined by the metadata on 'joint. 867 'joint. The type of joint is determined by the metadata on 'joint.
865 868
886 ;; when the simulation is started. 889 ;; when the simulation is started.
887 (joint-dispatch constraints 890 (joint-dispatch constraints
888 control-a control-b 891 control-a control-b
889 pivot-a pivot-b 892 pivot-a pivot-b
890 joint-rotation)))) 893 joint-rotation))))
891 #+end_src 894 #+end_src
892 #+end_listing 895 #+end_listing
893 896
894 In general, whenever =CORTEX= exposes a sense (or in this case 897 In general, whenever =CORTEX= exposes a sense (or in this case
895 physicality), it provides a function of the type =sense!=, which 898 physicality), it provides a function of the type =sense!=, which
896 takes in a collection of nodes and augments it to support that 899 takes in a collection of nodes and augments it to support that
897 sense. The function returns any controlls necessary to use that 900 sense. The function returns any controlls necessary to use that
898 sense. In this case =body!= cerates a physical body and returns no 901 sense. In this case =body!= cerates a physical body and returns no
899 control functions. 902 control functions.
900 903
901 #+caption: Program to give joints to a creature. 904 #+caption: Program to give joints to a creature.
902 #+name: name 905 #+name: name
903 #+begin_listing clojure 906 #+begin_listing clojure
904 #+begin_src clojure 907 #+begin_src clojure
905 (defn joints! 908 (defn joints!
906 "Connect the solid parts of the creature with physical joints. The 909 "Connect the solid parts of the creature with physical joints. The
907 joints are taken from the \"joints\" node in the creature." 910 joints are taken from the \"joints\" node in the creature."
908 [#^Node creature] 911 [#^Node creature]
909 (dorun 912 (dorun
917 particulars of the joints and the masses of each body part are 920 particulars of the joints and the masses of each body part are
918 determined in blender." 921 determined in blender."
919 [#^Node creature] 922 [#^Node creature]
920 (physical! creature) 923 (physical! creature)
921 (joints! creature)) 924 (joints! creature))
922 #+end_src 925 #+end_src
923 #+end_listing 926 #+end_listing
924 927
925 All of the code you have just seen amounts to only 130 lines, yet 928 All of the code you have just seen amounts to only 130 lines, yet
926 because it builds on top of Blender and jMonkeyEngine3, those few 929 because it builds on top of Blender and jMonkeyEngine3, those few
927 lines pack quite a punch! 930 lines pack quite a punch!
928 931
929 The hand from figure \ref{blender-hand}, which was modeled after my 932 The hand from figure \ref{blender-hand}, which was modeled after
930 own right hand, can now be given joints and simulated as a 933 my own right hand, can now be given joints and simulated as a
931 creature. 934 creature.
932 935
933 #+caption: With the ability to create physical creatures from blender, 936 #+caption: With the ability to create physical creatures from blender,
934 #+caption: =CORTEX= gets one step closer to a full creature simulation 937 #+caption: =CORTEX= gets one step closer to becomming a full creature
935 #+caption: environment. 938 #+caption: simulation environment.
936 #+name: name 939 #+name: name
937 #+ATTR_LaTeX: :width 15cm 940 #+ATTR_LaTeX: :width 15cm
938 [[./images/physical-hand.png]] 941 [[./images/physical-hand.png]]
939
940
941 942
942 ** Eyes reuse standard video game components 943 ** Eyes reuse standard video game components
943 944
944 ** Hearing is hard; =CORTEX= does it right 945 ** Hearing is hard; =CORTEX= does it right
945 946