• R/O
  • SSH

MMDLoaderJME: 提交

Java版MikuMikuDanceライブラリ


Commit MetaInfo

修訂88ee076326edda87e499275a283851076e96f5eb (tree)
時間2011-08-02 06:31:47
作者Kazuhiko Kobayashi <chototsu_ <moushinp@yaho...>
CommiterKazuhiko Kobayashi <chototsu_

Log Message

support sphere map
support alpha bending
VMD:interporation bug fix

Change Summary

差異

diff -r 91c63f1ce937 -r 88ee076326ed src/MatDefs/pmd/pmd.frag
--- a/src/MatDefs/pmd/pmd.frag Thu Jul 28 09:37:14 2011 +0900
+++ b/src/MatDefs/pmd/pmd.frag Tue Aug 02 06:31:47 2011 +0900
@@ -1,10 +1,10 @@
11 #import "Common/ShaderLib/Optics.glsllib"
22
33 #ifdef SPHERE_MAP_A
4- uniform sampler2D m_SphereMap_a;
4+ uniform sampler2D m_SphereMap_A;
55 #endif
66 #ifdef SPHERE_MAP_H
7- uniform sampler2D m_SphereMap_h;
7+ uniform sampler2D m_SphereMap_H;
88 #endif
99
1010
@@ -61,10 +61,11 @@
6161 #ifdef USE_REFLECTION
6262 uniform float m_ReflectionPower;
6363 uniform float m_ReflectionIntensity;
64- varying vec4 refVec;
64+// varying vec4 refVec;
6565
6666 uniform ENVMAP m_EnvMap;
6767 #endif
68+ varying vec4 refVec;
6869
6970 float tangDot(in vec3 v1, in vec3 v2){
7071 float d = dot(v1,v2);
@@ -148,6 +149,7 @@
148149 vec4 diffuseColor = vec4(1.0);
149150 #endif
150151 float alpha = DiffuseSum.a * diffuseColor.a;
152+ //float alpha = (DiffuseSum.a + diffuseColor.a)/2;
151153 #ifdef ALPHAMAP
152154 alpha = alpha * texture2D(m_AlphaMap, newTexCoord).r;
153155 #endif
@@ -219,19 +221,29 @@
219221 SpecularSum2 = vec4(1.0);
220222 light.y = 1.0;
221223 #endif
222-
224+ if (isnan(light.y)) {
225+ light.y = 0;
226+ }
223227 // gl_FragColor = (AmbientSum * diffuseColor +
224228 // DiffuseSum * diffuseColor + //* light.x +
225229 // SpecularSum2 * specularColor * light.y ) * 0.8;
226- gl_FragColor = (((AmbientSum + DiffuseSum) * diffuseColor) +
227- SpecularSum2 * specularColor * light.y * 0.8) ;
230+ vec4 output_color = (((AmbientSum + DiffuseSum) * diffuseColor) +
231+ SpecularSum2 * specularColor * light.y );
228232 #ifdef SPHERE_MAP_A
229- gl_FragColor += texture2D(m_SphereMap_a, Optics_SphereCoord(reflect(normView, normal));
233+ vec2 v2 = Optics_SphereCoord(normalize(refVec.xyz));
234+ v2.y = 1 - v2.y;
235+ output_color.xyz += (texture2D(m_SphereMap_A, v2).xyz);
230236 #endif
231237 #ifdef SPHERE_MAP_H
232- gl_FragColor *= texture2D(m_SphereMap_h, Optics_SphereCoord(reflect(normView, normal));
238+ vec2 v2 = Optics_SphereCoord(normalize(refVec.xyz));
239+ v2.y = 1 - v2.y;
240+ output_color.xyz *= texture2D(m_SphereMap_H, v2).xyz;
233241 #endif
234242
235243 #endif
236- gl_FragColor.a = alpha;
244+ output_color.a = alpha;
245+ // output_color.a = diffuseColor.a;
246+
247+ // gl_FragColor = 0.5 + 0.5 * light.x;//output_color;
248+ gl_FragColor = output_color;
237249 }
diff -r 91c63f1ce937 -r 88ee076326ed src/MatDefs/pmd/pmd.j3md
--- a/src/MatDefs/pmd/pmd.j3md Thu Jul 28 09:37:14 2011 +0900
+++ b/src/MatDefs/pmd/pmd.j3md Tue Aug 02 06:31:47 2011 +0900
@@ -139,11 +139,11 @@
139139
140140 // NUM_BONES : NumBones
141141 USE_HWSKINNING
142- SPHERE_MAP_A : SphereMap_a
143- SPHERE_MAP_H : SphereMap_h
142+ SPHERE_MAP_A : SphereMap_A
143+ SPHERE_MAP_H : SphereMap_H
144144 }
145145 RenderState {
146- FaceCull Off
146+ FaceCull Back
147147 }
148148 }
149149
diff -r 91c63f1ce937 -r 88ee076326ed src/MatDefs/pmd/pmd.vert
--- a/src/MatDefs/pmd/pmd.vert Thu Jul 28 09:37:14 2011 +0900
+++ b/src/MatDefs/pmd/pmd.vert Tue Aug 02 06:31:47 2011 +0900
@@ -1,5 +1,7 @@
11 // #import "MatDefs/pmd/Skinning.glsllib"
2+#ifdef USE_HWSKINNING
23 uniform mat4 m_BoneMatrices[20];
4+#endif
35 #define ATTENUATION
46 // #define HQ_ATTENUATION
57
@@ -49,7 +51,7 @@
4951 varying vec4 vLightDir;
5052 #endif
5153
52-#ifdef USE_REFLECTION
54+// #ifdef USE_REFLECTION
5355 uniform vec3 g_CameraPosition;
5456 uniform mat4 g_WorldMatrix;
5557
@@ -74,9 +76,9 @@
7476 vec3 N = normalize( (g_WorldMatrix * vec4(normal.xyz, 0.0)).xyz );
7577
7678 refVec.xyz = reflect(I, N);
77- refVec.w = m_FresnelParams.x + m_FresnelParams.y * pow(1.0 + dot(I, N), m_FresnelParams.z);
79+ refVec.w = 1;//m_FresnelParams.x + m_FresnelParams.y * pow(1.0 + dot(I, N), m_FresnelParams.z);
7880 }
79-#endif
81+// #endif
8082
8183 // JME3 lights in world space
8284 void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
@@ -121,7 +123,7 @@
121123 attribute vec4 inBoneWeight;
122124 attribute vec4 inBoneIndices;
123125 attribute vec4 inBoneIndex;
124-
126+#ifdef USE_HWSKINNING
125127 void Skinning_Compute(inout vec4 position, inout vec4 normal){
126128 // vec4 index = inBoneIndices;
127129 vec4 index = inBoneIndex;
@@ -141,11 +143,13 @@
141143 position = newPos;
142144 normal = newNormal;
143145 }
144-
146+#endif
145147 void main(){
146148 vec4 pos = vec4(inPosition, 1.0);
147149 vec4 normal = vec4(inNormal,0.0);
150+#ifdef USE_HWSKINNING
148151 Skinning_Compute(pos, normal);
152+#endif
149153 // pos = m_BoneMatrices[0] * pos;
150154 gl_Position = g_WorldViewProjectionMatrix * pos;
151155 texCoord = inTexCoord;
@@ -214,7 +218,7 @@
214218 SpecularSum.a = light.y;
215219 #endif
216220
217- #ifdef USE_REFLECTION
221+ #if defined(USE_REFLECTION) || defined(SPHERE_MAP_A) || defined(SPHERE_MAP_A)
218222 computeRef(pos,normal);
219223 #endif
220224 }
diff -r 91c63f1ce937 -r 88ee076326ed src/MatDefs/pmd/pmd_alpha.j3md
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/MatDefs/pmd/pmd_alpha.j3md Tue Aug 02 06:31:47 2011 +0900
@@ -0,0 +1,243 @@
1+MaterialDef pmd {
2+
3+ MaterialParameters {
4+
5+ // Compute vertex lighting in the shader
6+ // For better performance
7+ Boolean VertexLighting
8+
9+ // Use more efficent algorithms to improve performance
10+ Boolean LowQuality
11+
12+ // Improve quality at the cost of performance
13+ Boolean HighQuality
14+
15+ // Output alpha from the diffuse map
16+ Boolean UseAlpha
17+
18+ // Apha threshold for fragment discarding
19+ Float AlphaDiscardThreshold
20+
21+ // Normal map is in BC5/ATI2n/LATC/3Dc compression format
22+ Boolean LATC
23+
24+ // Use the provided ambient, diffuse, and specular colors
25+ Boolean UseMaterialColors
26+
27+ // Activate shading along the tangent, instead of the normal
28+ // Requires tangent data to be available on the model.
29+ Boolean VTangent
30+
31+ // Use minnaert diffuse instead of lambert
32+ Boolean Minnaert
33+
34+ // Use ward specular instead of phong
35+ Boolean WardIso
36+
37+ // Use vertex color as an additional diffuse color.
38+ Boolean UseVertexColor
39+
40+ // Ambient color
41+ Color Ambient
42+
43+ // Diffuse color
44+ Color Diffuse : Color
45+
46+ // Specular color
47+ Color Specular
48+
49+ // Specular power/shininess
50+ Float Shininess
51+
52+ // Diffuse map
53+ Texture2D DiffuseMap
54+
55+ // Normal map
56+ Texture2D NormalMap
57+
58+ // Specular/gloss map
59+ Texture2D SpecularMap
60+
61+ // Parallax/height map
62+ Texture2D ParallaxMap
63+
64+ // Texture that specifies alpha values
65+ Texture2D AlphaMap
66+
67+ // Color ramp, will map diffuse and specular values through it.
68+ Texture2D ColorRamp
69+
70+ // Texture of the glowing parts of the material
71+ Texture2D GlowMap
72+
73+ // The glow color of the object
74+ Color GlowColor
75+
76+ // Parameters for fresnel
77+ // X = bias
78+ // Y = scale
79+ // Z = power
80+ Vector3 FresnelParams
81+
82+ // Env Map for reflection
83+ TextureCubeMap EnvMap
84+
85+ // the env map is a spheremap and not a cube map
86+ Boolean EnvMapAsSphereMap
87+
88+ Matrix4Array BoneMatrices
89+ Int NumBones
90+ Texture2D BoneParameter
91+
92+ Float EdgeSize
93+ Texture2D SphereMap_A
94+ Texture2D SphereMap_H
95+ }
96+
97+ Technique {
98+
99+ LightMode MultiPass
100+
101+ VertexShader GLSL100: MatDefs/pmd/pmd.vert
102+ FragmentShader GLSL100: MatDefs/pmd/pmd.frag
103+ // VertexShader GLSL120: MatDefs/pmd/pmd_cartoon.vert
104+ // FragmentShader GLSL120: MatDefs/pmd/pmd_cartoon.frag
105+
106+ // VertexShader GLSL100: Common/MatDefs/Light/Lighting.vert
107+ // FragmentShader GLSL100: Common/MatDefs/Light/Lighting.frag
108+
109+ WorldParameters {
110+ WorldViewProjectionMatrix
111+ NormalMatrix
112+ WorldViewMatrix
113+ ViewMatrix
114+ CameraPosition
115+ WorldMatrix
116+ }
117+
118+ Defines {
119+ LATC : LATC
120+ VERTEX_COLOR : UseVertexColor
121+ VERTEX_LIGHTING : VertexLighting
122+ ATTENUATION : Attenuation
123+ MATERIAL_COLORS : UseMaterialColors
124+ V_TANGENT : VTangent
125+ MINNAERT : Minnaert
126+ WARDISO : WardIso
127+ LOW_QUALITY : LowQuality
128+ HQ_ATTENUATION : HighQuality
129+
130+ DIFFUSEMAP : DiffuseMap
131+ NORMALMAP : NormalMap
132+ SPECULARMAP : SpecularMap
133+ PARALLAXMAP : ParallaxMap
134+ ALPHAMAP : AlphaMap
135+ COLORRAMP : ColorRamp
136+
137+ USE_REFLECTION : EnvMap
138+ SPHERE_MAP : SphereMap
139+
140+ // NUM_BONES : NumBones
141+ USE_HWSKINNING
142+ SPHERE_MAP_A : SphereMap_A
143+ SPHERE_MAP_H : SphereMap_H
144+ }
145+ RenderState {
146+ FaceCull Off
147+ }
148+ }
149+
150+
151+ Technique PreShadow {
152+
153+ // VertexShader GLSL100 : Common/MatDefs/Shadow/PreShadow.vert
154+ FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag
155+ VertexShader GLSL100: MatDefs/pmd/pmd.vert
156+
157+ WorldParameters {
158+ WorldViewProjectionMatrix
159+ WorldViewMatrix
160+ }
161+
162+ Defines {
163+ DIFFUSEMAP_ALPHA : DiffuseMap
164+ USE_HWSKINNING
165+ }
166+
167+ RenderState {
168+ FaceCull Off
169+ DepthTest On
170+ DepthWrite On
171+ PolyOffset 5 0
172+ ColorWrite Off
173+ }
174+
175+ }
176+
177+ Technique PreNormalPass {
178+
179+ VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert
180+ FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
181+
182+ WorldParameters {
183+ WorldViewProjectionMatrix
184+ WorldViewMatrix
185+ NormalMatrix
186+ }
187+
188+ Defines {
189+ DIFFUSEMAP_ALPHA : DiffuseMap
190+ }
191+
192+ RenderState {
193+
194+ }
195+
196+ }
197+
198+ Technique GBuf {
199+
200+ VertexShader GLSL100: Common/MatDefs/Light/GBuf.vert
201+ FragmentShader GLSL100: Common/MatDefs/Light/GBuf.frag
202+
203+ WorldParameters {
204+ WorldViewProjectionMatrix
205+ NormalMatrix
206+ WorldViewMatrix
207+ WorldMatrix
208+ }
209+
210+ Defines {
211+ VERTEX_COLOR : UseVertexColor
212+ MATERIAL_COLORS : UseMaterialColors
213+ V_TANGENT : VTangent
214+ MINNAERT : Minnaert
215+ WARDISO : WardIso
216+
217+ DIFFUSEMAP : DiffuseMap
218+ NORMALMAP : NormalMap
219+ SPECULARMAP : SpecularMap
220+ PARALLAXMAP : ParallaxMap
221+ }
222+ }
223+
224+ Technique FixedFunc {
225+ LightMode FixedPipeline
226+ }
227+
228+ Technique Glow {
229+
230+ VertexShader GLSL100: Common/MatDefs/Misc/SimpleTextured.vert
231+ FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
232+
233+ WorldParameters {
234+ WorldViewProjectionMatrix
235+ }
236+
237+ Defines {
238+ HAS_GLOWMAP : GlowMap
239+ HAS_GLOWCOLOR : GlowColor
240+ }
241+ }
242+
243+}
\ No newline at end of file
diff -r 91c63f1ce937 -r 88ee076326ed src/MatDefs/pmd/pmd_cartoon.frag
--- a/src/MatDefs/pmd/pmd_cartoon.frag Thu Jul 28 09:37:14 2011 +0900
+++ b/src/MatDefs/pmd/pmd_cartoon.frag Tue Aug 02 06:31:47 2011 +0900
@@ -1,3 +1,3 @@
11 void main(){
2- gl_FragColor = vec4(0.0);
2+ gl_FragColor = vec4(0,0,0,1);
33 }
diff -r 91c63f1ce937 -r 88ee076326ed src/MatDefs/pmd/pmd_cartoon.vert
--- a/src/MatDefs/pmd/pmd_cartoon.vert Thu Jul 28 09:37:14 2011 +0900
+++ b/src/MatDefs/pmd/pmd_cartoon.vert Tue Aug 02 06:31:47 2011 +0900
@@ -44,6 +44,7 @@
4444 #endif
4545
4646 void main(){
47+ if (m_EdgeSize != 0.0) {
4748 vec4 pos = vec4(inPosition, 1.0);
4849 vec4 normal = vec4(inNormal,0.0);
4950 #ifdef USE_HWSKINNING
@@ -52,4 +53,7 @@
5253 normal = normalize(normal);
5354 pos = pos + normal * m_EdgeSize;
5455 gl_Position = g_WorldViewProjectionMatrix * pos;
56+ } else {
57+ gl_Position = vec4(1000.0,1000.0,1000.0,1000.0);
58+ }
5559 }
diff -r 91c63f1ce937 -r 88ee076326ed src/MatDefs/pmd/pmd_no_skinning.j3md
--- a/src/MatDefs/pmd/pmd_no_skinning.j3md Thu Jul 28 09:37:14 2011 +0900
+++ b/src/MatDefs/pmd/pmd_no_skinning.j3md Tue Aug 02 06:31:47 2011 +0900
@@ -90,13 +90,15 @@
9090 Texture2D BoneParameter
9191
9292 Float EdgeSize
93+ Texture2D SphereMap_A
94+ Texture2D SphereMap_H
9395 }
9496
9597 Technique {
9698
9799 LightMode MultiPass
98100
99- VertexShader GLSL100: Common/MatDefs/Light/Lighting.vert
101+ VertexShader GLSL100: MatDefs/pmd/pmd.vert
100102 FragmentShader GLSL100: MatDefs/pmd/pmd.frag
101103
102104 // VertexShader GLSL100: Common/MatDefs/Light/Lighting.vert
@@ -134,7 +136,13 @@
134136 SPHERE_MAP : SphereMap
135137
136138 // NUM_BONES : NumBones
137- USE_HWSKINNING
139+ // USE_HWSKINNING
140+
141+ SPHERE_MAP_A : SphereMap_A
142+ SPHERE_MAP_H : SphereMap_H
143+ }
144+ RenderState {
145+ FaceCull Back
138146 }
139147 }
140148
diff -r 91c63f1ce937 -r 88ee076326ed src/MatDefs/pmd/pmd_no_skinning.vert
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/MatDefs/pmd/pmd_no_skinning.vert Tue Aug 02 06:31:47 2011 +0900
@@ -0,0 +1,220 @@
1+// #import "MatDefs/pmd/Skinning.glsllib"
2+uniform mat4 m_BoneMatrices[20];
3+#define ATTENUATION
4+// #define HQ_ATTENUATION
5+
6+uniform mat4 g_WorldViewProjectionMatrix;
7+uniform mat4 g_WorldViewMatrix;
8+uniform mat3 g_NormalMatrix;
9+uniform mat4 g_ViewMatrix;
10+
11+uniform vec4 m_Ambient;
12+uniform vec4 m_Diffuse;
13+uniform vec4 m_Specular;
14+uniform float m_Shininess;
15+
16+uniform vec4 g_LightColor;
17+uniform vec4 g_LightPosition;
18+uniform vec4 g_AmbientLightColor;
19+
20+varying vec2 texCoord;
21+
22+varying vec4 AmbientSum;
23+varying vec4 DiffuseSum;
24+varying vec4 SpecularSum;
25+
26+attribute vec3 inPosition;
27+attribute vec2 inTexCoord;
28+attribute vec3 inNormal;
29+
30+// uniform Sampler2D m_BoneParameter;
31+// uniform sampler2D m_BoneParameter;
32+
33+#ifdef HQ_ATTENUATION
34+ varying vec3 lightVec;
35+#endif
36+
37+#ifdef VERTEX_COLOR
38+ attribute vec4 inColor;
39+#endif
40+
41+#ifndef VERTEX_LIGHTING
42+ attribute vec4 inTangent;
43+
44+ #ifndef NORMALMAP
45+ varying vec3 vNormal;
46+ #endif
47+ varying vec3 vPosition;
48+ varying vec3 vViewDir;
49+ varying vec4 vLightDir;
50+#endif
51+
52+// #ifdef USE_REFLECTION
53+ uniform vec3 g_CameraPosition;
54+ uniform mat4 g_WorldMatrix;
55+
56+ uniform vec3 m_FresnelParams;
57+ varying vec4 refVec;
58+
59+
60+ /**
61+ * Input:
62+ * attribute inPosition
63+ * attribute inNormal
64+ * uniform g_WorldMatrix
65+ * uniform g_CameraPosition
66+ *
67+ * Output:
68+ * varying refVec
69+ */
70+ void computeRef(in vec4 position, in vec4 normal){
71+ vec3 worldPos = (g_WorldMatrix * vec4(position.xyz,1.0)).xyz;
72+
73+ vec3 I = normalize( g_CameraPosition - worldPos ).xyz;
74+ vec3 N = normalize( (g_WorldMatrix * vec4(normal.xyz, 0.0)).xyz );
75+
76+ refVec.xyz = reflect(I, N);
77+ refVec.w = 1;//m_FresnelParams.x + m_FresnelParams.y * pow(1.0 + dot(I, N), m_FresnelParams.z);
78+ }
79+// #endif
80+
81+// JME3 lights in world space
82+void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
83+ float posLight = step(0.5, color.w);
84+ vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
85+ #ifdef ATTENUATION
86+ float dist = length(tempVec);
87+ lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
88+ lightDir.xyz = tempVec / vec3(dist);
89+ #ifdef HQ_ATTENUATION
90+ lightVec = tempVec;
91+ #endif
92+ #else
93+ lightDir = vec4(normalize(tempVec), 1.0);
94+ #endif
95+}
96+
97+#ifdef VERTEX_LIGHTING
98+ float lightComputeDiffuse(in vec3 norm, in vec3 lightdir){
99+ return max(0.0, dot(norm, lightdir));
100+ }
101+
102+ float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
103+ #ifndef LOW_QUALITY
104+ vec3 H = (viewdir + lightdir) * vec3(0.5);
105+ return pow(max(dot(H, norm), 0.0), shiny);
106+ #else
107+ return 0.0;
108+ #endif
109+ }
110+
111+vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec4 wvLightPos){
112+ vec4 lightDir;
113+ lightComputeDir(wvPos, g_LightColor, wvLightPos, lightDir);
114+
115+ float diffuseFactor = lightComputeDiffuse(wvNorm, lightDir.xyz);
116+ float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, lightDir.xyz, m_Shininess);
117+ //specularFactor *= step(0.01, diffuseFactor);
118+ return vec2(diffuseFactor, specularFactor) * vec2(lightDir.w);
119+ }
120+#endif
121+attribute vec4 inBoneWeight;
122+attribute vec4 inBoneIndices;
123+attribute vec4 inBoneIndex;
124+
125+void Skinning_Compute(inout vec4 position, inout vec4 normal){
126+// vec4 index = inBoneIndices;
127+ vec4 index = inBoneIndex;
128+ vec4 weight = inBoneWeight;
129+
130+ vec4 newPos = vec4(0.0);
131+ vec4 newNormal = vec4(0.0);
132+
133+ for (float i = 0.0; i < 2.0; i += 1.0){
134+ mat4 skinMat = m_BoneMatrices[int(index.x)];
135+ newPos += weight.x * (skinMat * position);
136+ newNormal += weight.x * (skinMat * normal);
137+ index = index.yzwx;
138+ weight = weight.yzwx;
139+ }
140+
141+ position = newPos;
142+ normal = newNormal;
143+}
144+
145+void main(){
146+ vec4 pos = vec4(inPosition, 1.0);
147+ vec4 normal = vec4(inNormal,0.0);
148+// Skinning_Compute(pos, normal);
149+// pos = m_BoneMatrices[0] * pos;
150+ gl_Position = g_WorldViewProjectionMatrix * pos;
151+ texCoord = inTexCoord;
152+
153+ vec3 wvPosition = (g_WorldViewMatrix * pos).xyz;
154+ vec3 wvNormal = normalize(g_NormalMatrix * normal.xyz);
155+
156+// vec3 wvPosition = (g_WorldViewMatrix * pos).xyz;
157+// vec3 wvNormal = normalize(g_NormalMatrix * inNormal);
158+
159+ vec3 viewDir = normalize(-wvPosition);
160+
161+ //vec4 lightColor = g_LightColor[gl_InstanceID];
162+ //vec4 lightPos = g_LightPosition[gl_InstanceID];
163+ //vec4 wvLightPos = (g_ViewMatrix * vec4(lightPos.xyz, lightColor.w));
164+ //wvLightPos.w = lightPos.w;
165+
166+ vec4 wvLightPos = (g_ViewMatrix * vec4(g_LightPosition.xyz, g_LightColor.w));
167+ wvLightPos.w = g_LightPosition.w;
168+ vec4 lightColor = g_LightColor;
169+
170+ #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
171+ vec3 wvTangent = normalize(g_NormalMatrix * inTangent.xyz);
172+ vec3 wvBinormal = cross(wvNormal, wvTangent);
173+
174+ mat3 tbnMat = mat3(wvTangent, wvBinormal * -inTangent.w,wvNormal);
175+
176+ vPosition = wvPosition * tbnMat;
177+ vViewDir = viewDir * tbnMat;
178+ lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
179+ vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz;
180+ #elif !defined(VERTEX_LIGHTING)
181+ vNormal = wvNormal;
182+
183+ vPosition = wvPosition;
184+ vViewDir = viewDir;
185+
186+ lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
187+
188+ #ifdef V_TANGENT
189+ vNormal = normalize(g_NormalMatrix * inTangent.xyz);
190+ vNormal = -cross(cross(vLightDir.xyz, vNormal), vNormal);
191+ #endif
192+ #endif
193+
194+ lightColor.w = 1.0;
195+ #ifdef MATERIAL_COLORS
196+ AmbientSum = m_Ambient * g_AmbientLightColor;
197+ DiffuseSum = m_Diffuse * lightColor;
198+ SpecularSum = m_Specular * lightColor;
199+ #else
200+ AmbientSum = vec4(0.2, 0.2, 0.2, 1.0) * g_AmbientLightColor; // Default: ambient color is dark gray
201+ DiffuseSum = lightColor;
202+ SpecularSum = lightColor;
203+ #endif
204+
205+ #ifdef VERTEX_COLOR
206+ AmbientSum *= inColor;
207+ DiffuseSum *= inColor;
208+ #endif
209+
210+ #ifdef VERTEX_LIGHTING
211+ vec2 light = computeLighting(wvPosition, wvNormal, viewDir, wvLightPos);
212+
213+ AmbientSum.a = light.x;
214+ SpecularSum.a = light.y;
215+ #endif
216+
217+ #if defined(USE_REFLECTION) || defined(SPHERE_MAP_A) || defined(SPHERE_MAP_A)
218+ computeRef(pos,normal);
219+ #endif
220+}
diff -r 91c63f1ce937 -r 88ee076326ed src/MatDefs/pmd/pmd_no_skinning_alpha.j3md
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/MatDefs/pmd/pmd_no_skinning_alpha.j3md Tue Aug 02 06:31:47 2011 +0900
@@ -0,0 +1,240 @@
1+MaterialDef pmd {
2+
3+ MaterialParameters {
4+
5+ // Compute vertex lighting in the shader
6+ // For better performance
7+ Boolean VertexLighting
8+
9+ // Use more efficent algorithms to improve performance
10+ Boolean LowQuality
11+
12+ // Improve quality at the cost of performance
13+ Boolean HighQuality
14+
15+ // Output alpha from the diffuse map
16+ Boolean UseAlpha
17+
18+ // Apha threshold for fragment discarding
19+ Float AlphaDiscardThreshold
20+
21+ // Normal map is in BC5/ATI2n/LATC/3Dc compression format
22+ Boolean LATC
23+
24+ // Use the provided ambient, diffuse, and specular colors
25+ Boolean UseMaterialColors
26+
27+ // Activate shading along the tangent, instead of the normal
28+ // Requires tangent data to be available on the model.
29+ Boolean VTangent
30+
31+ // Use minnaert diffuse instead of lambert
32+ Boolean Minnaert
33+
34+ // Use ward specular instead of phong
35+ Boolean WardIso
36+
37+ // Use vertex color as an additional diffuse color.
38+ Boolean UseVertexColor
39+
40+ // Ambient color
41+ Color Ambient
42+
43+ // Diffuse color
44+ Color Diffuse : Color
45+
46+ // Specular color
47+ Color Specular
48+
49+ // Specular power/shininess
50+ Float Shininess
51+
52+ // Diffuse map
53+ Texture2D DiffuseMap
54+
55+ // Normal map
56+ Texture2D NormalMap
57+
58+ // Specular/gloss map
59+ Texture2D SpecularMap
60+
61+ // Parallax/height map
62+ Texture2D ParallaxMap
63+
64+ // Texture that specifies alpha values
65+ Texture2D AlphaMap
66+
67+ // Color ramp, will map diffuse and specular values through it.
68+ Texture2D ColorRamp
69+
70+ // Texture of the glowing parts of the material
71+ Texture2D GlowMap
72+
73+ // The glow color of the object
74+ Color GlowColor
75+
76+ // Parameters for fresnel
77+ // X = bias
78+ // Y = scale
79+ // Z = power
80+ Vector3 FresnelParams
81+
82+ // Env Map for reflection
83+ TextureCubeMap EnvMap
84+
85+ // the env map is a spheremap and not a cube map
86+ Boolean EnvMapAsSphereMap
87+
88+ Matrix4Array BoneMatrices
89+ Int NumBones
90+ Texture2D BoneParameter
91+
92+ Float EdgeSize
93+ Texture2D SphereMap_A
94+ Texture2D SphereMap_H
95+ }
96+
97+ Technique {
98+
99+ LightMode MultiPass
100+
101+ VertexShader GLSL100: MatDefs/pmd/pmd.vert
102+ FragmentShader GLSL100: MatDefs/pmd/pmd.frag
103+
104+ // VertexShader GLSL100: Common/MatDefs/Light/Lighting.vert
105+ // FragmentShader GLSL100: Common/MatDefs/Light/Lighting.frag
106+
107+ WorldParameters {
108+ WorldViewProjectionMatrix
109+ NormalMatrix
110+ WorldViewMatrix
111+ ViewMatrix
112+ CameraPosition
113+ WorldMatrix
114+ }
115+
116+ Defines {
117+ LATC : LATC
118+ VERTEX_COLOR : UseVertexColor
119+ VERTEX_LIGHTING : VertexLighting
120+ ATTENUATION : Attenuation
121+ MATERIAL_COLORS : UseMaterialColors
122+ V_TANGENT : VTangent
123+ MINNAERT : Minnaert
124+ WARDISO : WardIso
125+ LOW_QUALITY : LowQuality
126+ HQ_ATTENUATION : HighQuality
127+
128+ DIFFUSEMAP : DiffuseMap
129+ NORMALMAP : NormalMap
130+ SPECULARMAP : SpecularMap
131+ PARALLAXMAP : ParallaxMap
132+ ALPHAMAP : AlphaMap
133+ COLORRAMP : ColorRamp
134+
135+ USE_REFLECTION : EnvMap
136+ SPHERE_MAP : SphereMap
137+
138+ // NUM_BONES : NumBones
139+ // USE_HWSKINNING
140+
141+ SPHERE_MAP_A : SphereMap_A
142+ SPHERE_MAP_H : SphereMap_H
143+ }
144+ RenderState {
145+ FaceCull Off
146+ }
147+ }
148+
149+
150+ Technique PreShadow {
151+
152+ VertexShader GLSL100 : Common/MatDefs/Shadow/PreShadow.vert
153+ FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag
154+
155+ WorldParameters {
156+ WorldViewProjectionMatrix
157+ WorldViewMatrix
158+ }
159+
160+ Defines {
161+ DIFFUSEMAP_ALPHA : DiffuseMap
162+ }
163+
164+ RenderState {
165+ FaceCull Off
166+ DepthTest On
167+ DepthWrite On
168+ PolyOffset 5 0
169+ ColorWrite Off
170+ }
171+
172+ }
173+
174+ Technique PreNormalPass {
175+
176+ VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert
177+ FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
178+
179+ WorldParameters {
180+ WorldViewProjectionMatrix
181+ WorldViewMatrix
182+ NormalMatrix
183+ }
184+
185+ Defines {
186+ DIFFUSEMAP_ALPHA : DiffuseMap
187+ }
188+
189+ RenderState {
190+
191+ }
192+
193+ }
194+
195+ Technique GBuf {
196+
197+ VertexShader GLSL100: Common/MatDefs/Light/GBuf.vert
198+ FragmentShader GLSL100: Common/MatDefs/Light/GBuf.frag
199+
200+ WorldParameters {
201+ WorldViewProjectionMatrix
202+ NormalMatrix
203+ WorldViewMatrix
204+ WorldMatrix
205+ }
206+
207+ Defines {
208+ VERTEX_COLOR : UseVertexColor
209+ MATERIAL_COLORS : UseMaterialColors
210+ V_TANGENT : VTangent
211+ MINNAERT : Minnaert
212+ WARDISO : WardIso
213+
214+ DIFFUSEMAP : DiffuseMap
215+ NORMALMAP : NormalMap
216+ SPECULARMAP : SpecularMap
217+ PARALLAXMAP : ParallaxMap
218+ }
219+ }
220+
221+ Technique FixedFunc {
222+ LightMode FixedPipeline
223+ }
224+
225+ Technique Glow {
226+
227+ VertexShader GLSL100: Common/MatDefs/Misc/SimpleTextured.vert
228+ FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag
229+
230+ WorldParameters {
231+ WorldViewProjectionMatrix
232+ }
233+
234+ Defines {
235+ HAS_GLOWMAP : GlowMap
236+ HAS_GLOWCOLOR : GlowColor
237+ }
238+ }
239+
240+}
\ No newline at end of file
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/jme3/mmd/PMDLoaderGLSLSkinning2.java
--- a/src/projectkyoto/jme3/mmd/PMDLoaderGLSLSkinning2.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/jme3/mmd/PMDLoaderGLSLSkinning2.java Tue Aug 02 06:31:47 2011 +0900
@@ -32,11 +32,15 @@
3232 import com.jme3.animation.Bone;
3333 import com.jme3.animation.Skeleton;
3434 import com.jme3.asset.AssetManager;
35+import com.jme3.asset.AssetNotFoundException;
3536 import com.jme3.material.Material;
37+import com.jme3.material.RenderState.BlendMode;
38+import com.jme3.material.RenderState.FaceCullMode;
3639 import com.jme3.math.ColorRGBA;
3740 import com.jme3.math.Matrix4f;
3841 import com.jme3.math.Quaternion;
3942 import com.jme3.math.Vector3f;
43+import com.jme3.renderer.queue.RenderQueue.Bucket;
4044 import com.jme3.scene.Mesh;
4145 import com.jme3.scene.Node;
4246 import com.jme3.scene.Spatial;
@@ -44,6 +48,7 @@
4448 import com.jme3.scene.debug.SkeletonPoints;
4549 import com.jme3.scene.debug.SkeletonWire;
4650 import com.jme3.scene.shape.Box;
51+import com.jme3.shader.VarType;
4752 import com.jme3.texture.Texture;
4853 import com.jme3.util.BufferUtils;
4954 import com.jme3.util.TempVars;
@@ -51,6 +56,7 @@
5156 import java.nio.ShortBuffer;
5257 import java.util.ArrayList;
5358 import java.util.List;
59+import java.util.StringTokenizer;
5460 import projectkyoto.mmd.file.*;
5561 import projectkyoto.mmd.file.util2.MeshConverter;
5662 import projectkyoto.mmd.file.util2.MeshData;
@@ -80,6 +86,7 @@
8086 // System.out.println("vertexCount = " + model.getVertCount());
8187 // System.out.println("faceVertCount = " + model.getFaceVertCount());
8288 meshConverter = new MeshConverter(model);
89+ assetManager.registerLoader(com.jme3.texture.plugins.AWTLoader.class, "sph","spa");
8390 }
8491
8592 public PMDNode createNode(String name) {
@@ -209,9 +216,7 @@
209216 mesh.setBuffer(wb);
210217 mesh.setBuffer(ib);
211218 mesh.setBuffer(bib);
212- short[] indexArray = new short[20/*
213- * md.getBoneList().size()
214- */];
219+ short[] indexArray = new short[meshConverter.getMaxBoneSize()];
215220 for (int i = 0; i < indexArray.length; i++) {
216221 if (i < md.getBoneList().size()) {
217222 indexArray[i] = md.getBoneList().get(i).shortValue();
@@ -244,83 +249,116 @@
244249 geom.setNoSkinningMaterial(mat);
245250 }
246251 geom.setPmdMaterial(m);
252+ if (m.getMaterial().getFaceColor().getAlpha() < 1f) {
253+ geom.setQueueBucket(Bucket.Transparent);
254+ } else {
255+ geom.setQueueBucket(Bucket.Inherit);
256+ }
247257 }
248258
249259 Material createMaterial(PMDMaterial m, boolean skinning) {
250260 Material mat;
251- if (!skinning) {
252- mat = new Material(assetManager, "MatDefs/pmd/pmd_no_skinning.j3md");
261+ if (m.getMaterial().getFaceColor().getAlpha() < 1f) {
262+ if (!skinning) {
263+ mat = new Material(assetManager, "MatDefs/pmd/pmd_no_skinning_alpha.j3md");
264+ } else {
265+ mat = new Material(assetManager, "MatDefs/pmd/pmd_alpha.j3md");
266+ }
253267 } else {
254- mat = new Material(assetManager, "MatDefs/pmd/pmd.j3md");
268+ if (!skinning) {
269+ mat = new Material(assetManager, "MatDefs/pmd/pmd_no_skinning.j3md");
270+ } else {
271+ mat = new Material(assetManager, "MatDefs/pmd/pmd.j3md");
272+ }
273+ }
274+ float alpha = m.getMaterial().getFaceColor().getAlpha();
275+ if (alpha > 0.99f) {
276+ alpha = 1f;
255277 }
256278 ColorRGBA ambientColor = new ColorRGBA(m.getMaterial().getAmbientColor().getRed(),
257- m.getMaterial().getAmbientColor().getGreen(), m.getMaterial().getAmbientColor().getBlue(), 1f);
279+ m.getMaterial().getAmbientColor().getGreen(), m.getMaterial().getAmbientColor().getBlue(), alpha);
258280 ColorRGBA diffuseColor = new ColorRGBA(m.getMaterial().getFaceColor().getRed(),
259- m.getMaterial().getFaceColor().getGreen(), m.getMaterial().getFaceColor().getBlue(), m.getMaterial().getFaceColor().getAlpha());
281+ m.getMaterial().getFaceColor().getGreen(), m.getMaterial().getFaceColor().getBlue(), alpha);
260282 ColorRGBA ambientAndDiffuseColor = ambientColor.add(diffuseColor);
261283 ambientAndDiffuseColor.multLocal(0.5f);
284+ ambientAndDiffuseColor.a = alpha;
262285 mat.setBoolean("UseMaterialColors", true);
263286 mat.setColor("Ambient", ambientAndDiffuseColor);
264287 mat.setColor("Specular", new ColorRGBA(m.getMaterial().getSpecularColor().getRed(),
265- m.getMaterial().getSpecularColor().getGreen(), m.getMaterial().getSpecularColor().getBlue(), 1f));
288+ m.getMaterial().getSpecularColor().getGreen(), m.getMaterial().getSpecularColor().getBlue(), alpha));
266289 mat.setColor("Diffuse", ambientAndDiffuseColor);
267290 mat.setFloat("Shininess", m.getMaterial().getPower());
268- if (m.getTextureFileName().length() > 0 /*
269- * && m.getTextureData() != null
270- */) {
271- String fileName = m.getTextureFileName();
272- int i = fileName.indexOf("*");
273- if (i >= 0) {
274- fileName = fileName.substring(0, i);
291+ if (m.getTextureFileName().length() > 0) {
292+ StringTokenizer st = new StringTokenizer(m.getTextureFileName(), "*");
293+ System.out.println("m.getTextureFileName() = "+m.getTextureFileName());
294+ while(st.hasMoreElements()) {
295+ String fileName = st.nextToken();
296+ System.out.println("fileName = "+fileName);
297+ String s = fileName.substring(fileName.indexOf('.')+1);
298+ Texture texture = assetManager.loadTexture("Model/" + fileName /*
299+ * m.getTextureFileName()
300+ */);
301+ s = s.toLowerCase();
302+ if (s.equals("spa")) {
303+ mat.setTexture("SphereMap_A", texture);
304+ } else if (s.equals("sph")) {
305+ mat.setTexture("SphereMap_H", texture);
306+ } else {
307+// texture.setWrap(Texture.WrapMode.Repeat);
308+ mat.setTexture("DiffuseMap", texture);
309+ }
275310 }
276-// mat = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
277-
278- Texture texture = assetManager.loadTexture("Model/" + fileName /*
279- * m.getTextureFileName()
280- */);
281- texture.setWrap(Texture.WrapMode.Repeat);
282- mat.setTexture("DiffuseMap", texture);
283-// mat.setTexture("ColorMap", texture);
284311 }
285312 int toonIndex = m.getToonIndex();
286- //toonIndex +=1;
287- String toonname = "toon0.bmp";
288- switch (toonIndex) {
289- case 0:
290- toonname = "toon01.bmp";
291- break;
292- case 1:
293- toonname = "toon02.bmp";
294- break;
295- case 2:
296- toonname = "toon03.bmp";
297- break;
298- case 3:
299- toonname = "toon04.bmp";
300- break;
301- case 4:
302- toonname = "toon05.bmp";
303- break;
304- case 5:
305- toonname = "toon06.bmp";
306- break;
307- case 6:
308- toonname = "toon07.bmp";
309- break;
310- case 7:
311- toonname = "toon08.bmp";
312- break;
313- case 8:
314- toonname = "toon09.bmp";
315- break;
316- case 9:
317- toonname = "toon10.bmp";
318- break;
313+ Texture toonTexture = null;
314+ if (toonIndex >= 0) {
315+ String extToonName = model.getToonTextureList().getToonFileName()[toonIndex];
316+ try {
317+ toonTexture = assetManager.loadTexture("/Model/"+extToonName);
318+ } catch(AssetNotFoundException ex) {
319+ String toonname = null;
320+ switch (toonIndex) {
321+ case 0:
322+ toonname = "toon01.bmp";
323+ break;
324+ case 1:
325+ toonname = "toon02.bmp";
326+ break;
327+ case 2:
328+ toonname = "toon03.bmp";
329+ break;
330+ case 3:
331+ toonname = "toon04.bmp";
332+ break;
333+ case 4:
334+ toonname = "toon05.bmp";
335+ break;
336+ case 5:
337+ toonname = "toon06.bmp";
338+ break;
339+ case 6:
340+ toonname = "toon07.bmp";
341+ break;
342+ case 7:
343+ toonname = "toon08.bmp";
344+ break;
345+ case 8:
346+ toonname = "toon09.bmp";
347+ break;
348+ case 9:
349+ toonname = "toon10.bmp";
350+ break;
351+ }
352+ if (toonname != null) {
353+ toonTexture = assetManager.loadTexture("toon/" + toonname);
354+ }
355+ }
319356 }
320- Texture texture = assetManager.loadTexture("toon/" + toonname);
321- texture.setWrap(Texture.WrapAxis.S, Texture.WrapMode.EdgeClamp);
322- texture.setWrap(Texture.WrapAxis.T, Texture.WrapMode.EdgeClamp);
323- mat.setTexture("ColorRamp", texture);
357+ if (toonTexture != null) {
358+ toonTexture.setWrap(Texture.WrapAxis.S, Texture.WrapMode.EdgeClamp);
359+ toonTexture.setWrap(Texture.WrapAxis.T, Texture.WrapMode.EdgeClamp);
360+ mat.setTexture("ColorRamp", toonTexture);
361+ }
324362 if (m.getEdgeFlag() != 0 /*
325363 * && !(geom.getMesh() instanceof PMDSkinMesh)
326364 */) {
@@ -332,8 +370,19 @@
332370 // mat.setParam("VertexLighting", VarType.Int, new Integer(1));
333371 // geom.setMaterial(mat);
334372 // geom.setPmdMaterial(m);
335-// mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
373+// mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Back);
374+// mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Back);
336375 // mat.getAdditionalRenderState().setWireframe(true);
376+ if (m.getMaterial().getFaceColor().getAlpha() < 1f) {
377+ mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
378+ mat.getAdditionalRenderState().setAlphaTest(true);
379+// mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Back);
380+ } else {
381+ mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
382+// mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Back);
383+// mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
384+ mat.getAdditionalRenderState().setAlphaTest(true);
385+ }
337386 return mat;
338387 }
339388
@@ -346,9 +395,6 @@
346395 bone.setUserControl(true);
347396 Vector3f translation = new Vector3f(pmdBone.getBoneHeadPos().x, pmdBone.getBoneHeadPos().y, pmdBone.getBoneHeadPos().z);
348397 Quaternion rotation = new Quaternion();
349-// rotation.loadIdentity();
350-// translation.zero();
351-// bone.setBindTransforms(translation, rotation,new Vector3f(1,1,1));
352398 boneArray[boneIndex++] = bone;
353399 }
354400 boneIndex = 0;
@@ -365,64 +411,20 @@
365411 v1.subtractLocal(v2);
366412
367413 bone.setBindTransforms(v1, Quaternion.IDENTITY, new Vector3f(1, 1, 1));
368-// bone.setBindTransforms(v1, Quaternion.IDENTITY);
369414 } else {
370415 Vector3f v1 = temp.vect1; //new Vector3f();
371416 v1.set(pmdBone.getBoneHeadPos().x, pmdBone.getBoneHeadPos().y, pmdBone.getBoneHeadPos().z);
372417 bone.setBindTransforms(v1, Quaternion.IDENTITY, new Vector3f(1, 1, 1));
373418 }
374419
375-// boneArray[boneIndex] = bone;
376420 boneIndex++;
377421 }
378422
379423 Skeleton skeleton = new Skeleton(boneArray);
380424 PMDMesh meshes[] = meshList.toArray(new PMDMesh[meshList.size()]);
381-// skeletonControl = new PMDControl2(node, meshes,
382-// skinMeshList.toArray(new PMDSkinMesh[skinMeshList.size()]),
383-// meshConverter.getSkinMeshData().getVertexList(),
384-// skinArray,
385-// skeleton,
386-// assetManager);
387-// node.addControl(skeletonControl);
388-// skeletonControl.resetToBind();
389-// skeleton.updateWorldVectors();
390425
391426 Quaternion q = new Quaternion();
392427 q = q.fromAngleNormalAxis((float) Math.PI / 8, new Vector3f(0, 0, 1));
393- for (int i = 0; i < skeleton.getBoneCount(); i++) {
394- Bone bone = skeleton.getBone(i);
395-// if (bone.getName().equals("左髪1")) {
396-// bone.setUserControl(true);
397-//// bone.setUserTransforms(new Vector3f(0f, 0f, 0f), q, new Vector3f(0, 0, 0));
398-// bone.setUserTransforms(new Vector3f(0f, 0f, 0f), q, Vector3f.ZERO);
399-// }
400-// if (bone.getName().equals("首")) {
401-// bone.setUserControl(true);
402-//// bone.setUserTransforms(new Vector3f(0f, 0f, 0f), q, new Vector3f(0, 0, 0));
403-//// bone.setUserTransforms(new Vector3f(0f, 0f, 0f), q, Vector3f.ZERO);
404-// }
405-// if (bone.getName().equals("上半身")) {
406-// bone.setUserControl(true);
407-// bone.setUserTransforms(new Vector3f(0f, 0f, 0f), q, new Vector3f(0, 0, 0));
408-// bone.setUserTransforms(new Vector3f(0f, 0f, 0f), q, Vector3f.ZERO);
409-// }
410-// if (bone.getName().equals("右ひじ")) {
411-// bone.setUserControl(true);
412-// bone.setUserTransforms(new Vector3f(0f, 0f, 0f), q, new Vector3f(0, 0, 0));
413-// bone.setUserTransforms(new Vector3f(0f, 0f, 0f), q, Vector3f.ZERO);
414-// }
415-// if (bone.getName().equals("右ひじ")) {
416-// bone.setUserControl(true);
417-// bone.setUserTransforms(new Vector3f(0f, 0f, 0f), q, new Vector3f(0, 0, 0));
418-// bone.setUserTransforms(new Vector3f(0f, 0f, 0f), q, Vector3f.ZERO);
419-// }
420- }
421-// skeletonControl.setSkinWeight("笑い", 1f);
422-// skeletonControl.setSkinWeight("あ", 1f);
423-// skeletonControl.setSkinWeight("困る", 1f);
424-
425-// skeleton.setBindingPose();
426428 node.skeleton = skeleton;
427429 }
428430
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/jme3/mmd/PMDNode.java
--- a/src/projectkyoto/jme3/mmd/PMDNode.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/jme3/mmd/PMDNode.java Tue Aug 02 06:31:47 2011 +0900
@@ -303,11 +303,13 @@
303303
304304 for (Skin skin : skinMap.values()) {
305305 if (skin.isUpdateNeeded()) {
306- for (PMDSkinVertData svd : skin.getSkinData().getSkinVertData()) {
307- javax.vecmath.Vector3f dist = skinPosArray[svd.getSkinVertIndex()];
308- dist.set(svd.getSkinVertPos());
309- dist.scale(skin.getWeight());
310- dist.add(skinPosArrayOrig[svd.getSkinVertIndex()]);
306+ if (skin.getWeight() != 1f) {
307+ for (PMDSkinVertData svd : skin.getSkinData().getSkinVertData()) {
308+ javax.vecmath.Vector3f dist = skinPosArray[svd.getSkinVertIndex()];
309+ dist.set(svd.getSkinVertPos());
310+ dist.scale(skin.getWeight());
311+ dist.add(skinPosArrayOrig[svd.getSkinVertIndex()]);
312+ }
311313 }
312314 skin.setUpdateNeeded(false);
313315 }
@@ -315,10 +317,10 @@
315317
316318 fvb.position(0);
317319 fnb.position(0);
320+ TempVars vars = TempVars.get();
318321 for (int i = 0; i < skinPosArray.length; i++) {
319322 int idxWeights = 0;
320323
321- TempVars vars = TempVars.get();
322324 float[] posBuf = vars.skinPositions;
323325 float[] normBuf = vars.skinNormals;
324326
@@ -355,8 +357,8 @@
355357
356358 fnb.put(rnx).put(rny).put(rnz);
357359 fvb.put(rx).put(ry).put(rz);
358- vars.release();
359360 }
361+ vars.release();
360362 vb.setUpdateNeeded();
361363 nb.setUpdateNeeded();
362364 }
@@ -582,7 +584,6 @@
582584 // bullet physics
583585 // PMDRigidBody rigidBodyArray[];
584586
585-
586587 void initMaterials() {
587588 for (Spatial sp : getChildren()) {
588589 if (sp instanceof PMDGeometry) {
@@ -610,7 +611,6 @@
610611 // PMDRigidBody createRigidBody(projectkyoto.mmd.file.PMDRigidBody fileRigidBody, Bone bone) {
611612 // return null;
612613 // }
613-
614614 public boolean isGlslSkinning() {
615615 return glslSkinning;
616616 }
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/jme3/mmd/RigidBodyConverter.java
--- a/src/projectkyoto/jme3/mmd/RigidBodyConverter.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/jme3/mmd/RigidBodyConverter.java Tue Aug 02 06:31:47 2011 +0900
@@ -31,6 +31,7 @@
3131
3232 import com.jme3.asset.AssetManager;
3333 import com.jme3.material.Material;
34+import com.jme3.material.RenderState.BlendMode;
3435 import com.jme3.math.ColorRGBA;
3536 import com.jme3.math.Vector3f;
3637 import com.jme3.renderer.queue.RenderQueue.Bucket;
@@ -68,7 +69,8 @@
6869
6970 public void createRigidBodyGeom(PMDRigidBody rigidBody) {
7071 Geometry geom = new Geometry(rigidBody.getRigidBodyName());
71- Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
72+ Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
73+ mat.setBoolean("UseMaterialColors", true);
7274 Mesh mesh;
7375 switch (rigidBody.getShapeType()) {
7476 case 0:
@@ -91,19 +93,19 @@
9193 }
9294 switch (rigidBody.getRigidBodyType()) {
9395 case 0:
94- mat.setColor("Color", ColorRGBA.Blue);
96+ mat.setColor("Diffuse", ColorRGBA.Blue);
9597 break;
9698 case 1:
97- mat.setColor("Color", ColorRGBA.Red);
99+ mat.setColor("Diffuse", ColorRGBA.Red);
98100 break;
99101 case 2:
100- mat.setColor("Color", ColorRGBA.Green);
102+ mat.setColor("Diffuse", ColorRGBA.Green);
101103 break;
102104 }
103105 geom.setMesh(mesh);
104106 geom.setMaterial(mat);
105- mat.getAdditionalRenderState().setWireframe(true);
106- mat.getAdditionalRenderState().setDepthTest(false);
107+// mat.getAdditionalRenderState().setWireframe(true);
108+// mat.getAdditionalRenderState().setDepthTest(false);
107109
108110 // geom.rotate(rigidBody.getRot().x, rigidBody.getRot().y, rigidBody.getRot().z);
109111 Vector3f v = new Vector3f(rigidBody.getPos().x, rigidBody.getPos().y, rigidBody.getPos().z);
@@ -120,5 +122,16 @@
120122 // System.out.println(rigidBody.getRigidBodyName()+" "+rigidBody.getRigidBodyGroupIndex()+ " "+ rigidBody.getRigidBodyGroupTarget());
121123 }
122124 node.attachChild(geom);
125+ System.out.println("rigidBody.getRigidBodyName() = "+rigidBody.getRigidBodyName());
126+ if(!rigidBody.getRigidBodyName().contains("スカート")) {
127+ ColorRGBA color = new ColorRGBA();
128+ color.set(0,0,0,0f);
129+ mat.setColor("Diffuse", color);
130+ mat.setColor("Ambient", color);
131+ mat.setColor("Specular", color);
132+ mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
133+ mat.getAdditionalRenderState().setAlphaTest(true);
134+ }
135+
123136 }
124137 }
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/jme3/mmd/ik/IKControl.java
--- a/src/projectkyoto/jme3/mmd/ik/IKControl.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/jme3/mmd/ik/IKControl.java Tue Aug 02 06:31:47 2011 +0900
@@ -96,7 +96,7 @@
9696 public void updateIKBoneRotation() {
9797 PMDModel pmdModel = pmdNode.getPmdModel();
9898 Skeleton skeleton = pmdNode.getSkeleton();
99- skeleton.updateWorldVectors();
99+// skeleton.updateWorldVectors();
100100 l1:
101101 for (PMDIKData ikData : pmdModel.getIkList().getPmdIKData()) {
102102 Bone ikBone = skeleton.getBone(ikData.getIkBoneIndex());
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/jme3/mmd/nativebullet/PMDPhysicsWorld.java
--- a/src/projectkyoto/jme3/mmd/nativebullet/PMDPhysicsWorld.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/jme3/mmd/nativebullet/PMDPhysicsWorld.java Tue Aug 02 06:31:47 2011 +0900
@@ -38,6 +38,7 @@
3838 import com.jme3.bullet.collision.shapes.SphereCollisionShape;
3939 import com.jme3.bullet.joints.SixDofJoint;
4040 import com.jme3.bullet.joints.SixDofSpringJoint;
41+import com.jme3.math.FastMath;
4142 import com.jme3.math.Matrix3f;
4243 import com.jme3.math.Matrix4f;
4344 import com.jme3.math.Quaternion;
@@ -64,7 +65,7 @@
6465 PhysicsSpace physicsSpace;
6566 Map<PMDNode, PMDRigidBody[]> rigidBodyMap = new HashMap<PMDNode, PMDRigidBody[]>();
6667 Map<PMDNode, SixDofJoint[]> constraintMap = new HashMap<PMDNode, SixDofJoint[]>();
67- float accuracy = 1f / 180f;
68+ float accuracy = 1f / 240;
6869
6970 public PMDPhysicsWorld() {
7071 float dist = 400f;
@@ -73,9 +74,10 @@
7374 new Vector3f(dist, dist, dist),
7475 PhysicsSpace.BroadphaseType.AXIS_SWEEP_3);
7576 // physicsSpace.setGravity(new Vector3f(0f, -9.8f * 2*2*2, 20f));
76- physicsSpace.setGravity(new Vector3f(0f, -9.8f * 4, 0f));
77+// physicsSpace.setGravity(new Vector3f(0f, -9.8f * 2, 0f));
78+ physicsSpace.setGravity(new Vector3f(0f, -9.8f * 1f, 0f));
7779 // physicsSpace.create();
78- physicsSpace.update(dist, 1);
80+// physicsSpace.update(dist, 1);
7981 physicsSpace.setAccuracy(accuracy);
8082 }
8183
@@ -113,7 +115,6 @@
113115 // btWorld.addRigidBody(rb, (short) (1 << fileRigidBody.getRigidBodyGroupIndex()),
114116 // (short) fileRigidBody.getRigidBodyGroupTarget());
115117 rb.setCollisionGroup(1 << (fileRigidBody.getRigidBodyGroupIndex()));
116-// rb.removeCollideWithGroup(0);
117118 rb.setCollideWithGroups(fileRigidBody.getRigidBodyGroupTarget());
118119 // rb.setCollideWithGroups(0 );
119120 physicsSpace.addCollisionObject(rb);
@@ -126,7 +127,7 @@
126127 constArray[i] = constraint;
127128 physicsSpace.add(constraint);
128129 }
129- physicsSpace.update(1 / 60f, 1);
130+// physicsSpace.update(1 / 60f, 1);
130131 }
131132
132133 public void removePMDNode(PMDNode pmdNode) {
@@ -198,22 +199,24 @@
198199 trans.setRotationQuaternion(q);
199200 trans.setTranslation(v);
200201 CollisionShape cs;
202+ float margin = 0.00f;
201203 switch (fileRigidBody.getShapeType()) {
202204 case 0:
203- cs = new SphereCollisionShape(fileRigidBody.getShapeW());
205+ cs = new SphereCollisionShape(fileRigidBody.getShapeW() - margin);
204206 break;
205207 case 1:
206- cs = new BoxCollisionShape(new Vector3f(fileRigidBody.getShapeW(),
207- fileRigidBody.getShapeH(),
208- fileRigidBody.getShapeD()));
208+ cs = new BoxCollisionShape(new Vector3f(fileRigidBody.getShapeW() - margin,
209+ fileRigidBody.getShapeH() - margin,
210+ fileRigidBody.getShapeD() - margin));
209211 break;
210212 case 2:
211- cs = new CapsuleCollisionShape(fileRigidBody.getShapeW(), fileRigidBody.getShapeH());
213+ cs = new CapsuleCollisionShape(fileRigidBody.getShapeW() - margin, fileRigidBody.getShapeH() - margin);
212214 break;
213215 default:
214216 throw new PMDException("Invalid getShapeType:" + fileRigidBody.getRigidBodyName() + " "
215217 + fileRigidBody.getShapeType());
216218 }
219+ cs.setMargin(0.1f);
217220 if (fileRigidBody.getRigidBodyType() != 0) {
218221 mass = fileRigidBody.getWeight();
219222 kinematic = false;
@@ -243,14 +246,13 @@
243246 // worldTrans.origin.add(localInertia)
244247 // PMDRigidBody rb = new PMDRigidBody(pmdNode, bone, trans2, trans, kinematic, ci);
245248 PMDRigidBody rb = new PMDRigidBody(pmdNode, bone, fileRigidBody.getRigidBodyType(), trans2.toTranslationVector(), trans2.toRotationQuat(), cs, mass);
246- rb.setPhysicsRotation(Quaternion.ZERO);
247- rb.setPhysicsLocation(Vector3f.ZERO);
249+// rb.setPhysicsRotation(Quaternion.ZERO);
250+// rb.setPhysicsLocation(Vector3f.ZERO);
248251 rb.updateFromBoneMatrix();
249- rb.updateFromBoneMatrix(); // because native bullet has a bug.
250- rb.setMass(mass);
252+// rb.setMass(mass * 1000f);
251253 rb.setDamping(fileRigidBody.getPosDim(), fileRigidBody.getRotDim());
252254 rb.setRestitution(fileRigidBody.getRecoil());
253- rb.setFriction(fileRigidBody.getFriction());
255+// rb.setFriction(fileRigidBody.getFriction());
254256
255257 // rb.setWorldTransform(worldTrans);
256258 if (kinematic) {
@@ -268,6 +270,11 @@
268270 return rb;
269271 }
270272
273+ void _convPMDEuler(Matrix3f out, float x, float y, float z) {
274+ Quaternion q = new Quaternion();
275+ q.fromAngles(x, y, z);
276+ q.toRotationMatrix(out);
277+ }
271278 void convPMDEuler(Matrix3f out, float x, float y, float z) {
272279 // Matrix3f m = new Matrix3f();
273280 // m.loadIdentity();
@@ -292,7 +299,6 @@
292299
293300 qy.toRotationMatrix(out);
294301 }
295-
296302 Vector3f convVec(javax.vecmath.Vector3f v) {
297303 return new Vector3f(v.x, v.y, v.z);
298304 }
@@ -349,28 +355,85 @@
349355 transA.setTranslation(rba.getPhysicsLocation());
350356 // transA.inverse();
351357 transA.invertLocal();
352-// transA.multLocal(trans);
353- transA = transA.mult(trans);
358+ transA.multLocal(trans);
359+// transA = transA.mult(trans);
354360 Matrix4f transB = new Matrix4f();
355361 transB.loadIdentity();
356362 // rbb.getWorldTransform(transB);
357363 transB.setTranslation(rbb.getPhysicsLocation());
358364 transB.setRotationQuaternion(rbb.getPhysicsRotation());
359365 transB.invertLocal();
360-// transB.multLocal(trans);
361- transB = transB.mult(trans);
366+ transB.multLocal(trans);
367+// transB = transB.mult(trans);
362368 // Generic6DofSpringConstraint constraint = new Generic6DofSpringConstraint(rba, rbb, transA, transB, true);
369+// SixDofSpringJoint constraint = new SixDofSpringJoint(rba, rbb,
370+// transA.toTranslationVector(),
371+// transB.toTranslationVector(),
372+// transA.toRotationMatrix(),
373+// transB.toRotationMatrix(),
374+// true);
375+
376+ Matrix4f transJ = new Matrix4f();
377+ transJ.loadIdentity();
378+ transJ.setTranslation(pmdJoint.getJointPos().x, pmdJoint.getJointPos().y, pmdJoint.getJointPos().z);
379+ convPMDEuler(m2, pmdJoint.getJointRot().x, pmdJoint.getJointRot().y, pmdJoint.getJointRot().z);
380+ q.fromRotationMatrix(m2);
381+// q.fromAngles(pmdJoint.getJointRot().x, pmdJoint.getJointRot().y, pmdJoint.getJointRot().z);
382+ transJ.setRotationQuaternion(q);
383+
384+ Matrix4f centerA = new Matrix4f();
385+ centerA.setRotationQuaternion(rba.getPhysicsRotation());
386+ centerA.setTranslation(rba.getPhysicsLocation());
387+ Matrix4f invCenterA = centerA.invert();
388+
389+ Matrix4f centerB = new Matrix4f();
390+ centerB.setRotationQuaternion(rbb.getPhysicsRotation());
391+ centerB.setTranslation(rbb.getPhysicsLocation());
392+ Matrix4f invCenterB = centerB.invert();
393+
394+ Matrix4f frameInA = invCenterA.mult(transJ);
395+ Matrix4f frameInB = invCenterB.mult(transJ);
396+
363397 SixDofSpringJoint constraint = new SixDofSpringJoint(rba, rbb,
364- transA.toTranslationVector(),
365- transB.toTranslationVector(),
366- transA.toRotationMatrix(),
367- transB.toRotationMatrix(),
398+ frameInA.toTranslationVector(),
399+ frameInB.toTranslationVector(),
400+ frameInA.toRotationMatrix(),
401+ frameInB.toRotationMatrix(),
368402 true);
369403 // Generic6DofConstraint constraint = new Generic6DofConstraint(rba, rbb, transA, transB, true);
370404 constraint.setLinearLowerLimit(convVec(pmdJoint.getConstPos1()));
371405 constraint.setLinearUpperLimit(convVec(pmdJoint.getConstPos2()));
372- constraint.setAngularLowerLimit(convVec(pmdJoint.getConstRot1()));
373- constraint.setAngularUpperLimit(convVec(pmdJoint.getConstRot2()));
406+ Vector3f constRot1 = convVec(pmdJoint.getConstRot1());
407+ if (constRot1.getX() <= -FastMath.PI / 1.0f) {
408+ constRot1.setX(-FastMath.PI * 1f);
409+ System.out.println("constRot1 x must > -90");
410+ }
411+ if (constRot1.getY() <= -FastMath.PI / 0.5f) {
412+ constRot1.setY(-FastMath.PI * 0.5f);
413+ System.out.println("constRot1 y must > -90");
414+ }
415+ if (constRot1.getZ() <= -FastMath.PI / 1.0f) {
416+ constRot1.setZ(-FastMath.PI * 1f);
417+ System.out.println("constRot1 z must > -90");
418+ }
419+ constraint.setAngularLowerLimit(constRot1);
420+
421+ Vector3f constRot2 = convVec(pmdJoint.getConstRot2());
422+ if (constRot2.getX() >= FastMath.PI / 1.0f) {
423+ constRot2.setX(FastMath.PI * 1f);
424+ System.out.println("constRot2 x must < 90");
425+ }
426+ if (constRot2.getY() >= FastMath.PI / 0.5f) {
427+ constRot2.setY(FastMath.PI * 0.5f);
428+ System.out.println("constRot2 y must < 90");
429+ }
430+ if (constRot2.getZ() >= FastMath.PI / 1.0f) {
431+ constRot2.setZ(FastMath.PI * 1f);
432+ System.out.println("constRot2 z must < 90");
433+ }
434+
435+ constraint.setAngularUpperLimit(constRot2);
436+ constraint.setEquilibriumPoint();
374437 // constraint.setCollisionBetweenLinkedBodys(false);
375438 for (int i = 0; i < 6; i++) {
376439 float f = pmdJoint.getStiffness()[i];
@@ -382,7 +445,7 @@
382445 return constraint;
383446 }
384447
385- void setKinematicPos() {
448+ public void updateKinematicPos() {
386449 for (PMDRigidBody rbarray[] : rigidBodyMap.values()) {
387450 for (int i = 0; i < rbarray.length; i++) {
388451 PMDRigidBody rb = rbarray[i];
@@ -413,7 +476,7 @@
413476 }
414477
415478 void stepSimulation(float timeStep) {
416- setKinematicPos();
479+// setKinematicPos();
417480 // float time = timeStep;
418481 // for(;time>0;time-=accuracy) {
419482 // physicsSpace.update(accuracy, 2);
@@ -424,13 +487,13 @@
424487 // applyResultToBone();
425488 // }
426489 physicsSpace.update(timeStep, 10);
427- applyResultToBone();
490+// applyResultToBone();
428491 }
429492 Transform t = new Transform();
430493 Quaternion rot2 = new Quaternion();
431494 Quat4f rot = new Quat4f();
432495
433- void applyResultToBone() {
496+ public void applyResultToBone() {
434497 // for(int i=0;i<btWorld.getNumCollisionObjects();i++) {
435498 // CollisionObject obj = btWorld.getCollisionObjectArray().getQuick(i);
436499 // if (obj instanceof PMDRigidBody) {
@@ -473,6 +536,7 @@
473536 PMDNode pmdNode = rb.getPmdNode();
474537 Node rigidBodyNode = pmdNode.getRigidBodyNode();
475538 rb.updateFromBoneMatrix();
539+ rb.setLinearVelocity(Vector3f.ZERO);
476540 if (rigidBodyNode != null) {
477541 Spatial spaital = rigidBodyNode.getChild(i);
478542 spaital.setLocalRotation(rb.getPhysicsRotation());
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/jme3/mmd/nativebullet/PMDRigidBody.java
--- a/src/projectkyoto/jme3/mmd/nativebullet/PMDRigidBody.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/jme3/mmd/nativebullet/PMDRigidBody.java Tue Aug 02 06:31:47 2011 +0900
@@ -52,6 +52,8 @@
5252 final Quaternion invRot = new Quaternion();
5353 final Vector3f tmpV = new Vector3f();
5454 final Quaternion tmpQ = new Quaternion();
55+ final Bone centerBone;
56+ final boolean centerFlag;
5557 Matrix4f m = new Matrix4f();
5658 Matrix4f invM = new Matrix4f();
5759
@@ -71,6 +73,12 @@
7173 m.set(invM);
7274 invM.invertLocal();
7375 m2.loadIdentity();
76+ centerBone = pmdNode.getSkeleton().getBone("センター");
77+ if (bone == centerBone) {
78+ centerFlag = true;
79+ } else {
80+ centerFlag = false;
81+ }
7482 }
7583
7684 public void update() {
@@ -93,7 +101,6 @@
93101 super.setPhysicsLocation(m2.toTranslationVector());
94102 super.setPhysicsRotation(m2.toRotationQuat());
95103 } else {
96- Bone centerBone = pmdNode.getSkeleton().getBone("センター");
97104 tmpV.set(centerBone.getModelSpacePosition());
98105 tmpV.addLocal(pos);
99106 tmpQ.set(centerBone.getModelSpaceRotation());
@@ -107,6 +114,12 @@
107114 }
108115 // System.out.println("objectId = "+objectId+(bone != null ? " name = "+bone.getName() : "")+" pos = "+getPhysicsLocation());
109116 }
117+ public void reset() {
118+ updateFromBoneMatrix();
119+ setLinearVelocity(Vector3f.ZERO);
120+ setAngularVelocity(Vector3f.ZERO);
121+ clearForces();
122+ }
110123 Matrix4f m2 = new Matrix4f();
111124 Matrix4f m3 = new Matrix4f();
112125
@@ -114,7 +127,7 @@
114127 // System.out.println("objectId = "+objectId+" name = "+bone.getName()+" pos = "+getPhysicsLocation());
115128 if (bone != null) {
116129 if (rigidBodyType == 2) {
117- if (!bone.getName().contains("センター")) {
130+ if (true/*!bone.getName().contains("センター")*/) {
118131 tmpV.set(super.getPhysicsLocation());
119132 tmpQ.set(super.getPhysicsRotation());
120133 m2.setRotationQuaternion(tmpQ);
@@ -130,7 +143,7 @@
130143 // super.getPhysicsRotation();
131144 }
132145 } else {
133- if (!bone.getName().contains("センター")) {
146+ if (rigidBodyType == 1 && !centerFlag) {
134147 tmpV.set(super.getPhysicsLocation());
135148 tmpQ.set(super.getPhysicsRotation());
136149 m2.setRotationQuaternion(tmpQ);
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/jme3/mmd/nativebullet/PhysicsControl.java
--- a/src/projectkyoto/jme3/mmd/nativebullet/PhysicsControl.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/jme3/mmd/nativebullet/PhysicsControl.java Tue Aug 02 06:31:47 2011 +0900
@@ -48,16 +48,16 @@
4848 world = new PMDPhysicsWorld();
4949 // world.init();
5050 world.addPMDNode(pmdNode);
51- world.stepSimulation(1f);
51+// world.stepSimulation(1f);
5252 }
5353
5454 @Override
5555 protected void controlUpdate(float tpf) {
56- pmdNode.getSkeleton().updateWorldVectors();
57- world.updateJointPosition(pmdNode);
56+// pmdNode.getSkeleton().updateWorldVectors();
57+// world.updateJointPosition(pmdNode);
5858 world.stepSimulation(tpf);
5959 // world.applyResultToBone();
60- pmdNode.calcOffsetMatrices();
60+// pmdNode.calcOffsetMatrices();
6161 // pmdNode.update();
6262 }
6363
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/jme3/mmd/vmd/IPUtil.java
--- a/src/projectkyoto/jme3/mmd/vmd/IPUtil.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/jme3/mmd/vmd/IPUtil.java Tue Aug 02 06:31:47 2011 +0900
@@ -14,7 +14,7 @@
1414 /* copyright notice, this list of conditions and the following */
1515 /* disclaimer in the documentation and/or other materials provided */
1616 /* with the distribution. */
17-/* - Neither the name of the MMDLoaderJME3 project team nor the names of */
17+/* - Neither the name of the MMDLoaderJME project team nor the names of */
1818 /* its contributors may be used to endorse or promote products */
1919 /* derived from this software without specific prior written */
2020 /* permission. */
@@ -36,8 +36,6 @@
3636
3737 package projectkyoto.jme3.mmd.vmd;
3838
39-import com.jme3.math.FastMath;
40-
4139 /**
4240 *
4341 * @author kobayasi
@@ -51,7 +49,6 @@
5149 static float ipfuncd(float t, float p1, float p2) {
5250 return ((3 + 9 * p1 - 9 * p2) * t * t + (6 * p2 - 12 * p1) * t + 3 * p1);
5351 }
54- /* VMD::setInterpolationTable: set up motion interpolation parameter */
5552
5653 static float calcIp(BoneMotionList bml, float x, int offset) {
5754 if (x <= 0) {
@@ -60,73 +57,41 @@
6057 if (x >=1) {
6158 return 1f;
6259 }
63- int i = (int)((float)BoneMotionList.IPTABLESIZE * x);
64- if (i >= BoneMotionList.IPTABLESIZE) {
65- return 1f;
60+ int ipTableSize = bml.ipTable[offset].length;
61+ for(int i=0;i<ipTableSize;i++) {
62+ if (bml.ipTable[offset][i][0] == x) {
63+ return bml.ipTable[offset][i][1];
64+ }
65+ if (bml.ipTable[offset][i][0] > x) {
66+ float x1,x2,y1,y2;
67+ if (i == 0) {
68+ x1 = 0;
69+ y1 = 0;
70+ } else {
71+ x1 = bml.ipTable[offset][i-1][0];
72+ y1 = bml.ipTable[offset][i-1][1];
73+ }
74+ x2 = bml.ipTable[offset][i][0];
75+ y2 = bml.ipTable[offset][i][1];
76+ return y1 + (y2 - y1) * (x - x1) / (x2 - x1);
77+ }
6678 }
67- float f1,f2;
68- f1 = bml.ipTable[offset][i];
69- if (i < BoneMotionList.IPTABLESIZE-1) {
70- f2 = bml.ipTable[offset][i+1];
71- } else {
72- f2 = 1f;
73- }
74- return f1 + (f2 - f1) * (x * (float)BoneMotionList.IPTABLESIZE - (float)i);
79+ return 1f;
7580 }
76- static float calcIp(byte ip[], float x, int offset) {
77- short i, d;
81+ static void createInterpolationTable(byte ip[], float ipTable[][][]) {
82+ int i, d;
7883 float x1, x2, y1, y2;
7984 float inval, t, v, tt;
80-
81- /*
82- * check if they are just a linear function
83- */
84- if (ip[0 + offset] == ip[4 + offset] && ip[8 + offset] == ip[12 + offset]) {
85- // linear
86-// return x;
87- }
88-
89- /*
90- * xの近似解を求める。
91- */
92- //for (i = 0; i < 4; i++) {
93- x1 = (float) ip[offset] / 127.0f;
94- y1 = (float) ip[ 4 + offset] / 127.0f;
95- x2 = (float) ip[ 8 + offset] / 127.0f;
96- y2 = (float) ip[12 + offset] / 127.0f;
97- // for (d = 0; d < kInterpolationTableSize; d++) {
98- inval = x; //((float) d + 0.5f) / (float) kInterpolationTableSize;
99- /*
100- * get Y value for given inval
101- */
102- t = inval;
103- for (int i2 = 0; i2 < 1000; i2++) {
104- v = ipfunc(t, x1, x2) - inval;
105- if (Math.abs(v) < 0.0001f) {
106- break;
107- }
108- tt = ipfuncd(t, x1, x2);
109- if (tt == 0.0f) {
110- break;
111- }
112- t -= v / tt;
113- }
114- return ipfunc(t, y1, y2);
115- }
116-
117- static void createInterpolationTable(byte ip[], int ipTableSize, float ipTable[][]) {
118- short i, d;
119- float x1, x2, y1, y2;
120- float inval, t, v, tt;
121-
12285 /*
12386 * check if they are just a linear function
12487 */
12588 for (i = 0; i < 4; i++) {
89+ int ipTableSize = ipTable[i].length;
12690 if (ip[0 + i] == ip[4 + i] && ip[8 + i] == ip[12 + i]) {
12791 // linear
12892 for (d = 0; d < ipTableSize; d++) {
129- ipTable[i][d] = (float) d / ipTableSize;
93+ ipTable[i][d][0] = (float) d / ipTableSize;
94+ ipTable[i][d][1] = (float) d / ipTableSize;
13095 }
13196 } else {
13297 x1 = ip[ i] / 127.0f;
@@ -134,25 +99,16 @@
13499 x2 = ip[ 8 + i] / 127.0f;
135100 y2 = ip[12 + i] / 127.0f;
136101 for (d = 0; d < ipTableSize; d++) {
137- inval = ((float) d + 0.5f) / (float) ipTableSize;
102+ inval = ((float) d ) / (float) ipTableSize;
138103 /*
139104 * get Y value for given inval
140105 */
141106 t = inval;
142- for (int i2=0;i2<1000;i2++) {
143- v = ipfunc(t, x1, x2) - inval;
144- if (FastMath.abs(v) < 0.0001f) {
145- break;
146- }
147- tt = ipfuncd(t, x1, x2);
148- if (tt == 0.0f) {
149- break;
150- }
151- t -= v / tt;
152- }
153- ipTable[i][d] = ipfunc(t, y1, y2);
107+ ipTable[i][d][0] = ipfunc(t, x1, x2);
108+ ipTable[i][d][1] = ipfunc(t, y1, y2);
154109 }
155110 }
156111 }
157112 }
113+
158114 }
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/jme3/mmd/vmd/VMDControl.java
--- a/src/projectkyoto/jme3/mmd/vmd/VMDControl.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/jme3/mmd/vmd/VMDControl.java Tue Aug 02 06:31:47 2011 +0900
@@ -1,31 +1,39 @@
11 /*
2- * Copyright (c) 2011 Kazuhiko Kobayashi All rights reserved. <p/>
2+ * Copyright (c) 2011 Kazuhiko Kobayashi All rights reserved.
3+ * <p/>
34 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions are met:
5- *
6+ * <p/>
67 * * Redistributions of source code must retain the above copyright notice,
7- * this list of conditions and the following disclaimer. <p/> *
8- * Redistributions in binary form must reproduce the above copyright notice,
9- * this list of conditions and the following disclaimer in the documentation
10- * and/or other materials provided with the distribution. <p/> * Neither the
11- * name of 'MMDLoaderJME' nor the names of its contributors may be used to
12- * endorse or promote products derived from this software without specific
13- * prior written permission. <p/> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
14- * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
15- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
17- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8+ * this list of conditions and the following disclaimer.
9+ * <p/>
10+ * * Redistributions in binary form must reproduce the above copyright
11+ * notice, this list of conditions and the following disclaimer in the
12+ * documentation and/or other materials provided with the distribution.
13+ * <p/>
14+ * * Neither the name of 'MMDLoaderJME' nor the names of its contributors
15+ * may be used to endorse or promote products derived from this software
16+ * without specific prior written permission.
17+ * <p/>
18+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+ * POSSIBILITY OF SUCH DAMAGE.
2429 */
2530 package projectkyoto.jme3.mmd.vmd;
2631
2732 import com.jme3.animation.Bone;
2833 import com.jme3.animation.Skeleton;
34+import com.jme3.bullet.PhysicsSpace;
35+import com.jme3.bullet.PhysicsTickListener;
36+import com.jme3.math.Quaternion;
2937 import com.jme3.math.Vector3f;
3038 import com.jme3.renderer.RenderManager;
3139 import com.jme3.renderer.ViewPort;
@@ -66,12 +74,14 @@
6674 static final VMDSkinComparator vmsc = new VMDSkinComparator();
6775 final PhysicsControl physicsControl;
6876 final IKControl ikControl;
77+ TickListener tl = new TickListener();
6978
7079 public VMDControl(PMDNode pmdNode, VMDFile vmdFile) {
7180 this.pmdNode = pmdNode;
7281 this.vmdFile = vmdFile;
7382 initMotionMap();
7483 physicsControl = new PhysicsControl(pmdNode);
84+ physicsControl.getWorld().getPhysicsSpace().addTickListener(tl);
7585 ikControl = new IKControl(pmdNode);
7686 }
7787
@@ -135,8 +145,10 @@
135145 // for(;time > 0; time -= physicsControl.getWorld().accuracy) {
136146 // controlUpdate2(physicsControl.getWorld().accuracy);
137147 // }
138- if (time != 0) {
139- controlUpdate2(time);
148+ if (time != 0 && !pause) {
149+// controlUpdate2(time);
150+ physicsControl.update(tpf);
151+// physicsControl.getWorld().applyResultToBone();
140152 }
141153 }
142154
@@ -151,7 +163,9 @@
151163 }
152164 }
153165 calcBonePosition(currentFrameNo, pmdNode.getSkeleton());
154- physicsControl.update(tpf);
166+ physicsControl.getWorld().updateKinematicPos();
167+// pmdNode.getSkeleton().updateWorldVectors();
168+ // physicsControl.update(tpf);
155169
156170 // timeFromCurrentFrameNo = 0;
157171 // i++;
@@ -169,14 +183,15 @@
169183 }
170184
171185 void calcBonePosition(int frameNo, Skeleton skeleton) {
186+ for(int i=0;i<pmdNode.getSkeleton().getBoneCount();i++) {
187+ Bone bone = pmdNode.getSkeleton().getBone(i);
188+ bone.getLocalRotation().loadIdentity();
189+ }
172190 boneLoop:
173191 for (BoneMotionList bml : motionMap.values()) {
174192 Bone bone = pmdNode.getSkeleton().getBone(bml.boneName);
175193 if (bone != null) {
176194 bone.setUserControl(true);
177-// if (bone.getName().equals("左足") || bone.getName().contains("ひざ")) {
178-// continue;
179-// } else
180195 if (bml.size() - 1 < bml.currentCount) {
181196 VMDMotion m1 = bml.get(bml.size() - 1);
182197 Quat4f q = m1.getRotation();
@@ -224,13 +239,7 @@
224239 float fy = IPUtil.calcIp(bml, f3, 1); //calcIp(m2.getInterpolation(), f3, 1);
225240 float fz = IPUtil.calcIp(bml, f3, 2); //calcIp(m2.getInterpolation(), f3, 2);
226241 float fr = IPUtil.calcIp(bml, f3, 3); //calcIp(m2.getInterpolation(), f3, 3);
227-// float fx = f3;
228-// float fy = f3;
229-// float fz = f3;
230-// float fr = f3;
231242 tmpq1.interpolate(m1.getRotation(), m2.getRotation(), fr);
232-// Quat4f q = m1.getRotation();
233-// tmpp1.interpolate(m1.getLocation(), m2.getLocation(), f3);
234243 tmpp1.x = m1.getLocation().x + (m2.getLocation().x - m1.getLocation().x) * fx;
235244 tmpp1.y = m1.getLocation().y + (m2.getLocation().y - m1.getLocation().y) * fy;
236245 tmpp1.z = m1.getLocation().z + (m2.getLocation().z - m1.getLocation().z) * fz;
@@ -246,7 +255,21 @@
246255 }
247256 }
248257 }
258+ pmdNode.getSkeleton().updateWorldVectors();
249259 ikControl.updateIKBoneRotation();
260+ for(int i=0;i<pmdNode.getPmdModel().getBoneList().getBoneCount();i++) {
261+ PMDBone pmdBone = pmdNode.getPmdModel().getBoneList().getBones()[i];
262+ if (pmdBone.getBoneType() == 5) {
263+ // under-rotation
264+ Bone bone = pmdNode.getSkeleton().getBone(i);
265+// if (motionMap.get(pmdBone.getBoneName()) == null) {
266+// bone.getLocalRotation().loadIdentity();
267+// }
268+ Bone targetBone = pmdNode.getSkeleton().getBone(pmdBone.getTargetBone());
269+ bone.getLocalRotation().multLocal(targetBone.getLocalRotation());
270+ bone.updateWorldVectors();
271+ }
272+ }
250273 for (SkinList skinList : skinMap.values()) {
251274 float w1 = 0f, w2 = 0f;
252275 int c1 = 0, c2 = 0;
@@ -311,7 +334,7 @@
311334 }
312335 }
313336 resetSkins();
314- calcBonePosition(currentFrameNo, pmdNode.getSkeleton());
337+// calcBonePosition(currentFrameNo, pmdNode.getSkeleton());
315338 physicsControl.getWorld().resetRigidBodyPos();
316339 // pmdNode.update();
317340 }
@@ -345,15 +368,28 @@
345368 public PhysicsControl getPhysicsControl() {
346369 return physicsControl;
347370 }
371+ class TickListener implements PhysicsTickListener {
372+
373+ @Override
374+ public void prePhysicsTick(PhysicsSpace ps, float f) {
375+ controlUpdate2(f);
376+ }
377+
378+ @Override
379+ public void physicsTick(PhysicsSpace ps, float f) {
380+ physicsControl.getWorld().applyResultToBone();
381+ }
382+
383+ }
348384 }
349385
350386 class BoneMotionList extends ArrayList<VMDMotion> {
351387
352- static final int IPTABLESIZE = 16;
388+ static final int IPTABLESIZE = 64;
353389 String boneName;
354390 int currentCount;
355391 int boneType;
356- final float ipTable[][] = new float[4][IPTABLESIZE];
392+ final float ipTable[][][] = new float[4][IPTABLESIZE][2];
357393 int frame1, frame2;
358394 final float val1[] = new float[4];
359395 final float val2[] = new float[4];
@@ -362,7 +398,7 @@
362398 if (currentCount != newCount) {
363399 currentCount = newCount;
364400 if (newCount >= 0 && newCount < size()) {
365- IPUtil.createInterpolationTable(get(currentCount).getInterpolation(), IPTABLESIZE, ipTable);
401+ IPUtil.createInterpolationTable(get(currentCount).getInterpolation(), ipTable);
366402 }
367403 }
368404 }
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/mmd/file/PMDBone.java
--- a/src/projectkyoto/mmd/file/PMDBone.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/mmd/file/PMDBone.java Tue Aug 02 06:31:47 2011 +0900
@@ -29,7 +29,6 @@
2929 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131 */
32-
3332 package projectkyoto.mmd.file;
3433
3534 import java.io.IOException;
@@ -46,16 +45,17 @@
4645 private int tailPosBoneIndex;
4746 private int boneType; // 0:回転のみ 1:回転と移動 2:IK 3:不明 4:IK影響下 5:回転影響下
4847 //6:IK接続先 7:非表示 8:捻り 9:回転運動
49- private int dummy;
48+ private int targetBone;
5049 private Vector3f boneHeadPos;
5150 private boolean hiza;
51+
5252 @Override
5353 public String toString() {
5454 return "{boneName = " + boneName
5555 + " parentBoneIndex = " + parentBoneIndex
5656 + " tailPosBoneIndex = " + tailPosBoneIndex
5757 + " boneType = " + boneType
58- + " dummy = " + dummy
58+ + " targetBone = " + targetBone
5959 + " boneHeadPos = {" + (boneHeadPos == null ? "null" : "{"
6060 + boneHeadPos.x + " " + boneHeadPos.y + " " + boneHeadPos.z)
6161 + "}"
@@ -67,10 +67,10 @@
6767 parentBoneIndex = is.readUnsignedShort();
6868 tailPosBoneIndex = is.readUnsignedShort();
6969 boneType = is.readByte();
70- dummy = is.readShort();
70+ targetBone = is.readShort();
7171 boneHeadPos = new Vector3f(is.readFloat(), is.readFloat(),
7272 -is.readFloat());
73- if (boneName.indexOf("ひざ") >=0) {
73+ if (boneName.indexOf("ひざ") >= 0) {
7474 hiza = true;
7575 } else {
7676 hiza = false;
@@ -101,12 +101,12 @@
101101 this.boneType = boneType;
102102 }
103103
104- public int getDummy() {
105- return dummy;
104+ public int getTargetBone() {
105+ return targetBone;
106106 }
107107
108- public void setDummy(int dummy) {
109- this.dummy = dummy;
108+ public void setTargetBone(int targetBone) {
109+ this.targetBone = targetBone;
110110 }
111111
112112 public int getParentBoneIndex() {
@@ -132,5 +132,4 @@
132132 public void setHiza(boolean hiza) {
133133 this.hiza = hiza;
134134 }
135-
136135 }
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/mmd/file/PMDMaterial.java
--- a/src/projectkyoto/mmd/file/PMDMaterial.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/mmd/file/PMDMaterial.java Tue Aug 02 06:31:47 2011 +0900
@@ -59,7 +59,7 @@
5959 // if (textureFileName.length() != 0) {
6060 // texture = TextureIO.newTexture(new URL(is.url ,textureFileName), true,"bmp");
6161 // }
62- if (!textureFileName.isEmpty()) {
62+ if ( false && !textureFileName.isEmpty()) {
6363 InputStream textureIs = null;
6464 try {
6565 textureIs = new URL(is.url ,textureFileName).openStream();
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/mmd/file/PMDVertex.java
--- a/src/projectkyoto/mmd/file/PMDVertex.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/mmd/file/PMDVertex.java Tue Aug 02 06:31:47 2011 +0900
@@ -136,35 +136,36 @@
136136 if (this == obj) {
137137 return true;
138138 }
139- if (obj == null) {
140- return false;
141- }
142- if (getClass() != obj.getClass()) {
143- return false;
144- }
145- final PMDVertex other = (PMDVertex) obj;
146- if (this.pos != other.pos && (this.pos == null || !this.pos.equals(other.pos))) {
147- return false;
148- }
149- if (this.normal != other.normal && (this.normal == null || !this.normal.equals(other.normal))) {
150- return false;
151- }
152- if (this.uv != other.uv && (this.uv == null || !this.uv.equals(other.uv))) {
153- return false;
154- }
155- if (this.boneNum1 != other.boneNum1) {
156- return false;
157- }
158- if (this.boneNum2 != other.boneNum2) {
159- return false;
160- }
161- if (this.boneWeight != other.boneWeight) {
162- return false;
163- }
164- if (this.edgeFlag != other.edgeFlag) {
165- return false;
166- }
167- return true;
139+ return false;
140+// if (obj == null) {
141+// return false;
142+// }
143+// if (getClass() != obj.getClass()) {
144+// return false;
145+// }
146+// final PMDVertex other = (PMDVertex) obj;
147+// if (this.pos != other.pos && (this.pos == null || !this.pos.equals(other.pos))) {
148+// return false;
149+// }
150+// if (this.normal != other.normal && (this.normal == null || !this.normal.equals(other.normal))) {
151+// return false;
152+// }
153+// if (this.uv != other.uv && (this.uv == null || !this.uv.equals(other.uv))) {
154+// return false;
155+// }
156+// if (this.boneNum1 != other.boneNum1) {
157+// return false;
158+// }
159+// if (this.boneNum2 != other.boneNum2) {
160+// return false;
161+// }
162+// if (this.boneWeight != other.boneWeight) {
163+// return false;
164+// }
165+// if (this.edgeFlag != other.edgeFlag) {
166+// return false;
167+// }
168+// return true;
168169 }
169170
170171 @Override
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/mmd/file/util2/MeshConverter.java
--- a/src/projectkyoto/mmd/file/util2/MeshConverter.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/mmd/file/util2/MeshConverter.java Tue Aug 02 06:31:47 2011 +0900
@@ -34,10 +34,15 @@
3434
3535 import java.net.URL;
3636 import java.util.ArrayList;
37+import java.util.HashMap;
38+import java.util.HashSet;
3739 import java.util.List;
40+import java.util.Map;
41+import java.util.Set;
3842 import projectkyoto.mmd.file.PMDMaterial;
3943 import projectkyoto.mmd.file.PMDModel;
4044 import projectkyoto.mmd.file.PMDSkinData;
45+import projectkyoto.mmd.file.PMDVertex;
4146
4247 /**
4348 *
@@ -49,10 +54,24 @@
4954 int maxBoneSize = 20;
5055 List<MeshData> meshDataList = new ArrayList<MeshData>();
5156 SkinMeshData skinMeshData;
57+ HashMap<PMDVertex, Integer> meshTmpVertMap = new HashMap<PMDVertex, Integer>();
58+ HashMap<PMDVertex, Integer> skinTmpVertMap = new HashMap<PMDVertex, Integer>();
5259
5360 public MeshConverter(PMDModel model) {
5461 this.model = model;
55- skinMeshData = new SkinMeshData(model);
62+ skinMeshData = new SkinMeshData(this, model);
63+ initSkinVertSet();
64+ }
65+ private final void initSkinVertSet() {
66+ for(int skinCount = 0;skinCount<model.getSkinCount();skinCount++) {
67+ PMDSkinData skinData = model.getSkinData()[skinCount];
68+ if (skinData.getSkinType() == 0) {
69+ for(int skinVertCount = 0;skinVertCount<skinData.getSkinVertCount();skinVertCount++) {
70+ VertIndex vi = new VertIndex(skinData.getSkinVertData()[skinVertCount].getSkinVertIndex());
71+ skinVertSet.add(vi);
72+ }
73+ }
74+ }
5675 }
5776
5877 public void checkDupMaterial() {
@@ -83,10 +102,11 @@
83102 if (containsSkin(i1, i2, i3)) {
84103 addSkinTriangle(material, i1, i2, i3);
85104 } else {
86- if (!meshData.addTriangle(i1, i2, i3)) {
105+ if (!meshData.addTriangle(this, i1, i2, i3)) {
87106 meshData = new MeshData(model, maxBoneSize, material);
107+ meshTmpVertMap.clear();
88108 meshDataList.add(meshData);
89- meshData.addTriangle(i1, i2, i3);
109+ meshData.addTriangle(this, i1, i2, i3);
90110 }
91111 }
92112 }
@@ -105,6 +125,7 @@
105125 // System.out.println("index " + model.getFaceVertCount() + " " + indexSizeSum
106126 // + " vertSizeSum = " + model.getVertCount() + " " + vertSizeSum
107127 // + " boneSizeSum = " + model.getBoneList().getBoneCount() + " " + boneSizeSum);
128+// printFaceVertSize();
108129 for(MeshData meshData : meshDataList) {
109130 // meshData.printTrinangles();
110131 }
@@ -122,8 +143,12 @@
122143 }
123144 return false;
124145 }
125-
146+ VertIndex tmpvi = new VertIndex(0);
126147 boolean containsSkin(int i) {
148+ tmpvi.index = i;
149+ return skinVertSet.contains(tmpvi);
150+ }
151+ boolean _containsSkin(int i) {
127152 for(int skinCount = 0;skinCount<model.getSkinCount();skinCount++) {
128153 PMDSkinData skinData = model.getSkinData()[skinCount];
129154 if (skinData.getSkinType() == 0) {
@@ -136,8 +161,10 @@
136161 }
137162 return false;
138163 }
164+ Set<VertIndex> skinVertSet = new java.util.HashSet<VertIndex> ();
165+
139166 void addSkinTriangle(PMDMaterial material, int i1,int i2,int i3) {
140- skinMeshData.addTriangle(material, i1, i2, i3);
167+ skinMeshData.addTriangle(this, material, i1, i2, i3);
141168 }
142169
143170 public int getMaxBoneSize() {
@@ -173,3 +200,32 @@
173200 }
174201
175202 }
203+class VertIndex {
204+ int index;
205+
206+ public VertIndex(int index) {
207+ this.index = index;
208+ }
209+
210+ @Override
211+ public boolean equals(Object obj) {
212+// if (obj == null) {
213+// return false;
214+// }
215+// if (getClass() != obj.getClass()) {
216+// return false;
217+// }
218+ final VertIndex other = (VertIndex) obj;
219+ if (this.index != other.index) {
220+ return false;
221+ }
222+ return true;
223+ }
224+
225+ @Override
226+ public int hashCode() {
227+ int hash = 7;
228+ hash = 53 * hash + this.index;
229+ return hash;
230+ }
231+}
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/mmd/file/util2/MeshData.java
--- a/src/projectkyoto/mmd/file/util2/MeshData.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/mmd/file/util2/MeshData.java Tue Aug 02 06:31:47 2011 +0900
@@ -57,15 +57,15 @@
5757 this.maxBoneSize = maxBoneSize;
5858 this.material = material;
5959 }
60- public boolean addTriangle(int i1,int i2,int i3) {
60+ public boolean addTriangle(MeshConverter mc, int i1,int i2,int i3) {
6161 int boneListSizeBefore = boneList.size();
6262 addBoneList(i1);
6363 addBoneList(i2);
6464 addBoneList(i3);
6565 if (boneList.size() <= maxBoneSize) {
66- addVertex(i1);
67- addVertex(i2);
68- addVertex(i3);
66+ addVertex(mc, i1);
67+ addVertex(mc, i2);
68+ addVertex(mc, i3);
6969 return true;
7070 }
7171 for(int i=boneList.size();i>boneListSizeBefore;i--) {
@@ -81,14 +81,16 @@
8181 if (!boneList.contains(v.getBoneNum2()))
8282 boneList.add(v.getBoneNum2());
8383 }
84- private void addVertex(int vertIndex) {
84+ private void addVertex(MeshConverter mc, int vertIndex) {
8585 PMDVertex v = model.getVertexList()[vertIndex];
8686 int newVertIndex;
87- if (vertexList.contains(v)) {
88- newVertIndex = vertexList.indexOf(v);
87+ Integer index = mc.meshTmpVertMap.get(v);
88+ if (index != null /*vertexList.contains(v)*/) {
89+ newVertIndex = index.intValue();//vertexList.indexOf(v);
8990 } else {
9091 newVertIndex = vertexList.size();
9192 vertexList.add(v);
93+ mc.meshTmpVertMap.put(v, index);
9294 }
9395 indexList.add(newVertIndex);
9496 }
diff -r 91c63f1ce937 -r 88ee076326ed src/projectkyoto/mmd/file/util2/SkinMeshData.java
--- a/src/projectkyoto/mmd/file/util2/SkinMeshData.java Thu Jul 28 09:37:14 2011 +0900
+++ b/src/projectkyoto/mmd/file/util2/SkinMeshData.java Tue Aug 02 06:31:47 2011 +0900
@@ -52,19 +52,20 @@
5252 List<PMDVertex> vertexList = new ArrayList<PMDVertex>();
5353 Map<PMDMaterial, List<Integer>> indexMap = new HashMap<PMDMaterial, List<Integer>>();
5454
55- public SkinMeshData(PMDModel model) {
55+ public SkinMeshData(MeshConverter mc, PMDModel model) {
5656 this.model = model;
5757 for(PMDSkinData sd : model.getSkinData()) {
5858 if (sd.getSkinType() == 0) {
5959 for(int i=0;i<sd.getSkinVertCount();i++) {
6060 PMDVertex v = model.getVertexList()[sd.getSkinVertData()[i].getSkinVertIndex()];
6161 vertexList.add(v);
62+ mc.skinTmpVertMap.put(v, i);
6263 }
6364 }
6465 }
6566 }
6667
67- public void addTriangle(PMDMaterial material, int i1, int i2, int i3) {
68+ public void addTriangle(MeshConverter mc, PMDMaterial material, int i1, int i2, int i3) {
6869 addBoneList(i1);
6970 addBoneList(i2);
7071 addBoneList(i3);
@@ -73,9 +74,9 @@
7374 indexList = new ArrayList<Integer>();
7475 indexMap.put(material, indexList);
7576 }
76- addVertex(indexList,i1);
77- addVertex(indexList,i2);
78- addVertex(indexList,i3);
77+ addVertex(mc, indexList,i1);
78+ addVertex(mc, indexList,i2);
79+ addVertex(mc, indexList,i3);
7980 }
8081
8182 private void addBoneList(int vertIndex) {
@@ -88,16 +89,19 @@
8889 }
8990 }
9091
91- private void addVertex(List<Integer>indexList, int vertIndex) {
92+ private void addVertex(MeshConverter mc, List<Integer>indexList, int vertIndex) {
9293 PMDVertex v = model.getVertexList()[vertIndex];
94+ Integer index = mc.skinTmpVertMap.get(v);
9395 int newVertIndex;
94- if (vertexList.contains(v)) {
95- newVertIndex = vertexList.indexOf(v);
96+ if (index != null /*vertexList.contains(v)*/) {
97+ newVertIndex = index.intValue(); //vertexList.indexOf(v);
9698 } else {
9799 newVertIndex = vertexList.size();
98100 vertexList.add(v);
101+ mc.skinTmpVertMap.put(v, newVertIndex);
102+ index = newVertIndex;
99103 }
100- indexList.add(newVertIndex);
104+ indexList.add(index/*newVertIndex*/);
101105 }
102106
103107 public List<Integer> getBoneList() {
Show on old repository browser