Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Voxel Importer

Discussion in 'Assets and Asset Store' started by AloneSoft, May 26, 2018.

  1. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    Until then, where would be the best place to add my own code to compute AO and store it in vertex colors?
     
  2. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Do you want to add vertex colors to Mesh with your own modifications?
    In that case, search for "Unwrapping.GenerateSecondaryUVSet" which is creating the second UV for the lightmap.
    Isn't it better to add it just before that?
     
  3. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    I don't think I need or care about a secondary UV set since I'm not using lightmaps. I'd just be adding vertex colors to the vertices.
     
  4. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    I've just shown you the best place to insert your own vertex color processing.
    The lightmap is irrelevant, and it is an example that the place in front of it may be good.
     
  5. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    Ah, thank you, I misunderstood your comment. I'll try it there, thanks!
     
  6. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    I'm currently working on generating ambient occlusion vertex colors.
    Asset updates will be made as soon as possible.
    AO.png
     
    Brady likes this.
  7. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    That's awesome news!
     
  8. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Version 1.2.5 has been released.
    - ADD : Change the minimum operation version to Unity2019.4
    - ADD : Mesh : Added the ability to create ambient occlusion vertex colors

    AO also affects mesh optimization, which increases the number of vertices.
    AO.png
     
    Brady and Silenius_ like this.
  9. Silenius_

    Silenius_

    Joined:
    Oct 23, 2017
    Posts:
    14
    Hey is there anyway to fix the z fighting problem on colluding .vox objects?
    Demonstration:


    btw I know this problem isn't related to Voxel Importer but just wanted to ask if anyone knows a solution.
     
  10. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    Amazing work, and super fast! Thanks very much.
     
  11. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Version 1.2.6 has been released.
    - FIX : Load From Vox Material : Fixed an error that occurs when unknown information is included
     
  12. max974

    max974

    Joined:
    Feb 20, 2015
    Posts:
    3
    Hi there, When I import a vox file I have this error message :

    Exception: The version of file isn't 150 that version of vox, tihs version of file is 200.
    Cubizer.Model.VoxFileImport.Load (System.String path) (at Assets/VOXFileLoader/Scripts/VOXFileImport.cs:265)
    Cubizer.Model.VoxFileImport.LoadVoxelFileAsPrefab (System.String path, System.String outpath, System.Int32 lodLevel) (at Assets/VOXFileLoader/Scripts/VOXFileImport.cs:614)
    VOXFileLoader.LoadVoxelFileAsPrefab () (at Assets/VOXFileLoader/Editor/VOXFileLoader.cs:33)

    What is it? Is it because of the new version of magicavoxel?
     
  13. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Hello.
    I checked the content of the error, but it seems that the location of the question is incorrect.
    I guess there is an error in "VOXFileLoader".
    This location is the location of the "VoxelImporter".
     
  14. Spiraseven

    Spiraseven

    Joined:
    May 2, 2014
    Posts:
    25
    Great asset! Just started playing with it. Is there a way to automatically have the tool use a URP or HDRP lit shader on import instead of the normal standard shader on import. I know I can change it after importing. Thanks!
     
  15. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Hello.
    This asset should already behave as you want.
    Projects created with URP or HDRP are created to automatically use URP or HDRP shaders instead of Standard Shaders.

    If it's not working, it's a bug.
    I want to know the environment that is not working. Please report the version of Unity etc.
     
    Spiraseven likes this.
  16. Spiraseven

    Spiraseven

    Joined:
    May 2, 2014
    Posts:
    25
    Sure, I am using Unity 2021.2.11f1 with URP. I used the Manu default model in MagicaVoxel and exported it as a vox file. Then simply dragged it into the editor. Maybe I should be using a different process?

    EDIT: I found my issue. It was on my end. Thank you for the quick reply! I had re applied a new Universal Render Pipeline Asset to my project, and to my Quality settings. But did not apply it to the Graphics Settings. That seemed to be the issue!
     
  17. Manufactory

    Manufactory

    Joined:
    Aug 6, 2017
    Posts:
    5
    Hello,

    Is it possible to change frames in Voxel Frame Animation Object via script? In my case using animations isn't preferable.Trying VoxelFrameAnimationObject.ChangeFrame(string frameName) makes compiler errors CS0246 and CS0518.

    Regards,
     
  18. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Hello,

    Sample scenes where changes from the script are working can be found at:
    Assets/VoxelImporter/Examples/FrameAnimation
    Please check this.

    I can't determine why it doesn't work at the moment, so please tell me the details of the error.

    If you just don't understand why it doesn't work.
    If you can provide a project, we can investigate it here if you provide the smallest project with reproducible errors.
     
  19. Manufactory

    Manufactory

    Joined:
    Aug 6, 2017
    Posts:
    5
    Hello,

    I fixed it by reinstalling the package. The problem was in old references in project (I started using Voxel Importer in 2020.31f and later switched project to 2020.33f but references in V.I. didn't update). Anyway, thank you for reply. By the way, Voxel Imporer is one of the greatest asset I've ever used! Good job, man!
     
  20. Manufactory

    Manufactory

    Joined:
    Aug 6, 2017
    Posts:
    5
    P.S. It will be nice in future updates to add possibility to change frames via script by index.
     
  21. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    593
    Hi, is it possible to use the generated 'avatar' to create an Avatar mask?

    I've been testing it using the `SD Human Facial` prefab in the demo.

    upload_2022-6-6_3-51-44.png

    But the 'import skeleton' button does not work (disabled)

    upload_2022-6-6_3-49-10.png
     
  22. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Hello,
    I have looked at the source code of the Unity editor to find out why the "Import skeleton" button is disabled.
    It turns out that the button requires a ModelImporter reference to work and only works for avatars created from fbx, etc.
    In other words, it appears that the avatar for this asset, which is created using AvatarBuilder, does not allow any elements other than Humanoid to be set in the editor.
    If that is necessary, it seems that the AvatarMask would have to be controlled and edited by a script.
     
    xjjon likes this.
  23. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    593
    Thanks for looking at it. Yes you are correct about ModelImporter.

    I was able to fix this by creating the AvatarMask in code:

    Code (CSharp):
    1. using System.IO;
    2. using UnityEditor;
    3. using UnityEngine;
    4.  
    5. namespace Editor
    6. {
    7.     public static class AvatarMaskEditor
    8.     {
    9.         [MenuItem("Tools/CreateAvatarMask")]
    10.         private static void CreateAvatarMask()
    11.         {
    12.             GameObject gameObject = Selection.activeGameObject;
    13.             if (gameObject != null)
    14.             {
    15.                 var path = AssetDatabase.GetAssetPath(gameObject.GetInstanceID());
    16.                 path = Path.GetDirectoryName(path);
    17.  
    18.                 AvatarMask avatarMask = new AvatarMask();
    19.                 avatarMask.AddTransformPath(gameObject.transform);
    20.                 var maskPath = string.Format("{0}/{1}.mask", path, gameObject.name);
    21.                 AssetDatabase.CreateAsset(avatarMask, maskPath);
    22.             }
    23.         }
    24.     }
    25. }
    upload_2022-6-6_18-52-50.png
     
    Rockaso likes this.
  24. peanutgallery

    peanutgallery

    Joined:
    Oct 5, 2013
    Posts:
    35
    Hello,

    I am still enjoying using this asset very much. I was trying to figure out how to manipulate individual voxels at runtime, for the following types of purposes:

    - Random colors per voxel, or turn a specific voxel the mouse is pointing at a different color.
    - Change the material properties per voxel -- for instance, if part of the model gets wet, making only specific voxels turn shiny/wet looking.

    Is this something that is realistically possible? I know such things can be edited during edit time but I was hoping I could do such things at runtime if possible. I thought maybe looking at the Voxel Explosion code would lead me to the answer but I'm having a little trouble understanding it. Is the effect happening all in a shader? It seems like the model only has the standard material shader on it, so I'm not sure where the "explosion" part is happening.

    Sorry for all of these questions!
    Thank you as always for your help.
     
  25. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Hello,
    Please see this video.

    texture.png
    With this setting, the texture will have a regularity of 2x2 dots per palette.
    Using this, it would be possible to rewrite the color of the part of the texture corresponding to the palette to be changed, even at runtime.
    It may be possible to calculate the current palette from the UV value of the vertex information at the mouse cursor position.

    As for changing the material for each voxel, if it is possible to change only a specific palette in the same way as above, it may be possible to create the same 32x32 Metallic Map Texture and set it, but it is difficult to change only the top, for example.
    If this is necessary, you would have to create a special shader like for an explosion.

    A sample explosion can be found in VoxelImporter/Examples/VoxelExplosion.
    The operation is realized by replacing the original mesh display with a mesh for the explosion by deleting the original mesh display and displaying the mesh for the explosion.
    The explosion has its own shader, and the URP version is created with Shader Graph.

    Alternatively, for objects that do not move during animation and are not very large, voxel information can be used to create a cube, as in the sample CreateCubes process.
    This is a collection of separate Cubes, so control is easy.
     
    Last edited: Jun 7, 2022
    peanutgallery likes this.
  26. peanutgallery

    peanutgallery

    Joined:
    Oct 5, 2013
    Posts:
    35
    Thank you so much! I will look into those details and let you know if I have further questions.
     
  27. UnityHas

    UnityHas

    Unity Technologies

    Joined:
    May 1, 2020
    Posts:
    32
    Is it possible to have the voxel materials import into Unity with a custom shader?
    i.e. I have a created a custom HDRP shader in shadergraph.
     
  28. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Voxels will be regular Unity Meshes and Textures when imported.
    In other words, it is possible to change the material and use a custom shader as in a normal model.
     
  29. UnityHas

    UnityHas

    Unity Technologies

    Joined:
    May 1, 2020
    Posts:
    32
    Yea I can add a new shader after the fact, but it would be great if I could import the model with my shader by default.
    Also -

    1- Can I separate my materials from the voxel prefab?
    2- When I update my voxel mesh and reimport it, can I make sure it does not update the material (only updates the texture)

    It's difficult when you are building a game and constantly losing and reapplying your materials whenever you update your model.

    Thanks,
     
  30. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Search for "GetStandardShader" in the assets.
    As you can see there, the default shader is "GraphicsSettings.renderPipelineAsset.defaultShader" if it is SRP.
    If it is not SRP, Standard is used, so the only way is to change that part.

    Material separation is possible.
    There are two import methods, each of which is described below.

    ScriptedImporter.png
    In the case of importing with ScriptedImporter, the material is separated from the Extract Materials button.
    If there are updates to the voxels after changing this material, only the textures will be updated.

    Script.png
    For import in Script, Save from the button next to the material.
    In this case as well, only the texture will be updated.
    In the case of a script, it will not be updated until the Refresh button is pressed.
     
  31. AldeRoberge

    AldeRoberge

    Joined:
    Jun 23, 2017
    Posts:
    48
    upload_2022-7-14_2-25-56.png

    What is the difference between LowTexture and LowPoly?

    What is the recommended?
     
  32. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    The direction of optimization is different.
    You can see the difference by switching the settings and checking each Mesh and Texture.

    In general, "LowPoly" is more advantageous because it requires fewer vertices.
    However, "LowTexture" only has an advantage in situations where many materials can be shared, as shown in the video below.
     
  33. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    593
    Hi, I have been using the "Voxel Skinned Animation Object" to separate the humanoid model into (head, body, arms, legs)

    However, I don't need any mesh deformation and only use the Unity Animation keyframes to animate the characters:

    upload_2022-7-18_22-51-22.png

    upload_2022-7-18_22-51-51.png

    Is there a way to separate into these without using the "Skinned Mesh Renderer"? The performance should be better with normal "Mesh Renderer" since they use simple keyframe animation and don't require any deformation.

    Thanks
     
  34. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Hello,

    There is no way to isolate this asset.
    If such a procedure is necessary, it would have to be done in a DCC tool such as Blender.

    As for separating by part, I can't conclude whether multiple MeshRenderer that would be by part would perform better than a SkinnedMeshRenderer of a single Mesh.
    I would guess that even if the cost of deformation is reduced, the cost of rendering would increase because of the separate Mesh.
     
    xjjon likes this.
  35. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    593
    Would it be possible for the explosion component to not decrease the individual cube size over time?
    Also is it possible for the cubes to just drop down towards ground instead of exploding outwards

    Thanks
     
  36. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    The operation of the explosion is realized by the shader, so it needs to be modified to get the desired operation.
    I will explain with Shader Graph of URP.
    shadergraph.png
    To avoid scaling over time, always fix the ShaderGraph image location to 1 and it will work.
    To make it behave like gravity, it can be achieved by modifying it by applying force around dir or Position.
    I'm sorry, but I can't handle individual customization, so it needs to be modified by the user.
     
    xjjon likes this.
  37. Rockaso

    Rockaso

    Joined:
    Oct 31, 2016
    Posts:
    85
    Hello,
    Thanks for sharing your solution.
    I followed it and create the AvatarMask and added the transform path using the code provided on the Mesh renderer that has the Voxel Skinned Animation Object script.
    It then adds the path as Mesh/Hips to the last bone.

    The problem is I add the AvatarMask to the Animation Controller's Layer but the avatar mask is completelly ignored (As if it just didn't had a AvatarMask)

    Could you please share how did you manage to get it working?
     
  38. peartreegames

    peartreegames

    Joined:
    Mar 15, 2016
    Posts:
    7
    Are there plans to support MagicaVoxel 0.99.7 frame animations?

    It would also be really great if the animation frame meshes can be added to the voxel asset as subassets rather than only on the VoxelFrameAnimationObject prefab.
     
  39. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    There are no plans to update MagicaVoxel 0.99.7's new frame animations.
    The reason is that there are many parts that require fundamental changes to respond, and it takes a lot of time to respond, but there is no budget for it.

    We will investigate the option of importing all meshes that are internally stored as requested and consider adding it if it is possible to respond in a short time.
     
  40. peartreegames

    peartreegames

    Joined:
    Mar 15, 2016
    Posts:
    7
    Thanks for the response, that's understandable.

    I appreciate you taking a look at the mesh import. Cheers!
     
  41. zchek

    zchek

    Joined:
    Dec 8, 2014
    Posts:
    7
    I'm getting this error.
    Failed to load '..../sk_tv_stand.vox'. File may be corrupted or was serialized with a newer version of Unity.
    UnityEngine.Object:eek:p_Inequality (UnityEngine.Object,UnityEngine.Object)
    VoxelImporter.VoxelFrameAnimationObject:LateUpdate () (at Assets/VoxelImporter/Runtime/Scripts/VoxelFrameAnimationObject.cs:90)

    It's with a MagicaVoxel 0.99.7, you mentioned the frame animations are not supported. When I first imported the voxel it worked fine. Adding the voxel frame animation object gave me access to the frames, but after reloading Unity I got the error.
    How would you usually use this component? Do I need to import every frame as a separate vox?
    Unity 2022.2.1
     
  42. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Hello,
    First of all, I am unable to reproduce this error in my environment.
    For that reason, if you could, could you please provide me with the project data to investigate?
    The minimum Unity project data where this error occurs is fine.

    MagicaVoxel's Frame Animation has undergone major changes between 0.98.2 and 0.99.7 and is not compatible with the newer ones.


    Therefore, if you want to create with one vox in the existing way, you need to create with MagicaVoxel 0.98.2.
    Currently, voxes saved with MagicaVoxel 0.99.7 have a problem where all frames are combined into a single frame.
    We are working on a fix for this issue, but it has not been addressed yet.
    Therefore, when using MagicaVoxel 0.99.7, the frames are saved as separate voxes to build the Frame Animation.
    You can add another vox as a new Frame by adding it from the Open button on the right side of Animation/Frame in the VoxelFrameAnimationObject.
     
  43. AldeRoberge

    AldeRoberge

    Joined:
    Jun 23, 2017
    Posts:
    48
    While profiling slow script domain reload times, I have noticed that "AloneSoft.VoxelImporter.Editor" takes 0.5s to reload. Is there some code executing there on reload, like [RuntimeInitializeOnLoadMethod] that makes it slow?
     
  44. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    I don't understand the meaning of RuntimeInitializeOnLoadMethod, but this asset has almost no runtime processing other than FrameAnimation and Explosion.
    Since there is no processing in the first place, it is assumed that the processing belonging to "Editor" will not affect execution on the actual machine.
    In the results of profiling in Editor, can't we ignore the part belonging to "Editor" that is not executed on the actual machine?
     
  45. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Version 1.3.0 has been released.
    - ADD : Change the minimum operation version to Unity2020.3
    - ADD : Unity2022.2 : support
    - ADD : Chunks : Chunk pivot specification function
    - ADD : ScriptedImporter : Added Models type that reads all the models contained in Mesh Mode
    - FIX : VoxelFrameAnimationObject : Temporary support for reading Animation of MagicaVoxel 0.99.7
    - FIX : Reduced memory usage to avoid running out of memory when importing huge voxels
    - FIX : Faster import
    - FIX : Configure Disable Face : ShowNotification

    There is no problem when creating a new project, but here are some things to be aware of when updating.
    1. Changing types when using StructureData
      The type has been changed to avoid running out of memory when reading huge data.
      Action may be required.
      VoxelData.png
    2. Minor changes by adding Pivot function of Chunks
      In the previous version, it was supposed to be the center of Chunks, but there was a problem that this was slightly misaligned, so Pivot will be slightly changed.
      Since this is a bug fix, the new position will be correct.
      The specified PivotT is not the size of MagicaVoxel, but the ratio within the Bounds of the actual Voxel.
      It does not include blank spaces.
      PivotT.png
    With this fix, MagicaVoxel 0.99.7 animation data can be read with VoxelFrameAnimationObject.
    However, since complete correspondence is not possible, position changes created by animation will not be reflected.
    It will be used in the same way as MagicaVoxel 0.98.2 animation.
     
    AldeRoberge and peartreegames like this.
  46. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Version 1.3.1 has been released.
    - FIX : Change the minimum operation version to Unity2019.4
     
  47. AloneSoft

    AloneSoft

    Joined:
    Apr 28, 2015
    Posts:
    309
    Version 1.3.2 has been released.
    - ADD : Unity2023.1 : support
    - ADD : Added Auto Refresh flag to control automatic refresh due to configuration changes
    - ADD : VoxelChunksObject : Removed special processing when settings that are no longer needed due to the addition of the Auto Refresh flag are changed
     
    AldeRoberge likes this.
  48. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    Your continued updates are very much appreciated. Awesome asset!