2 * Copyright (c) 2011 Kazuhiko Kobayashi
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of 'MMDLoaderJME' nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 package projectkyoto.mmd.file;
35 import java.io.BufferedInputStream;
36 import java.io.IOException;
37 import java.io.InputStream;
44 public class VMDFile {
45 private String vmdHeader; // char[30] Vocaloid Motion Data 0002
46 private String vmdModelName; // char[20]
47 private int motionCount;
48 private VMDMotion motionArray[];
49 private int skinCount;
50 private VMDSkin skinArray[];
55 public VMDFile(URL url) throws IOException {
56 read(url.openStream());
58 public VMDFile(InputStream is2) throws IOException {
61 public void read(InputStream is2) throws IOException{
62 DataInputStreamLittleEndian is = null;
64 is = new DataInputStreamLittleEndian(new BufferedInputStream(is2));
65 vmdHeader = is.readString(30);
66 if (!"Vocaloid Motion Data 0002".equals(vmdHeader)) {
67 throw new InvalidVMDFileException();
69 vmdModelName = is.readString(20);
70 motionCount = is.readInt();
71 motionArray = new VMDMotion[motionCount];
72 for(int i=0;i<motionCount;i++) {
73 motionArray[i] = new VMDMotion(is);
75 skinCount = is.readInt();
76 skinArray = new VMDSkin[skinCount];
77 for(int i=0;i<skinCount;i++) {
78 skinArray[i] = new VMDSkin(is);
88 public String toString() {
89 StringBuffer sb = new StringBuffer();
90 sb.append("{vmdHeader = ").append(vmdHeader).append("\n");
91 sb.append("vmdModelName = ").append(vmdModelName).append("\n");
92 sb.append("motionCount = ").append(motionCount).append("\n");
93 sb.append("motionArray = {\n");
94 for(VMDMotion m : motionArray) {
95 sb.append(m).append("\n");
98 sb.append("skinCount = ").append(skinCount).append("\n");
99 sb.append("skinArray = {\n");
100 for(VMDSkin skin : skinArray) {
101 sb.append(skin).append("\n");
104 return sb.toString();
107 public VMDMotion[] getMotionArray() {
111 public void setMotionArray(VMDMotion[] motionArray) {
112 this.motionArray = motionArray;
115 public int getMotionCount() {
119 public void setMotionCount(int motionCount) {
120 this.motionCount = motionCount;
123 public VMDSkin[] getSkinArray() {
127 public void setSkinArray(VMDSkin[] skinArray) {
128 this.skinArray = skinArray;
131 public int getSkinCount() {
135 public void setSkinCount(int skinCount) {
136 this.skinCount = skinCount;
139 public String getVmdHeader() {
143 public void setVmdHeader(String vmdHeader) {
144 this.vmdHeader = vmdHeader;
147 public String getVmdModelName() {
151 public void setVmdModelName(String vmdModelName) {
152 this.vmdModelName = vmdModelName;