-/*\r
- * building material information\r
- *\r
- * License : The MIT License\r
- * Copyright(c) 2010 MikuToga Partners\r
- */\r
-\r
-package jp.sourceforge.mikutoga.pmd.pmdloader;\r
-\r
-import jp.sourceforge.mikutoga.corelib.ListUtil;\r
-import java.awt.Color;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import jp.sourceforge.mikutoga.parser.ParseStage;\r
-import jp.sourceforge.mikutoga.parser.pmd.PmdMaterialHandler;\r
-import jp.sourceforge.mikutoga.pmd.Material;\r
-import jp.sourceforge.mikutoga.pmd.PmdModel;\r
-import jp.sourceforge.mikutoga.pmd.ShadeInfo;\r
-import jp.sourceforge.mikutoga.pmd.Surface;\r
-import jp.sourceforge.mikutoga.pmd.ToonMap;\r
-\r
-/**\r
- * マテリアル素材関連の通知をパーサから受け取る。\r
- */\r
-class MaterialBuilder implements PmdMaterialHandler {\r
-\r
- private final List<Material> materialList;\r
- private Iterator<Material> materialIt;\r
- private Material currentMaterial = null;\r
-\r
- private final List<Surface> surfacelList;\r
- private Iterator<Surface> surfaceIt;\r
-\r
- private final ToonMap toonMap;\r
-\r
- /**\r
- * コンストラクタ。\r
- * @param model モデル\r
- */\r
- MaterialBuilder(PmdModel model){\r
- super();\r
-\r
- this.materialList = model.getMaterialList();\r
- this.surfacelList = model.getSurfaceList();\r
- this.toonMap = model.getToonMap();\r
-\r
- return;\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * @param stage {@inheritDoc}\r
- * @param loops {@inheritDoc}\r
- */\r
- @Override\r
- public void loopStart(ParseStage stage, int loops){\r
- assert stage == PmdMaterialHandler.MATERIAL_LIST;\r
-\r
- ListUtil.prepareDefConsList(this.materialList, Material.class, loops);\r
-\r
- this.materialIt = this.materialList.iterator();\r
- if(this.materialIt.hasNext()){\r
- this.currentMaterial = this.materialIt.next();\r
- }\r
-\r
- this.surfaceIt = this.surfacelList.iterator();\r
-\r
- return;\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * @param stage {@inheritDoc}\r
- */\r
- @Override\r
- public void loopNext(ParseStage stage){\r
- assert stage == PmdMaterialHandler.MATERIAL_LIST;\r
-\r
- if(this.materialIt.hasNext()){\r
- this.currentMaterial = this.materialIt.next();\r
- }\r
-\r
- return;\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * @param stage {@inheritDoc}\r
- */\r
- @Override\r
- public void loopEnd(ParseStage stage){\r
- assert stage == PmdMaterialHandler.MATERIAL_LIST;\r
- return;\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * @param red {@inheritDoc}\r
- * @param green {@inheritDoc}\r
- * @param blue {@inheritDoc}\r
- * @param alpha {@inheritDoc}\r
- */\r
- @Override\r
- public void pmdMaterialDiffuse(float red,\r
- float green,\r
- float blue,\r
- float alpha ){\r
- Color diffuse = new Color(red, green, blue, alpha);\r
- this.currentMaterial.setDiffuseColor(diffuse);\r
- return;\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * @param red {@inheritDoc}\r
- * @param green {@inheritDoc}\r
- * @param blue {@inheritDoc}\r
- */\r
- @Override\r
- public void pmdMaterialAmbient(float red,\r
- float green,\r
- float blue ){\r
- Color ambient = new Color(red, green, blue);\r
- this.currentMaterial.setAmbientColor(ambient);\r
- return;\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * @param red {@inheritDoc}\r
- * @param green {@inheritDoc}\r
- * @param blue {@inheritDoc}\r
- * @param shininess {@inheritDoc}\r
- */\r
- @Override\r
- public void pmdMaterialSpecular(float red,\r
- float green,\r
- float blue,\r
- float shininess ){\r
- Color specular = new Color(red, green, blue);\r
- this.currentMaterial.setSpecularColor(specular);\r
- this.currentMaterial.setShininess(shininess);\r
- return;\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * @param hasEdge {@inheritDoc}\r
- * @param vertexNum {@inheritDoc}\r
- */\r
- @Override\r
- public void pmdMaterialInfo(boolean hasEdge, int vertexNum){\r
- this.currentMaterial.setEdgeAppearance(hasEdge);\r
-\r
- List<Surface> list = this.currentMaterial.getSurfaceList();\r
-\r
- int surfaceNum = vertexNum / 3;\r
- for(int ct = 1; ct <= surfaceNum; ct++){\r
- Surface surface = this.surfaceIt.next();\r
- list.add(surface);\r
- }\r
-\r
- return;\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * @param toonIdx {@inheritDoc}\r
- * @param textureFile {@inheritDoc}\r
- * @param sphereFile {@inheritDoc}\r
- */\r
- @Override\r
- public void pmdMaterialShading(int toonIdx,\r
- String textureFile,\r
- String sphereFile ){\r
- ShadeInfo info = this.currentMaterial.getShadeInfo();\r
-\r
- ToonMap map = this.toonMap;\r
-\r
- info.setToonMap(map);\r
- info.setToonIndex(toonIdx);\r
- info.setTextureFileName(textureFile);\r
- info.setSpheremapFileName(sphereFile);\r
-\r
- return;\r
- }\r
-\r
-}\r
+/*
+ * building material information
+ *
+ * License : The MIT License
+ * Copyright(c) 2010 MikuToga Partners
+ */
+
+package jp.sourceforge.mikutoga.pmd.pmdloader;
+
+import java.awt.Color;
+import java.util.Iterator;
+import java.util.List;
+import jp.sourceforge.mikutoga.corelib.ListUtil;
+import jp.sourceforge.mikutoga.parser.ParseStage;
+import jp.sourceforge.mikutoga.parser.pmd.PmdMaterialHandler;
+import jp.sourceforge.mikutoga.pmd.model.Material;
+import jp.sourceforge.mikutoga.pmd.model.PmdModel;
+import jp.sourceforge.mikutoga.pmd.model.ShadeInfo;
+import jp.sourceforge.mikutoga.pmd.model.Surface;
+import jp.sourceforge.mikutoga.pmd.model.ToonMap;
+
+/**
+ * マテリアル素材関連の通知をパーサから受け取る。
+ */
+class MaterialBuilder implements PmdMaterialHandler {
+
+ private final List<Material> materialList;
+ private Iterator<Material> materialIt;
+ private Material currentMaterial = null;
+
+ private final List<Surface> surfacelList;
+ private Iterator<Surface> surfaceIt;
+
+ private final ToonMap toonMap;
+
+ /**
+ * コンストラクタ。
+ * @param model モデル
+ */
+ MaterialBuilder(PmdModel model){
+ super();
+
+ this.materialList = model.getMaterialList();
+ this.surfacelList = model.getSurfaceList();
+ this.toonMap = model.getToonMap();
+
+ return;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @param stage {@inheritDoc}
+ * @param loops {@inheritDoc}
+ */
+ @Override
+ public void loopStart(ParseStage stage, int loops){
+ assert stage == PmdMaterialHandler.MATERIAL_LIST;
+
+ ListUtil.prepareDefConsList(this.materialList, Material.class, loops);
+
+ this.materialIt = this.materialList.iterator();
+ if(this.materialIt.hasNext()){
+ this.currentMaterial = this.materialIt.next();
+ }
+
+ this.surfaceIt = this.surfacelList.iterator();
+
+ return;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @param stage {@inheritDoc}
+ */
+ @Override
+ public void loopNext(ParseStage stage){
+ assert stage == PmdMaterialHandler.MATERIAL_LIST;
+
+ if(this.materialIt.hasNext()){
+ this.currentMaterial = this.materialIt.next();
+ }
+
+ return;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @param stage {@inheritDoc}
+ */
+ @Override
+ public void loopEnd(ParseStage stage){
+ assert stage == PmdMaterialHandler.MATERIAL_LIST;
+ return;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @param red {@inheritDoc}
+ * @param green {@inheritDoc}
+ * @param blue {@inheritDoc}
+ * @param alpha {@inheritDoc}
+ */
+ @Override
+ public void pmdMaterialDiffuse(float red,
+ float green,
+ float blue,
+ float alpha ){
+ Color diffuse = new Color(red, green, blue, alpha);
+ this.currentMaterial.setDiffuseColor(diffuse);
+ return;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @param red {@inheritDoc}
+ * @param green {@inheritDoc}
+ * @param blue {@inheritDoc}
+ */
+ @Override
+ public void pmdMaterialAmbient(float red,
+ float green,
+ float blue ){
+ Color ambient = new Color(red, green, blue);
+ this.currentMaterial.setAmbientColor(ambient);
+ return;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @param red {@inheritDoc}
+ * @param green {@inheritDoc}
+ * @param blue {@inheritDoc}
+ * @param shininess {@inheritDoc}
+ */
+ @Override
+ public void pmdMaterialSpecular(float red,
+ float green,
+ float blue,
+ float shininess ){
+ Color specular = new Color(red, green, blue);
+ this.currentMaterial.setSpecularColor(specular);
+ this.currentMaterial.setShininess(shininess);
+ return;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @param hasEdge {@inheritDoc}
+ * @param vertexNum {@inheritDoc}
+ */
+ @Override
+ public void pmdMaterialInfo(boolean hasEdge, int vertexNum){
+ this.currentMaterial.setEdgeAppearance(hasEdge);
+
+ List<Surface> list = this.currentMaterial.getSurfaceList();
+
+ int surfaceNum = vertexNum / 3;
+ for(int ct = 1; ct <= surfaceNum; ct++){
+ Surface surface = this.surfaceIt.next();
+ list.add(surface);
+ }
+
+ return;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @param toonIdx {@inheritDoc}
+ * @param textureFile {@inheritDoc}
+ * @param sphereFile {@inheritDoc}
+ */
+ @Override
+ public void pmdMaterialShading(int toonIdx,
+ String textureFile,
+ String sphereFile ){
+ ShadeInfo info = this.currentMaterial.getShadeInfo();
+
+ ToonMap map = this.toonMap;
+
+ info.setToonMap(map);
+ info.setToonIndex(toonIdx);
+ info.setTextureFileName(textureFile);
+ info.setSpheremapFileName(sphereFile);
+
+ return;
+ }
+
+}