└── p5f_sample ├── PBvh.pde ├── code └── BVHParser.jar ├── data ├── A_test.bvh ├── B_test.bvh └── C_test.bvh ├── lib ├── doc │ ├── allclasses-frame.html │ ├── allclasses-noframe.html │ ├── com │ │ └── rhizomatiks │ │ │ └── bvh │ │ │ ├── BvhBone.html │ │ │ ├── BvhParser.html │ │ │ ├── class-use │ │ │ ├── BvhBone.html │ │ │ └── BvhParser.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ ├── constant-values.html │ ├── deprecated-list.html │ ├── help-doc.html │ ├── index-files │ │ ├── index-1.html │ │ ├── index-10.html │ │ ├── index-11.html │ │ ├── index-2.html │ │ ├── index-3.html │ │ ├── index-4.html │ │ ├── index-5.html │ │ ├── index-6.html │ │ ├── index-7.html │ │ ├── index-8.html │ │ └── index-9.html │ ├── index.html │ ├── overview-tree.html │ ├── package-list │ ├── resources │ │ └── inherit.gif │ └── stylesheet.css └── src │ ├── BvhBone.java │ └── BvhParser.java └── p5f_sample.pde /p5f_sample/PBvh.pde: -------------------------------------------------------------------------------- 1 | public class PBvh 2 | { 3 | public BvhParser parser; 4 | 5 | public PBvh(String[] data) 6 | { 7 | parser = new BvhParser(); 8 | parser.init(); 9 | parser.parse( data ); 10 | } 11 | 12 | public void update( int ms ) 13 | { 14 | parser.moveMsTo( ms );//30-sec loop 15 | parser.update(); 16 | } 17 | 18 | public void draw() 19 | { 20 | fill(color(255)); 21 | 22 | for( BvhBone b : parser.getBones()) 23 | { 24 | pushMatrix(); 25 | translate(b.absPos.x, b.absPos.y, b.absPos.z); 26 | ellipse(0, 0, 2, 2); 27 | popMatrix(); 28 | if (!b.hasChildren()) 29 | { 30 | pushMatrix(); 31 | translate( b.absEndPos.x, b.absEndPos.y, b.absEndPos.z); 32 | ellipse(0, 0, 10, 10); 33 | popMatrix(); 34 | } 35 | 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /p5f_sample/code/BVHParser.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/code/BVHParser.jar -------------------------------------------------------------------------------- /p5f_sample/lib/doc/allclasses-frame.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/allclasses-frame.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/allclasses-noframe.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/allclasses-noframe.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/com/rhizomatiks/bvh/BvhBone.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/com/rhizomatiks/bvh/BvhBone.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/com/rhizomatiks/bvh/BvhParser.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/com/rhizomatiks/bvh/BvhParser.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/com/rhizomatiks/bvh/class-use/BvhBone.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/com/rhizomatiks/bvh/class-use/BvhBone.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/com/rhizomatiks/bvh/class-use/BvhParser.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/com/rhizomatiks/bvh/class-use/BvhParser.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/com/rhizomatiks/bvh/package-frame.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/com/rhizomatiks/bvh/package-frame.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/com/rhizomatiks/bvh/package-summary.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/com/rhizomatiks/bvh/package-summary.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/com/rhizomatiks/bvh/package-tree.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/com/rhizomatiks/bvh/package-tree.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/com/rhizomatiks/bvh/package-use.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/com/rhizomatiks/bvh/package-use.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/constant-values.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/constant-values.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/deprecated-list.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/deprecated-list.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/help-doc.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/help-doc.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-1.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-1.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-10.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-10.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-11.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-11.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-2.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-2.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-3.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-3.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-4.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-4.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-5.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-5.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-6.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-6.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-7.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-7.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-8.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-8.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index-files/index-9.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index-files/index-9.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/index.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/overview-tree.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/overview-tree.html -------------------------------------------------------------------------------- /p5f_sample/lib/doc/package-list: -------------------------------------------------------------------------------- 1 | com.rhizomatiks.bvh 2 | -------------------------------------------------------------------------------- /p5f_sample/lib/doc/resources/inherit.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/resources/inherit.gif -------------------------------------------------------------------------------- /p5f_sample/lib/doc/stylesheet.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/perfume-dev/example-processing/c1e289ad84de4092d422c2d049fd2e7e49410b9e/p5f_sample/lib/doc/stylesheet.css -------------------------------------------------------------------------------- /p5f_sample/lib/src/BvhBone.java: -------------------------------------------------------------------------------- 1 | package com.rhizomatiks.bvh; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import processing.core.PMatrix3D; 7 | import processing.core.PVector; 8 | 9 | public class BvhBone { 10 | 11 | private String _name; 12 | 13 | public PVector absPos = new PVector(); 14 | public PVector absEndPos = new PVector(); 15 | 16 | private float _offsetX = 0; 17 | private float _offsetY = 0; 18 | private float _offsetZ = 0; 19 | 20 | private int _nbChannels; 21 | private List _channels; 22 | 23 | private float _endOffsetX = 0; 24 | private float _endOffsetY = 0; 25 | private float _endOffsetZ = 0; 26 | 27 | private BvhBone _parent; 28 | private List _children; 29 | 30 | private float _Xposition = 0; 31 | private float _Yposition = 0; 32 | private float _Zposition = 0; 33 | private float _Xrotation = 0; 34 | private float _Yrotation = 0; 35 | private float _Zrotation = 0; 36 | 37 | public PMatrix3D global_matrix; 38 | 39 | public BvhBone(BvhBone __parent) 40 | { 41 | _parent = __parent; 42 | _channels = new ArrayList(); 43 | _children = new ArrayList(); 44 | } 45 | 46 | public BvhBone() 47 | { 48 | _parent = null; 49 | _channels = new ArrayList(); 50 | _children = new ArrayList(); 51 | } 52 | 53 | public String toString() 54 | { 55 | return "[BvhBone] " + _name; 56 | } 57 | 58 | public String structureToString() 59 | { 60 | return structureToString(0); 61 | } 62 | 63 | public String structureToString(int __indent) 64 | { 65 | String res = ""; 66 | for (int i = 0; i < __indent; i++) 67 | res += "="; 68 | 69 | res = res + "> " + _name + " " + _offsetX + " " + _offsetY+ " " + _offsetZ + "\n"; 70 | for (BvhBone child : _children) 71 | res += child.structureToString(__indent+1); 72 | 73 | return res; 74 | } 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | public String getName() 83 | { 84 | return _name; 85 | } 86 | 87 | public void setName( String value) 88 | { 89 | _name = value; 90 | } 91 | 92 | public Boolean isRoot() 93 | { 94 | return (_parent == null); 95 | } 96 | 97 | public Boolean hasChildren() 98 | { 99 | return _children.size() > 0; 100 | } 101 | 102 | 103 | public List getChildren() 104 | { 105 | return _children; 106 | } 107 | 108 | public void setChildren(List value) 109 | { 110 | _children = value; 111 | } 112 | 113 | public BvhBone getParent() 114 | { 115 | return _parent; 116 | } 117 | 118 | 119 | public void setParent(BvhBone value) 120 | { 121 | _parent = value; 122 | } 123 | 124 | public List getChannels() 125 | { 126 | return _channels; 127 | } 128 | 129 | public void setChannels(List value) 130 | { 131 | _channels = value; 132 | } 133 | 134 | public int getNbChannels() 135 | { 136 | return _nbChannels; 137 | } 138 | 139 | public void setnbChannels( int value ) 140 | { 141 | _nbChannels = value; 142 | } 143 | 144 | //------ position 145 | 146 | public float getZrotation() 147 | { 148 | return _Zrotation; 149 | } 150 | 151 | public void setZrotation(float value) 152 | { 153 | _Zrotation = value; 154 | } 155 | 156 | public float getYrotation() 157 | { 158 | return _Yrotation; 159 | } 160 | 161 | 162 | public void setYrotation(float value) 163 | { 164 | _Yrotation = value; 165 | } 166 | 167 | public float getXrotation() 168 | { 169 | return _Xrotation; 170 | } 171 | 172 | 173 | public void setXrotation(float value) 174 | { 175 | _Xrotation = value; 176 | } 177 | 178 | 179 | 180 | public float getZposition() 181 | { 182 | return _Zposition; 183 | } 184 | 185 | public void setZposition(float value) 186 | { 187 | _Zposition = value; 188 | } 189 | 190 | public float getYposition() 191 | { 192 | return _Yposition; 193 | } 194 | 195 | public void setYposition(float value) 196 | { 197 | _Yposition = value; 198 | } 199 | 200 | public float getXposition() 201 | { 202 | return _Xposition; 203 | } 204 | 205 | public void setXposition(float value) 206 | { 207 | _Xposition = value; 208 | } 209 | 210 | public float getEndOffsetZ() 211 | { 212 | return _endOffsetZ; 213 | } 214 | public void setEndOffsetZ(float value) 215 | { 216 | _endOffsetZ = value; 217 | } 218 | 219 | public float getEndOffsetY() 220 | { 221 | return _endOffsetY; 222 | } 223 | 224 | public void setEndOffsetY(float value) 225 | { 226 | _endOffsetY = value; 227 | } 228 | 229 | public float getEndOffsetX() 230 | { 231 | return _endOffsetX; 232 | } 233 | 234 | public void setEndOffsetX(float value) 235 | { 236 | _endOffsetX = value; 237 | } 238 | 239 | public float getOffsetZ() 240 | { 241 | return _offsetZ; 242 | } 243 | 244 | public void setOffsetZ(float value) 245 | { 246 | _offsetZ = value; 247 | } 248 | 249 | public float getOffsetY() 250 | { 251 | return _offsetY; 252 | } 253 | 254 | public void setOffsetY(float value) 255 | { 256 | _offsetY = value; 257 | } 258 | 259 | public float getOffsetX() 260 | { 261 | return _offsetX; 262 | } 263 | 264 | public void setOffsetX(float value) 265 | { 266 | _offsetX = value; 267 | } 268 | 269 | public void setAbsPosition(PVector pos) { 270 | absPos = pos; 271 | } 272 | 273 | public PVector getAbsPosition() 274 | { 275 | return absPos; 276 | } 277 | 278 | 279 | public void setAbsEndPosition( PVector pos) 280 | { 281 | absEndPos = pos; 282 | } 283 | 284 | public PVector getAbsEndPosition() 285 | { 286 | return absEndPos; 287 | } 288 | } -------------------------------------------------------------------------------- /p5f_sample/lib/src/BvhParser.java: -------------------------------------------------------------------------------- 1 | package com.rhizomatiks.bvh; 2 | import java.lang.reflect.InvocationTargetException; 3 | import java.lang.reflect.Method; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import processing.core.PApplet; 8 | import processing.core.PMatrix3D; 9 | import processing.core.PVector; 10 | 11 | public class BvhParser { 12 | 13 | private Boolean _motionLoop; 14 | 15 | private int _currentFrame = 0; 16 | 17 | private List _lines; 18 | 19 | private int _currentLine; 20 | private BvhBone _currentBone; 21 | 22 | private BvhBone _rootBone; 23 | private List> _frames; 24 | private int _nbFrames; 25 | private float _frameTime; 26 | 27 | private List _bones; 28 | 29 | public BvhParser() 30 | { 31 | _motionLoop = true; 32 | } 33 | 34 | /** 35 | * if set to True motion will loop at end 36 | */ 37 | public Boolean getMotionLoop() 38 | { 39 | return _motionLoop; 40 | } 41 | 42 | /** 43 | * set Loop state 44 | * @param value 45 | */ 46 | public void setMotionLoop(Boolean value) 47 | { 48 | _motionLoop = value; 49 | } 50 | 51 | /** 52 | * to string 53 | * @return 54 | */ 55 | public String toStr() 56 | { 57 | return _rootBone.structureToString(); 58 | } 59 | 60 | /** 61 | * get frame total 62 | * @return 63 | */ 64 | public int getNbFrames() 65 | { 66 | return _nbFrames; 67 | } 68 | 69 | /** 70 | * get bones list 71 | * @return 72 | */ 73 | public List getBones() 74 | { 75 | return _bones; 76 | } 77 | 78 | 79 | /** 80 | * call before parse BVH 81 | * create array instance 82 | * and setloopstatus true 83 | */ 84 | public void init() 85 | { 86 | _bones = new ArrayList(); 87 | _motionLoop = true; 88 | } 89 | 90 | /** 91 | * go to the frame at index 92 | */ 93 | public void moveFrameTo(int __index) 94 | { 95 | if(!_motionLoop) 96 | { 97 | if(__index >= _nbFrames) 98 | _currentFrame = _nbFrames-1;//last frame 99 | }else{ 100 | while (__index >= _nbFrames) 101 | __index -= _nbFrames; 102 | _currentFrame = __index; //looped frame 103 | } 104 | _updateFrame(); 105 | } 106 | 107 | /** 108 | * go to millisecond of the BVH 109 | * @param mills millisecond 110 | * @param loopSec the default loopsec for 111 | */ 112 | public void moveMsTo( int mills ) 113 | { 114 | float frameTime = _frameTime * 1000; 115 | int curFrame = (int)(mills / frameTime); 116 | moveFrameTo( curFrame ); 117 | } 118 | 119 | /** 120 | * update bone position and rotation 121 | */ 122 | public void update() 123 | { 124 | update( getBones().get(0) ); 125 | } 126 | 127 | protected void update(BvhBone bone ) 128 | { 129 | 130 | PMatrix3D m = new PMatrix3D(); 131 | 132 | m.translate(bone.getXposition(), bone.getYposition(), bone.getZposition()); 133 | m.translate(bone.getOffsetX(), bone.getOffsetY(), bone.getOffsetZ()); 134 | 135 | m.rotateY(PApplet.radians(bone.getYrotation())); 136 | m.rotateX(PApplet.radians(bone.getXrotation())); 137 | m.rotateZ(PApplet.radians(bone.getZrotation())); 138 | 139 | bone.global_matrix = m; 140 | 141 | if (bone.getParent() != null && bone.getParent().global_matrix != null) 142 | m.preApply(bone.getParent().global_matrix); 143 | m.mult(new PVector(), bone.getAbsPosition()); 144 | 145 | if (bone.getChildren().size() > 0) 146 | { 147 | for (BvhBone child : bone.getChildren()) 148 | { 149 | update(child); 150 | } 151 | } 152 | else 153 | { 154 | m.translate(bone.getEndOffsetX(), bone.getEndOffsetY(), bone.getEndOffsetZ()); 155 | m.mult(new PVector(), bone.getAbsEndPosition()); 156 | } 157 | } 158 | 159 | 160 | private void _updateFrame() 161 | { 162 | if (_currentFrame >= _frames.size()) return; 163 | List frame = _frames.get(_currentFrame); 164 | int count = 0; 165 | for (float n : frame) 166 | { 167 | BvhBone bone = _getBoneInFrameAt(count); 168 | String prop = _getBonePropInFrameAt(count); 169 | if(bone != null) { 170 | Method getterMethod; 171 | try { 172 | getterMethod = bone.getClass().getDeclaredMethod("set".concat(prop), new Class[]{float.class}); 173 | getterMethod.invoke(bone, n); 174 | } catch (SecurityException e) { 175 | e.printStackTrace(); 176 | System.err.println("ERROR WHILST GETTING FRAME - 1"); 177 | } catch (NoSuchMethodException e) { 178 | e.printStackTrace(); 179 | System.err.println("ERROR WHILST GETTING FRAME - 2"); 180 | } catch (IllegalArgumentException e) { 181 | e.printStackTrace(); 182 | System.err.println("ERROR WHILST GETTING FRAME - 3"); 183 | } catch (IllegalAccessException e) { 184 | e.printStackTrace(); 185 | System.err.println("ERROR WHILST GETTING FRAME - 4"); 186 | } catch (InvocationTargetException e) { 187 | e.printStackTrace(); 188 | System.err.println("ERROR WHILST GETTING FRAME - 5"); 189 | } 190 | } 191 | count++; 192 | } 193 | } 194 | 195 | private String _getBonePropInFrameAt(int n) 196 | { 197 | int c = 0; 198 | for (BvhBone bone : _bones) 199 | { 200 | if (c + bone.getNbChannels() > n) 201 | { 202 | n -= c; 203 | return bone.getChannels().get(n); 204 | }else{ 205 | c += bone.getNbChannels(); 206 | } 207 | } 208 | return null; 209 | } 210 | 211 | private BvhBone _getBoneInFrameAt( int n) 212 | { 213 | int c = 0; 214 | for (BvhBone bone : _bones) 215 | { 216 | c += bone.getNbChannels(); 217 | if ( c > n ) 218 | return bone; 219 | } 220 | return null; 221 | } 222 | 223 | public void parse(String[] srces) 224 | { 225 | String[] linesStr = srces; 226 | // liste de BvhLines 227 | _lines = new ArrayList(); 228 | 229 | for ( String lineStr : linesStr) 230 | _lines.add(new BvhLine(lineStr)); 231 | 232 | _currentLine = 1; 233 | _rootBone = _parseBone(); 234 | 235 | // center locs 236 | //_rootBone.offsetX = _rootBone.offsetY = _rootBone.offsetZ = 0; 237 | 238 | _parseFrames(); 239 | } 240 | 241 | private void _parseFrames() 242 | { 243 | int currentLine = _currentLine; 244 | for (; currentLine < _lines.size(); currentLine++) 245 | if(_lines.get(currentLine).getLineType() == BvhLine.MOTION) break; 246 | 247 | if ( _lines.size() > currentLine) 248 | { 249 | currentLine++; //Frames 250 | _nbFrames = _lines.get(currentLine).getNbFrames(); 251 | currentLine++; //FrameTime 252 | _frameTime = _lines.get(currentLine).getFrameTime(); 253 | currentLine++; 254 | 255 | _frames = new ArrayList>(); 256 | for (; currentLine < _lines.size(); currentLine++) 257 | { 258 | _frames.add(_lines.get(currentLine).getFrames()); 259 | } 260 | } 261 | } 262 | 263 | private BvhBone _parseBone() 264 | { 265 | //_currentBone is Parent 266 | BvhBone bone = new BvhBone( _currentBone ); 267 | 268 | _bones.add(bone); 269 | 270 | bone.setName( _lines.get(_currentLine)._boneName ); //1 271 | 272 | // +2 OFFSET 273 | _currentLine++; // 2 { 274 | _currentLine++; // 3 OFFSET 275 | bone.setOffsetX( _lines.get(_currentLine).getOffsetX() ); 276 | bone.setOffsetY( _lines.get(_currentLine).getOffsetY() ); 277 | bone.setOffsetZ( _lines.get(_currentLine).getOffsetZ() ); 278 | 279 | // +3 CHANNELS 280 | _currentLine++; 281 | bone.setnbChannels( _lines.get(_currentLine).getNbChannels() ); 282 | bone.setChannels( _lines.get(_currentLine).getChannelsProps() ); 283 | 284 | // +4 JOINT or End Site or } 285 | _currentLine++; 286 | while(_currentLine < _lines.size()) 287 | { 288 | String lineType = _lines.get(_currentLine).getLineType(); 289 | if ( BvhLine.BONE.equals( lineType ) ) //JOINT or ROOT 290 | { 291 | BvhBone child = _parseBone(); //generate new BvhBONE 292 | child.setParent( bone ); 293 | bone.getChildren().add(child); 294 | } 295 | else if( BvhLine.END_SITE.equals( lineType ) ) 296 | { 297 | _currentLine++; // { 298 | _currentLine++; // OFFSET 299 | bone.setEndOffsetX( _lines.get(_currentLine).getOffsetX() ); 300 | bone.setEndOffsetY( _lines.get(_currentLine).getOffsetY() ); 301 | bone.setEndOffsetZ( _lines.get(_currentLine).getOffsetZ() ); 302 | _currentLine++; //} 303 | _currentLine++; //} 304 | return bone; 305 | } 306 | else if( BvhLine.BRACE_CLOSED.equals( lineType ) ) 307 | { 308 | return bone; //} 309 | } 310 | _currentLine++; 311 | } 312 | System.out.println("//Something strage"); 313 | return bone; 314 | } 315 | 316 | private class BvhLine 317 | { 318 | 319 | public static final String HIERARCHY = "HIERARCHY"; 320 | public static final String BONE = "BONE"; 321 | public static final String BRACE_OPEN = "BRACE_OPEN"; 322 | public static final String BRACE_CLOSED = "BRACE_CLOSED"; 323 | public static final String OFFSET = "OFFSET"; 324 | public static final String CHANNELS = "CHANNELS"; 325 | public static final String END_SITE = "END_SITE"; 326 | 327 | public static final String MOTION = "MOTION"; 328 | public static final String FRAMES = "FRAMES"; 329 | public static final String FRAME_TIME = "FRAME_TIME"; 330 | public static final String FRAME = "FRAME"; 331 | 332 | 333 | public static final String BONE_TYPE_ROOT = "ROOT"; 334 | public static final String BONE_TYPE_JOINT = "JOINT"; 335 | 336 | private String _lineStr; 337 | 338 | private String _lineType; 339 | private String _boneType; 340 | 341 | private String _boneName; 342 | private float _offsetX; 343 | private float _offsetY; 344 | private float _offsetZ; 345 | private int _nbChannels; 346 | private List _channelsProps; 347 | private int _nbFrames; 348 | private float _frameTime; 349 | private List _frames; 350 | 351 | public String toString() 352 | { 353 | return _lineStr; 354 | } 355 | 356 | private void _parse(String __lineStr) 357 | { 358 | _lineStr = __lineStr; 359 | _lineStr = _lineStr.trim(); 360 | _lineStr = _lineStr.replace("\t", ""); 361 | _lineStr = _lineStr.replace("\n", ""); 362 | _lineStr = _lineStr.replace("\r", ""); 363 | 364 | String[] words = _lineStr.split(" "); 365 | 366 | _lineType = _parseLineType(words); 367 | 368 | // 369 | if ( HIERARCHY.equals(_lineType) ) 370 | { 371 | return; 372 | } else if ( BONE.equals(_lineType) ) { 373 | _boneType = (words[0] == "ROOT") ? BONE_TYPE_ROOT : BONE_TYPE_JOINT; 374 | _boneName = words[1]; 375 | return; 376 | } else if ( OFFSET.equals(_lineType) ) { 377 | _offsetX = Float.valueOf(words[1]); 378 | _offsetY = Float.valueOf(words[2]); 379 | _offsetZ = Float.valueOf(words[3]); 380 | return; 381 | } else if ( CHANNELS.equals(_lineType) ) { 382 | _nbChannels = Integer.valueOf(words[1]); 383 | _channelsProps = new ArrayList(); 384 | for (int i = 0; i < _nbChannels; i++) 385 | _channelsProps.add(words[i+2]); 386 | return; 387 | 388 | } else if (FRAMES.equals(_lineType) ) { 389 | _nbFrames = Integer.valueOf(words[1]); 390 | return; 391 | } else if ( FRAME_TIME.equals(_lineType) ) { 392 | _frameTime = Float.valueOf(words[2]); 393 | return; 394 | } else if ( FRAME.equals(_lineType) ) { 395 | _frames = new ArrayList(); 396 | for (String word : words) _frames.add(Float.valueOf(word)); 397 | return; 398 | } else if ( END_SITE.equals(_lineType) || 399 | BRACE_OPEN.equals(_lineType) || 400 | BRACE_CLOSED.equals(_lineType) || 401 | MOTION.equals(_lineType)) { 402 | return; 403 | } 404 | } 405 | 406 | private String _parseLineType( String[] __words) { 407 | //trace("'" + __words[0] + "' : " + __words[0].length); 408 | if ( "HIERARCHY".equals(__words[ 0 ] ) ) 409 | return HIERARCHY; 410 | if ( "ROOT".equals(__words[ 0 ] ) || 411 | "JOINT".equals(__words[ 0 ] ) ) 412 | return BONE; 413 | if ( "{".equals(__words[ 0 ] ) ) 414 | return BRACE_OPEN; 415 | if ( "}".equals(__words[ 0 ] ) ) 416 | return BRACE_CLOSED; 417 | if ( "OFFSET".equals(__words[ 0 ] ) ) 418 | return OFFSET; 419 | if ( "CHANNELS".equals(__words[ 0 ] ) ) 420 | return CHANNELS; 421 | if ( "End".equals(__words[ 0 ] ) ) 422 | return END_SITE; 423 | if ( "MOTION".equals(__words[ 0 ] ) ) 424 | return MOTION; 425 | if ( "Frames:".equals(__words[ 0 ] ) ) 426 | return FRAMES; 427 | if ( "Frame".equals(__words[ 0 ] ) ) 428 | return FRAME_TIME; 429 | 430 | try { 431 | Float.parseFloat(__words[0]); //check is Parsable 432 | return FRAME; 433 | } catch ( NumberFormatException e) { 434 | e.printStackTrace(); 435 | } 436 | return null; 437 | } 438 | 439 | 440 | public BvhLine(String __lineStr) 441 | { 442 | _parse(__lineStr); 443 | } 444 | 445 | public List getFrames() 446 | { 447 | return _frames; 448 | } 449 | 450 | public float getFrameTime() 451 | { 452 | return _frameTime; 453 | } 454 | 455 | public int getNbFrames() 456 | { 457 | return _nbFrames; 458 | } 459 | 460 | public List getChannelsProps() 461 | { 462 | return _channelsProps; 463 | } 464 | 465 | public int getNbChannels() 466 | { 467 | return _nbChannels; 468 | } 469 | 470 | public float getOffsetZ() 471 | { 472 | return _offsetZ; 473 | } 474 | 475 | public float getOffsetY() 476 | { 477 | return _offsetY; 478 | } 479 | 480 | public float getOffsetX() 481 | { 482 | return _offsetX; 483 | } 484 | 485 | public String getBoneName() 486 | { 487 | return _boneName; 488 | } 489 | 490 | public String getBoneType() 491 | { 492 | return _boneType; 493 | } 494 | 495 | public String getLineType() 496 | { 497 | return _lineType; 498 | } 499 | } 500 | } 501 | -------------------------------------------------------------------------------- /p5f_sample/p5f_sample.pde: -------------------------------------------------------------------------------- 1 | BvhParser parserA = new BvhParser(); 2 | PBvh bvh1, bvh2, bvh3; 3 | 4 | 5 | public void setup() 6 | { 7 | size( 1280, 720, P3D ); 8 | background( 0 ); 9 | noStroke(); 10 | frameRate( 30 ); 11 | 12 | bvh1 = new PBvh( loadStrings( "A_test.bvh" ) ); 13 | bvh2 = new PBvh( loadStrings( "B_test.bvh" ) ); 14 | bvh3 = new PBvh( loadStrings( "C_test.bvh" ) ); 15 | 16 | loop(); 17 | } 18 | 19 | public void draw() 20 | { 21 | background( 0 ); 22 | 23 | //camera 24 | float _cos = cos(millis() / 5000.f); 25 | float _sin = sin(millis() / 5000.f); 26 | camera(width/4.f + width/4.f * _cos +200, height/2.0f-100, 550 + 150 * _sin,width/2.0f, height/2.0f, -400, 0, 1, 0); 27 | 28 | //ground 29 | fill( color( 255 )); 30 | stroke(127); 31 | line(width/2.0f, height/2.0f, -30, width/2.0f, height/2.0f, 30); 32 | stroke(127); 33 | line(width/2.0f-30, height/2.0f, 0, width/2.0f + 30, height/2.0f, 0); 34 | stroke(255); 35 | pushMatrix(); 36 | translate( width/2, height/2-10, 0); 37 | scale(-1, -1, -1); 38 | 39 | //model 40 | bvh1.update( millis() ); 41 | bvh2.update( millis() ); 42 | bvh3.update( millis() ); 43 | bvh1.draw(); 44 | bvh2.draw(); 45 | bvh3.draw(); 46 | popMatrix(); 47 | } 48 | 49 | --------------------------------------------------------------------------------