Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

SpatialUnderstanding MeshRenderer color change during run-time

BokuBoku
edited August 2018 in Questions And Answers

Hi guys,

I'm currently working with SpatialUnderstanding, which is a module for the Microsoft HoloLens. Within the module, mesh of the space the user is currently in is mapped (essentially a processed spatial map). I'm looking to modify the mesh material color during run-time, but the following code I have seems to have no effect (visually):

 void TestFunction()
 {
     List<MeshRenderer> roomMeshRenderers = SpatialUnderstanding.Instance.UnderstandingCustomMesh.GetMeshRenderers() as List<MeshRenderer>;
     foreach (currentRenderer in roomMeshRenderers)
     {
         Material material = currentRenderer.material;
         Debug.Log(material.color);
         material.color = Color.white;
         currentRenderer.material = material;
     }
 }

Would appreciate it if anyone could point why this code has no effect.

Thanks!

Best Answer

Answers

  • pstuevenpstueven ✭✭
    edited August 2018

    Hey @Boku ,

    I did something similar with but also used spatialUnterstanding in that scenario. Try this:
    SpatialUnderstandingCustomMesh spatialMesh = GameObject.Find("SpatialMapping").GetComponent<SpatialUnderstandingCustomMesh>(); foreach (SpatialMappingSource.SurfaceObject surfaceObject in spatialMesh.SurfaceObjects) { surfaceObject.Renderer.material = material }
    Of course you need to adjust the string "SpatialMapping" to the name of the object holding your SpatialMapping

    Regards
    @pstueven

  • @pstueven said:
    Hey @Boku ,

    I did something similar with but also used spatialUnterstanding in that scenario. Try this:
    SpatialUnderstandingCustomMesh spatialMesh = GameObject.Find("SpatialMapping").GetComponent<SpatialUnderstandingCustomMesh>(); foreach (SpatialMappingSource.SurfaceObject surfaceObject in spatialMesh.SurfaceObjects) { surfaceObject.Renderer.material = material }
    Of course you need to adjust the string "SpatialMapping" to the name of the object holding your SpatialMapping

    Regards
    @pstueven

    Hey @pstueven

    That works and changes the material. I found out there is already a function available in SpatialUnderstandingCustomMesh.cs which does this, called "MeshMaterial".

    I have a slightly different problem however, when I try to change the texture of the material to be rendered the new texture doesn't seem to get applied. The code is as follows:
    SpatialUnderstanding.Instance.UnderstandingCustomMesh.ChangeProcessedMeshTexture(targetTexture);

    And in SpatialUnderstandingCustomMesh.cs I have:
    public void ChangeProcessedMeshTexture(Texture2D targetTexture) { for (int i = 0; i < SurfaceObjects.Count; ++i) { SurfaceObjects[i].Renderer.material.SetTexture("_MainTex", targetTexture); } }

  • @pstueven said:
    Hey @Boku ,
    To be honest I am not into materials that much. So I am just giving suggestions here:
    Are you sure the current material has a texture called "_MainTex" applied? The first argument of SetTexture determines which texture you want to set. Maybe try using "_BumpMap" or Material.mainTex .

    That was the problem! My shader didn't have a _MainTex. Think I'll have to use another shader.

    Thanks :)

Sign In or Register to comment.