2 * building material information
\r
4 * License : The MIT License
\r
5 * Copyright(c) 2010 MikuToga Partners
\r
8 package jp.sourceforge.mikutoga.pmd.pmdloader;
\r
10 import jp.sourceforge.mikutoga.corelib.ListUtil;
\r
11 import java.awt.Color;
\r
12 import java.util.Iterator;
\r
13 import java.util.List;
\r
14 import jp.sourceforge.mikutoga.parser.ParseStage;
\r
15 import jp.sourceforge.mikutoga.parser.pmd.PmdMaterialHandler;
\r
16 import jp.sourceforge.mikutoga.pmd.Material;
\r
17 import jp.sourceforge.mikutoga.pmd.PmdModel;
\r
18 import jp.sourceforge.mikutoga.pmd.ShadeInfo;
\r
19 import jp.sourceforge.mikutoga.pmd.Surface;
\r
20 import jp.sourceforge.mikutoga.pmd.ToonMap;
\r
23 * マテリアル素材関連の通知をパーサから受け取る。
\r
25 class MaterialBuilder implements PmdMaterialHandler {
\r
27 private final List<Material> materialList;
\r
28 private Iterator<Material> materialIt;
\r
29 private Material currentMaterial = null;
\r
31 private final List<Surface> surfacelList;
\r
32 private Iterator<Surface> surfaceIt;
\r
34 private final ToonMap toonMap;
\r
40 MaterialBuilder(PmdModel model){
\r
43 this.materialList = model.getMaterialList();
\r
44 this.surfacelList = model.getSurfaceList();
\r
45 this.toonMap = model.getToonMap();
\r
52 * @param stage {@inheritDoc}
\r
53 * @param loops {@inheritDoc}
\r
55 public void loopStart(ParseStage stage, int loops){
\r
56 assert stage == PmdMaterialHandler.MATERIAL_LIST;
\r
58 ListUtil.prepareDefConsList(this.materialList, Material.class, loops);
\r
60 this.materialIt = this.materialList.iterator();
\r
61 if(this.materialIt.hasNext()){
\r
62 this.currentMaterial = this.materialIt.next();
\r
65 this.surfaceIt = this.surfacelList.iterator();
\r
72 * @param stage {@inheritDoc}
\r
74 public void loopNext(ParseStage stage){
\r
75 assert stage == PmdMaterialHandler.MATERIAL_LIST;
\r
77 if(this.materialIt.hasNext()){
\r
78 this.currentMaterial = this.materialIt.next();
\r
86 * @param stage {@inheritDoc}
\r
88 public void loopEnd(ParseStage stage){
\r
89 assert stage == PmdMaterialHandler.MATERIAL_LIST;
\r
95 * @param red {@inheritDoc}
\r
96 * @param green {@inheritDoc}
\r
97 * @param blue {@inheritDoc}
\r
98 * @param alpha {@inheritDoc}
\r
100 public void pmdMaterialDiffuse(float red,
\r
104 Color diffuse = new Color(red, green, blue, alpha);
\r
105 this.currentMaterial.setDiffuseColor(diffuse);
\r
111 * @param red {@inheritDoc}
\r
112 * @param green {@inheritDoc}
\r
113 * @param blue {@inheritDoc}
\r
115 public void pmdMaterialAmbient(float red,
\r
118 Color ambient = new Color(red, green, blue);
\r
119 this.currentMaterial.setAmbientColor(ambient);
\r
125 * @param red {@inheritDoc}
\r
126 * @param green {@inheritDoc}
\r
127 * @param blue {@inheritDoc}
\r
128 * @param shininess {@inheritDoc}
\r
130 public void pmdMaterialSpecular(float red,
\r
134 Color specular = new Color(red, green, blue);
\r
135 this.currentMaterial.setSpecularColor(specular);
\r
136 this.currentMaterial.setShininess(shininess);
\r
142 * @param hasEdge {@inheritDoc}
\r
143 * @param vertexNum {@inheritDoc}
\r
145 public void pmdMaterialInfo(boolean hasEdge, int vertexNum){
\r
146 this.currentMaterial.setEdgeAppearance(hasEdge);
\r
148 List<Surface> list = this.currentMaterial.getSurfaceList();
\r
150 int surfaceNum = vertexNum / 3;
\r
151 for(int ct = 1; ct <= surfaceNum; ct++){
\r
152 Surface surface = this.surfaceIt.next();
\r
161 * @param toonIdx {@inheritDoc}
\r
162 * @param textureFile {@inheritDoc}
\r
163 * @param sphereFile {@inheritDoc}
\r
165 public void pmdMaterialShading(int toonIdx,
\r
166 String textureFile,
\r
167 String sphereFile ){
\r
168 ShadeInfo info = this.currentMaterial.getShadeInfo();
\r
170 ToonMap map = this.toonMap;
\r
172 info.setToonMap(map);
\r
173 info.setToonIndex(toonIdx);
\r
174 info.setTextureFileName(textureFile);
\r
175 info.setSpheremapFileName(sphereFile);
\r