OSDN Git Service

import文順序調整
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / pmd / pmdloader / MaterialBuilder.java
1 /*\r
2  * building material information\r
3  *\r
4  * License : The MIT License\r
5  * Copyright(c) 2010 MikuToga Partners\r
6  */\r
7 \r
8 package jp.sourceforge.mikutoga.pmd.pmdloader;\r
9 \r
10 import java.awt.Color;\r
11 import java.util.Iterator;\r
12 import java.util.List;\r
13 import jp.sourceforge.mikutoga.corelib.ListUtil;\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
21 \r
22 /**\r
23  * マテリアル素材関連の通知をパーサから受け取る。\r
24  */\r
25 class MaterialBuilder implements PmdMaterialHandler {\r
26 \r
27     private final List<Material> materialList;\r
28     private Iterator<Material> materialIt;\r
29     private Material currentMaterial = null;\r
30 \r
31     private final List<Surface> surfacelList;\r
32     private Iterator<Surface> surfaceIt;\r
33 \r
34     private final ToonMap toonMap;\r
35 \r
36     /**\r
37      * コンストラクタ。\r
38      * @param model モデル\r
39      */\r
40     MaterialBuilder(PmdModel model){\r
41         super();\r
42 \r
43         this.materialList = model.getMaterialList();\r
44         this.surfacelList = model.getSurfaceList();\r
45         this.toonMap = model.getToonMap();\r
46 \r
47         return;\r
48     }\r
49 \r
50     /**\r
51      * {@inheritDoc}\r
52      * @param stage {@inheritDoc}\r
53      * @param loops {@inheritDoc}\r
54      */\r
55     @Override\r
56     public void loopStart(ParseStage stage, int loops){\r
57         assert stage == PmdMaterialHandler.MATERIAL_LIST;\r
58 \r
59         ListUtil.prepareDefConsList(this.materialList, Material.class, loops);\r
60 \r
61         this.materialIt = this.materialList.iterator();\r
62         if(this.materialIt.hasNext()){\r
63             this.currentMaterial = this.materialIt.next();\r
64         }\r
65 \r
66         this.surfaceIt = this.surfacelList.iterator();\r
67 \r
68         return;\r
69     }\r
70 \r
71     /**\r
72      * {@inheritDoc}\r
73      * @param stage {@inheritDoc}\r
74      */\r
75     @Override\r
76     public void loopNext(ParseStage stage){\r
77         assert stage == PmdMaterialHandler.MATERIAL_LIST;\r
78 \r
79         if(this.materialIt.hasNext()){\r
80             this.currentMaterial = this.materialIt.next();\r
81         }\r
82 \r
83         return;\r
84     }\r
85 \r
86     /**\r
87      * {@inheritDoc}\r
88      * @param stage {@inheritDoc}\r
89      */\r
90     @Override\r
91     public void loopEnd(ParseStage stage){\r
92         assert stage == PmdMaterialHandler.MATERIAL_LIST;\r
93         return;\r
94     }\r
95 \r
96     /**\r
97      * {@inheritDoc}\r
98      * @param red {@inheritDoc}\r
99      * @param green {@inheritDoc}\r
100      * @param blue {@inheritDoc}\r
101      * @param alpha {@inheritDoc}\r
102      */\r
103     @Override\r
104     public void pmdMaterialDiffuse(float red,\r
105                                    float green,\r
106                                    float blue,\r
107                                    float alpha ){\r
108         Color diffuse = new Color(red, green, blue, alpha);\r
109         this.currentMaterial.setDiffuseColor(diffuse);\r
110         return;\r
111     }\r
112 \r
113     /**\r
114      * {@inheritDoc}\r
115      * @param red {@inheritDoc}\r
116      * @param green {@inheritDoc}\r
117      * @param blue {@inheritDoc}\r
118      */\r
119     @Override\r
120     public void pmdMaterialAmbient(float red,\r
121                                    float green,\r
122                                    float blue ){\r
123         Color ambient = new Color(red, green, blue);\r
124         this.currentMaterial.setAmbientColor(ambient);\r
125         return;\r
126     }\r
127 \r
128     /**\r
129      * {@inheritDoc}\r
130      * @param red {@inheritDoc}\r
131      * @param green {@inheritDoc}\r
132      * @param blue {@inheritDoc}\r
133      * @param shininess {@inheritDoc}\r
134      */\r
135     @Override\r
136     public void pmdMaterialSpecular(float red,\r
137                                     float green,\r
138                                     float blue,\r
139                                     float shininess ){\r
140         Color specular = new Color(red, green, blue);\r
141         this.currentMaterial.setSpecularColor(specular);\r
142         this.currentMaterial.setShininess(shininess);\r
143         return;\r
144     }\r
145 \r
146     /**\r
147      * {@inheritDoc}\r
148      * @param hasEdge {@inheritDoc}\r
149      * @param vertexNum {@inheritDoc}\r
150      */\r
151     @Override\r
152     public void pmdMaterialInfo(boolean hasEdge, int vertexNum){\r
153         this.currentMaterial.setEdgeAppearance(hasEdge);\r
154 \r
155         List<Surface> list = this.currentMaterial.getSurfaceList();\r
156 \r
157         int surfaceNum = vertexNum / 3;\r
158         for(int ct = 1; ct <= surfaceNum; ct++){\r
159             Surface surface = this.surfaceIt.next();\r
160             list.add(surface);\r
161         }\r
162 \r
163         return;\r
164     }\r
165 \r
166     /**\r
167      * {@inheritDoc}\r
168      * @param toonIdx {@inheritDoc}\r
169      * @param textureFile {@inheritDoc}\r
170      * @param sphereFile {@inheritDoc}\r
171      */\r
172     @Override\r
173     public void pmdMaterialShading(int toonIdx,\r
174                                    String textureFile,\r
175                                    String sphereFile ){\r
176         ShadeInfo info = this.currentMaterial.getShadeInfo();\r
177 \r
178         ToonMap map = this.toonMap;\r
179 \r
180         info.setToonMap(map);\r
181         info.setToonIndex(toonIdx);\r
182         info.setTextureFileName(textureFile);\r
183         info.setSpheremapFileName(sphereFile);\r
184 \r
185         return;\r
186     }\r
187 \r
188 }\r