Skip to content

Commit 19b3105

Browse files
authored
Merge pull request #9 from jonaskivi/master
Simple support for PACK chunk in vox files
2 parents 3dbd422 + 96b5742 commit 19b3105

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

Assets/MagicaVoxel/Scripts/MVImporter.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,20 @@ public static MVMainChunk LoadVOXFromData(byte[] data, MVVoxelChunk alphaMask =
350350
int readSize = 0;
351351
while (readSize < childrenSize) {
352352
chunkId = br.ReadBytes (4);
353-
if (chunkId [0] == 'S' &&
353+
354+
if (chunkId [0] == 'P' &&
355+
chunkId [1] == 'A' &&
356+
chunkId [2] == 'C' &&
357+
chunkId [3] == 'K') {
358+
359+
int chunkContentBytes = br.ReadInt32 ();
360+
int childrenBytes = br.ReadInt32 ();
361+
362+
int modelCount = br.ReadInt32 ();
363+
364+
readSize += chunkContentBytes + childrenBytes + 4 * 3;
365+
}
366+
else if (chunkId [0] == 'S' &&
354367
chunkId [1] == 'I' &&
355368
chunkId [2] == 'Z' &&
356369
chunkId [3] == 'E') {
@@ -898,7 +911,7 @@ public static Mesh[] CreateMeshesFromChunk(MVVoxelChunk chunk, Color[] palatte,
898911
mesh.colors = colors.ToArray();
899912
mesh.normals = normals.ToArray();
900913
mesh.triangles = indicies.ToArray ();
901-
mesh.Optimize ();
914+
902915
result.Add (mesh);
903916

904917
verts.Clear ();
@@ -921,7 +934,7 @@ public static Mesh[] CreateMeshesFromChunk(MVVoxelChunk chunk, Color[] palatte,
921934
mesh.colors = colors.ToArray();
922935
mesh.normals = normals.ToArray();
923936
mesh.triangles = indicies.ToArray ();
924-
mesh.Optimize ();
937+
925938
result.Add (mesh);
926939

927940
totalQuadCount += currentQuadCount;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Shader "MagicaVoxel/VoxelAlpha"
2+
{
3+
Properties
4+
{
5+
_Color ("Main Color", Color) = (1,1,1,1)
6+
_MainTex ("Color (RGB) Trans (A)", 2D) = "white" {}
7+
}
8+
9+
SubShader
10+
{
11+
Tags { "Queue" = "Transparent"}
12+
13+
Pass
14+
{
15+
//ZWrite On
16+
ColorMask 0
17+
}
18+
19+
ZWrite Off // don't write to depth buffer
20+
Blend SrcAlpha OneMinusSrcAlpha // use alpha blending
21+
22+
CGPROGRAM
23+
#pragma surface surf Lambert alpha:fade
24+
25+
uniform float4 _Color;
26+
uniform sampler2D _MainTex;
27+
28+
struct Input
29+
{
30+
float4 color : COLOR;
31+
};
32+
33+
void surf (Input IN, inout SurfaceOutput o)
34+
{
35+
fixed4 col = IN.color * _Color;
36+
o.Albedo = col.rgb;
37+
o.Alpha = col.a;
38+
}
39+
ENDCG
40+
}
41+
Fallback "Glossy", 0
42+
}

0 commit comments

Comments
 (0)