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.
Options

Any demo projects on how to apply a new texture to a plane?

The basic gist here is I'm working on experience that re-maps an environment. So I would like to take my texture and apply it to a pre-existing plane (floor).

Thanks!

Answers

  • Options
    ahillierahillier mod
    edited September 2016

    There are a few ways to do this, but here's the basic approach:
    1) Create a new material that uses the texture you want.
    2) Create a script that has a public Material property that you can set.
    3) Update the MeshRenderer(s) associated with your plane (or any 3D object) to use the new material.

    Here's a simple script that does #2 and #3:

    using UnityEngine;
    
    public class ChangeMaterial : MonoBehaviour
    {
        /// <summary>
        /// Material to use when rendering.
        /// </summary>
        public Material renderMaterial;
    
        private Material previousMaterial;
    
        /// <summary>
        /// The material to use when rendering.
        /// </summary>
        public Material RenderMaterial
        {
            get
            {
                return renderMaterial;
            }
            set
            {
                previousMaterial = renderMaterial;
                renderMaterial = value;
                SetRenderMaterial(renderMaterial);
            }
        }
    
    // Use this for initialization
    void Start ()
    {
        previousMaterial = gameObject.GetComponent<MeshRenderer>().sharedMaterial;
        if (renderMaterial == null)
        {
            renderMaterial = previousMaterial;
        }
    }
    
        // Update the material when changes are made in the editor.
        void Update()
        {
            if(renderMaterial != previousMaterial)
            {
                RenderMaterial = renderMaterial;
            }
        }
    
        /// <summary>
        /// Sets the material for all MeshRenderers on the gameObject.
        /// </summary>
        /// <param name="material">Material to use when rendering the gameObject.</param>
        void SetRenderMaterial(Material material)
        {
            MeshRenderer[] renderers = gameObject.GetComponents<MeshRenderer>();
            for (int index = 0; index < renderers.Length; index++)
            {
                renderers[index].sharedMaterial = material;
            }
        }
    }
    

    If you create a plane in Unity, add this script to the gameObject, then press the 'Play' button, you can drag a new material into the 'Render Material' field to see the material change while running in the editor. You could also set the 'RenderMaterial' property via code.

    I hope this helps,
    ~Angela

  • Options

    This is a great I will give this a try in the morning. Thank you for sharing, it really helps those that are foreign to this space.

  • Options
    edited September 2016

    Evening, I just now sat down to do this. So what I'm trying to do is select the plane "the floor" with a tap gesture and then apply the material selected to that plane. I have a new plane called "plane" and the material and the script you provided is attached to that plane.

    What I was attempting to do was to:

    1. On Scene / Project Load get the spatial map of the room
    2. Detect areas that are "floors"
    3. Automatically apply the "wooden" floor texture to the plane floor
    4. Look down at floor with holo lens and see its now a new texture.

    Thank you

  • Options

    @imagineholos said:
    Evening, I just now sat down to do this. So what I'm trying to do is select the plane "the floor" with a tap gesture and then apply the material selected to that plane. I have a new plane called "plane" and the material and the script you provided is attached to that plane.

    What I was attempting to do was to:

    1. On Scene / Project Load get the spatial map of the room
    2. Detect areas that are "floors"
    3. Automatically apply the "wooden" floor texture to the plane floor
    4. Look down at floor with holo lens and see its now a new texture.

    Thank you

    Did you figure it out?

  • Options

    I did not:

    • I haven't had a chance to get back to it, but would love to figure it out.
Sign In or Register to comment.