darkfall / MagicaVoxelUnity

Unity3D plugin for MagicaVoxel's vox format.
MIT License
197 stars 34 forks source link

Error when selecting individual voxels then trying to recombine, no alpha model. #12

Open Discipol opened 7 years ago

Discipol commented 7 years ago

Steps to reproduce: Get latest unity build. Install this repo. Load the knight model, without alpha model. Select the individual voxel option, reimport. Select the voxels that form the axe, or another voxel set. Try to merge them. An error pops up here: alphaMax.voxels is null and you try to access it:

int alpha = alphaMask == null ? (byte)0 : alphaMask.voxels[ x, y, z ];

Fixing it like this:

int alpha = alphaMask == null || alphaMask.voxels == null ? (byte)0 : alphaMask.voxels[ x, y, z ];

Creates this error :S help

NullReferenceException: Object reference not set to an instance of an object (wrapper managed-to-managed) object:ElementAddr_3_1 (object,int,int,int) MVImporter.GenerateFaces (.MVVoxelChunk voxelChunk, .MVVoxelChunk alphaMask) (at Assets/MagicaVoxel/Scripts/MVImporter.cs:420) MVVoxModelVoxelInspector.CombineVoxels (.MVVoxModelVoxel[] voxels) (at Assets/MagicaVoxel/Scripts/Editor/MVVoxModelVoxelInspector.cs:43) MVVoxModelVoxelInspector.OnInspectorGUI () (at Assets/MagicaVoxel/Scripts/Editor/MVVoxModelVoxelInspector.cs:20) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1240) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

barraudf commented 7 years ago

Did you pull #11 ? I think I got this error fixed. Let me know if you still have it!

Discipol commented 7 years ago

@barraudf I downloaded the repo. There's only the master. I assumed I got up to including the last commit :S

barraudf commented 7 years ago

Can you tell what file / line did you made this change please? 'Cause this looks like the exact changes I did in #11, and as far as I know I left no alphaMask.voxels[] without ensuring first that alphaMask.voxels is not null

On 5 Oct 2017 00:18, "Discipol" notifications@github.com wrote:

@barraudf https://github.com/barraudf I downloaded the repo. There's only the master. I assumed I got up to including the last commit :S

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/darkfall/MagicaVoxelUnity/issues/12#issuecomment-334305778, or mute the thread https://github.com/notifications/unsubscribe-auth/AHUmgY6-9kFSZX1YfU9Zco0fos1LQZqmks5spAQogaJpZM4PuP2V .

Discipol commented 7 years ago

@barraudf I didn't push it, only tried to fix it locally, but then other things started throwing errors :S I don't want to mess things up as I JUST found this repo, just shared how far I got.

barraudf commented 7 years ago

What file did you modify please? What line number?

I'll have a look tomorrow

Thinking about it, adding alphamask was a bad idea :/, especially now that material data has been added to the vox file

On 5 Oct 2017 00:26, "Discipol" notifications@github.com wrote:

@barraudf https://github.com/barraudf I didn't push it, only tried to fix it locally, but then other things started throwing errors :S I don't want to mess things up as I JUST found this repo, just shared how far I got.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/darkfall/MagicaVoxelUnity/issues/12#issuecomment-334307535, or mute the thread https://github.com/notifications/unsubscribe-auth/AHUmgXctv3wQAFqmTJc_4bhpb_aIM3VRks5spAYkgaJpZM4PuP2V .

Discipol commented 7 years ago

@barraudf MVImporter.cs > 457 > int alpha = alphaMask == null ? (byte)0 : alphaMask.voxels[ x, y, z ];

Yeah I don't see the point of that either :D There are also some problems with the shaders / meshes. Some of the faces are reversed, so I can see through some cube faces :S

barraudf commented 7 years ago

This is not what the file actually looks like : https://github.com/darkfall/MagicaVoxelUnity/blob/master/Assets/MagicaVoxel/Scripts/MVImporter.cs

It was updated 10 days ago, and no longer contains any "(byte)0". My guess is your working copy is outdated. You should try to revert and pull.

Discipol commented 7 years ago

@barraudf Downloading it gives me that old version, I am git-ing now and its the latest one. Also, error:

if(alphaMask == null && alphaMask.voxels != null)

Should be alphaMask != null :D

Discipol commented 7 years ago

@barraudf The unitypackage and the source files are different, that's why I was getting outdated stuff, I was using the package :S what's happening here?

barraudf commented 7 years ago

This repository is not much active anymore, I guess the unitypackage is not updated after each Pull Request, you'd better stick with git source code.

What I did back in time was to make my own magicka voxel importer in the end. MVImporter.cs contains all the code to read a vox file (the vox file format has been updated recently and now include a MATT chunk with all the Material data, which MagicaVoxelUnity doesn't handle) and how to build a model from the voxel data.

Good catch on alphaMask != null, I'll change it (or you can if you wish, that's what open source is about :))

Discipol commented 7 years ago

@barraudf I want to mate but deadlines tell me I can't. At least, not at the moment. I will need some of this code to transform VOX into a format I will need, so I will say my warmest thanks to you and other contributors :+1: