2 * building material information
4 * License : The MIT License
5 * Copyright(c) 2010 MikuToga Partners
8 package jp.sfjp.mikutoga.pmd.model.binio;
10 import java.awt.Color;
11 import java.util.Iterator;
12 import java.util.List;
13 import jp.sfjp.mikutoga.bin.parser.ParseStage;
14 import jp.sfjp.mikutoga.pmd.model.ListUtil;
15 import jp.sfjp.mikutoga.pmd.model.Material;
16 import jp.sfjp.mikutoga.pmd.model.PmdModel;
17 import jp.sfjp.mikutoga.pmd.model.ShadeInfo;
18 import jp.sfjp.mikutoga.pmd.model.Surface;
19 import jp.sfjp.mikutoga.pmd.model.ToonMap;
20 import jp.sfjp.mikutoga.pmd.parser.PmdMaterialHandler;
23 * マテリアル素材関連の通知をパーサから受け取る。
25 class MaterialBuilder implements PmdMaterialHandler {
27 private static final int TRIANGLE = 3;
30 private final List<Material> materialList;
31 private Iterator<Material> materialIt;
32 private Material currentMaterial = null;
34 private final List<Surface> surfacelList;
35 private Iterator<Surface> surfaceIt;
37 private final ToonMap toonMap;
44 MaterialBuilder(PmdModel model){
47 this.materialList = model.getMaterialList();
48 this.surfacelList = model.getSurfaceList();
49 this.toonMap = model.getToonMap();
57 * @param stage {@inheritDoc}
58 * @param loops {@inheritDoc}
61 public void loopStart(ParseStage stage, int loops){
62 assert stage == PmdMaterialHandler.MATERIAL_LIST;
64 ListUtil.prepareDefConsList(this.materialList, Material.class, loops);
66 this.materialIt = this.materialList.iterator();
67 if(this.materialIt.hasNext()){
68 this.currentMaterial = this.materialIt.next();
71 this.surfaceIt = this.surfacelList.iterator();
78 * @param stage {@inheritDoc}
81 public void loopNext(ParseStage stage){
82 assert stage == PmdMaterialHandler.MATERIAL_LIST;
84 if(this.materialIt.hasNext()){
85 this.currentMaterial = this.materialIt.next();
93 * @param stage {@inheritDoc}
96 public void loopEnd(ParseStage stage){
97 assert stage == PmdMaterialHandler.MATERIAL_LIST;
103 * @param red {@inheritDoc}
104 * @param green {@inheritDoc}
105 * @param blue {@inheritDoc}
106 * @param alpha {@inheritDoc}
109 public void pmdMaterialDiffuse(float red,
113 Color diffuse = new Color(red, green, blue, alpha);
114 this.currentMaterial.setDiffuseColor(diffuse);
120 * @param red {@inheritDoc}
121 * @param green {@inheritDoc}
122 * @param blue {@inheritDoc}
125 public void pmdMaterialAmbient(float red,
128 Color ambient = new Color(red, green, blue);
129 this.currentMaterial.setAmbientColor(ambient);
135 * @param red {@inheritDoc}
136 * @param green {@inheritDoc}
137 * @param blue {@inheritDoc}
138 * @param shininess {@inheritDoc}
141 public void pmdMaterialSpecular(float red,
145 Color specular = new Color(red, green, blue);
146 this.currentMaterial.setSpecularColor(specular);
147 this.currentMaterial.setShininess(shininess);
153 * @param hasEdge {@inheritDoc}
154 * @param vertexNum {@inheritDoc}
157 public void pmdMaterialInfo(boolean hasEdge, int vertexNum){
158 this.currentMaterial.setEdgeAppearance(hasEdge);
160 List<Surface> list = this.currentMaterial.getSurfaceList();
162 int surfaceNum = vertexNum / TRIANGLE;
163 for(int ct = 1; ct <= surfaceNum; ct++){
164 Surface surface = this.surfaceIt.next();
173 * @param toonIdx {@inheritDoc}
174 * @param textureFile {@inheritDoc}
175 * @param sphereFile {@inheritDoc}
178 public void pmdMaterialShading(int toonIdx,
181 ShadeInfo info = this.currentMaterial.getShadeInfo();
183 ToonMap map = this.toonMap;
185 info.setToonMap(map);
186 info.setToonIndex(toonIdx);
187 info.setTextureFileName(textureFile);
188 info.setSpheremapFileName(sphereFile);