Skip to content

Commit 8cb35d2

Browse files
committed
Support new model and procedural model
1 parent 0059a5f commit 8cb35d2

2 files changed

Lines changed: 56 additions & 17 deletions

File tree

Dev/Plugin/Assets/Effekseer/Scripts/Effekseer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ public struct ModelVertex
440440
public Vector3 Normal;
441441
public Vector3 Binormal;
442442
public Vector3 Tangent;
443-
public Vector2 UV;
443+
public Vector2 UV1;
444+
public Vector2 UV2;
444445
public Color32 VColor;
445446
}
446447

Dev/Plugin/Assets/Effekseer/Scripts/EffekseerRendererUnity.cs

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ public unsafe void Initialize(Plugin.ModelVertex* vertecies,
153153
for (int i = 0; i < verteciesCount; i++)
154154
{
155155
vertexBuffer.Add(
156-
new Vertex
157-
{
158-
Position = vertecies[i].Position,
159-
Normal = vertecies[i].Normal,
160-
Binormal = vertecies[i].Binormal,
161-
Tangent = vertecies[i].Tangent,
162-
UV = vertecies[i].UV,
163-
VColor = new Color(vertecies[i].VColor.r / 255.0f, vertecies[i].VColor.g / 255.0f, vertecies[i].VColor.b / 255.0f, vertecies[i].VColor.a / 255.0f)
164-
});
156+
new Vertex
157+
{
158+
Position = vertecies[i].Position,
159+
Normal = vertecies[i].Normal,
160+
Binormal = vertecies[i].Binormal,
161+
Tangent = vertecies[i].Tangent,
162+
UV = vertecies[i].UV1,
163+
VColor = new Color(vertecies[i].VColor.r / 255.0f, vertecies[i].VColor.g / 255.0f, vertecies[i].VColor.b / 255.0f, vertecies[i].VColor.a / 255.0f)
164+
});
165165
}
166166

167167
for (int i = 0; i < facesCount; i++)
@@ -195,16 +195,20 @@ public unsafe void Initialize(Plugin.ModelVertex* vertecies,
195195

196196
public unsafe void Initialize(byte[] buffer)
197197
{
198-
int sizeEffekseerVertex = 4 * 15;
199-
200198
int version = 0;
201199
int offset = 0;
202200
version = BitConverter.ToInt32(buffer, offset);
203201
offset += sizeof(int);
204202

203+
int sizeEffekseerVertex = Marshal.SizeOf<InternalVertexV1>();
204+
205205
if (version < 1)
206206
{
207-
sizeEffekseerVertex -= 4;
207+
sizeEffekseerVertex = Marshal.SizeOf<InternalVertexV0>();
208+
}
209+
else if (version >= 6)
210+
{
211+
sizeEffekseerVertex = Marshal.SizeOf<InternalVertexV6>();
208212
}
209213

210214
if (version == 2 || version >= 5)
@@ -295,17 +299,39 @@ public unsafe void Initialize(byte[] buffer)
295299
}
296300
}
297301
}
302+
else if (version >= 6)
303+
{
304+
fixed (byte* vs_ = &buffer[offset])
305+
{
306+
InternalVertexV6* vs = (InternalVertexV6*)vs_;
307+
308+
for (int vi = 0; vi < vertexCount; vi++)
309+
{
310+
Vertex v;
311+
v.Position = vs[vi].Position;
312+
v.UV = vs[vi].UV1;
313+
v.Normal = vs[vi].Normal;
314+
v.Tangent = vs[vi].Tangent;
315+
v.Binormal = vs[vi].Binormal;
316+
v.VColor.r = vs[vi].VColor.r / 255.0f;
317+
v.VColor.g = vs[vi].VColor.g / 255.0f;
318+
v.VColor.b = vs[vi].VColor.b / 255.0f;
319+
v.VColor.a = vs[vi].VColor.a / 255.0f;
320+
vertex.Add(v);
321+
}
322+
}
323+
}
298324
else
299325
{
300326
fixed (byte* vs_ = &buffer[offset])
301327
{
302-
InternalVertex* vs = (InternalVertex*)vs_;
328+
InternalVertexV1* vs = (InternalVertexV1*)vs_;
303329

304330
for (int vi = 0; vi < vertexCount; vi++)
305331
{
306332
Vertex v;
307333
v.Position = vs[vi].Position;
308-
v.UV = vs[vi].UV;
334+
v.UV = vs[vi].UV1;
309335
v.Normal = vs[vi].Normal;
310336
v.Tangent = vs[vi].Tangent;
311337
v.Binormal = vs[vi].Binormal;
@@ -381,13 +407,25 @@ public void Dispose()
381407
}
382408

383409
[StructLayout(LayoutKind.Sequential)]
384-
struct InternalVertex
410+
struct InternalVertexV1
385411
{
386412
public Vector3 Position;
387413
public Vector3 Normal;
388414
public Vector3 Binormal;
389415
public Vector3 Tangent;
390-
public Vector2 UV;
416+
public Vector2 UV1;
417+
public Color32 VColor;
418+
}
419+
420+
[StructLayout(LayoutKind.Sequential)]
421+
struct InternalVertexV6
422+
{
423+
public Vector3 Position;
424+
public Vector3 Normal;
425+
public Vector3 Binormal;
426+
public Vector3 Tangent;
427+
public Vector2 UV1;
428+
public Vector2 UV2;
391429
public Color32 VColor;
392430
}
393431

0 commit comments

Comments
 (0)