public static VoxelData[] FromJsonData(VoxelJson jData) { VoxelData[] datas = new VoxelData[jData.vox.Length]; for (int i = 0; i < jData.vox.Length; ++i) { VoxelData data = new VoxelData(); data.pos.x = jData.vox[i].x; data.pos.y = jData.vox[i].y; data.pos.z = jData.vox[i].z; data.id = i; if (jData.rgba != null && jData.vox[i].c - 1 < jData.rgba.Length) { data.color.r = (float)(jData.rgba[jData.vox[i].c - 1].r) / 255.0f; data.color.g = (float)(jData.rgba[jData.vox[i].c - 1].g) / 255.0f; data.color.b = (float)(jData.rgba[jData.vox[i].c - 1].b) / 255.0f; data.color.a = (float)(jData.rgba[jData.vox[i].c - 1].a) / 255.0f; } else { ushort c = palette[jData.vox[i].c - 1]; data.color.a = 1.0f; data.color.r = (float)(c & 0x1f) / 31.0f; data.color.g = (float)(c >> 5 & 0x1f) / 31.0f; data.color.b = (float)(c >> 10 & 0x1f) / 31.0f; } datas[i] = data; } return(datas); }
public static VoxelData[] FromJsonData(VoxelJson jData) { VoxelData[] datas = new VoxelData[jData.vox.Length]; for(int i = 0; i<jData.vox.Length; ++i){ VoxelData data = new VoxelData(); data.x = jData.vox[i].x; data.y = jData.vox[i].y; data.z = jData.vox[i].z; data.id = i; if(jData.rgba != null && jData.vox[i].c-1 < jData.rgba.Length){ data.color.r = (float)(jData.rgba[jData.vox[i].c-1].r)/255.0f; data.color.g = (float)(jData.rgba[jData.vox[i].c-1].g)/255.0f; data.color.b = (float)(jData.rgba[jData.vox[i].c-1].b)/255.0f; data.color.a = (float)(jData.rgba[jData.vox[i].c-1].a)/255.0f; }else{ ushort c = voxColors[jData.vox[i].c - 1]; data.color.a = 1.0f; data.color.r = (float)(c & 0x1f)/31.0f; data.color.g = (float)(c >> 5 & 0x1f)/31.0f; data.color.b = (float)(c >> 10 & 0x1f)/31.0f; string co = "0x" + string.Format("{0,2:X2}", (int)((float)(c & 0x1f)/31.0f * 255.0f)) + string.Format("{0,2:X2}", (int)((float)(c >> 5 & 0x1f)/31.0f * 255.0f)) +string.Format("{0,2:X2}", (int)((float)(c >> 10 & 0x1f)/31.0f * 255.0f)) ; Debug.Log (data.color.r.ToString() + co + "!" + jData.vox[i].c); } //_data.vox[i].c //data.color = datas[i] = data; //data.color = } return datas; }