2 * building material information
4 * License : The MIT License
5 * Copyright(c) 2010 MikuToga Partners
8 package jp.sourceforge.mikutoga.pmd.model.binio;
10 import java.awt.Color;
11 import java.util.Iterator;
12 import java.util.List;
13 import jp.sourceforge.mikutoga.pmd.model.ListUtil;
14 import jp.sourceforge.mikutoga.parser.ParseStage;
15 import jp.sourceforge.mikutoga.pmd.model.Material;
16 import jp.sourceforge.mikutoga.pmd.model.PmdModel;
17 import jp.sourceforge.mikutoga.pmd.model.ShadeInfo;
18 import jp.sourceforge.mikutoga.pmd.model.Surface;
19 import jp.sourceforge.mikutoga.pmd.model.ToonMap;
20 import jp.sourceforge.mikutoga.pmd.parser.PmdMaterialHandler;
23 * マテリアル素材関連の通知をパーサから受け取る。
25 class MaterialBuilder implements PmdMaterialHandler {
27 private final List<Material> materialList;
28 private Iterator<Material> materialIt;
29 private Material currentMaterial = null;
31 private final List<Surface> surfacelList;
32 private Iterator<Surface> surfaceIt;
34 private final ToonMap toonMap;
40 MaterialBuilder(PmdModel model){
43 this.materialList = model.getMaterialList();
44 this.surfacelList = model.getSurfaceList();
45 this.toonMap = model.getToonMap();
52 * @param stage {@inheritDoc}
53 * @param loops {@inheritDoc}
56 public void loopStart(ParseStage stage, int loops){
57 assert stage == PmdMaterialHandler.MATERIAL_LIST;
59 ListUtil.prepareDefConsList(this.materialList, Material.class, loops);
61 this.materialIt = this.materialList.iterator();
62 if(this.materialIt.hasNext()){
63 this.currentMaterial = this.materialIt.next();
66 this.surfaceIt = this.surfacelList.iterator();
73 * @param stage {@inheritDoc}
76 public void loopNext(ParseStage stage){
77 assert stage == PmdMaterialHandler.MATERIAL_LIST;
79 if(this.materialIt.hasNext()){
80 this.currentMaterial = this.materialIt.next();
88 * @param stage {@inheritDoc}
91 public void loopEnd(ParseStage stage){
92 assert stage == PmdMaterialHandler.MATERIAL_LIST;
98 * @param red {@inheritDoc}
99 * @param green {@inheritDoc}
100 * @param blue {@inheritDoc}
101 * @param alpha {@inheritDoc}
104 public void pmdMaterialDiffuse(float red,
108 Color diffuse = new Color(red, green, blue, alpha);
109 this.currentMaterial.setDiffuseColor(diffuse);
115 * @param red {@inheritDoc}
116 * @param green {@inheritDoc}
117 * @param blue {@inheritDoc}
120 public void pmdMaterialAmbient(float red,
123 Color ambient = new Color(red, green, blue);
124 this.currentMaterial.setAmbientColor(ambient);
130 * @param red {@inheritDoc}
131 * @param green {@inheritDoc}
132 * @param blue {@inheritDoc}
133 * @param shininess {@inheritDoc}
136 public void pmdMaterialSpecular(float red,
140 Color specular = new Color(red, green, blue);
141 this.currentMaterial.setSpecularColor(specular);
142 this.currentMaterial.setShininess(shininess);
148 * @param hasEdge {@inheritDoc}
149 * @param vertexNum {@inheritDoc}
152 public void pmdMaterialInfo(boolean hasEdge, int vertexNum){
153 this.currentMaterial.setEdgeAppearance(hasEdge);
155 List<Surface> list = this.currentMaterial.getSurfaceList();
157 int surfaceNum = vertexNum / 3;
158 for(int ct = 1; ct <= surfaceNum; ct++){
159 Surface surface = this.surfaceIt.next();
168 * @param toonIdx {@inheritDoc}
169 * @param textureFile {@inheritDoc}
170 * @param sphereFile {@inheritDoc}
173 public void pmdMaterialShading(int toonIdx,
176 ShadeInfo info = this.currentMaterial.getShadeInfo();
178 ToonMap map = this.toonMap;
180 info.setToonMap(map);
181 info.setToonIndex(toonIdx);
182 info.setTextureFileName(textureFile);
183 info.setSpheremapFileName(sphereFile);