예제 #1
0
    public Task <Remote.Material> LoadMaterial(RemoteMaterial material)
    {
        if (material == null)
        {
            return(Task.FromResult <Remote.Material>(null));
        }

        Task <Remote.Material> remoteMaterial = null;

        lock (m_nameToMaterial)
        {
            if (m_nameToMaterial.ContainsKey(material.name))
            {
                remoteMaterial = m_nameToMaterial[material.name];
                if (remoteMaterial.IsCanceled || remoteMaterial.IsFaulted)
                {
                    remoteMaterial = null;
                }
            }
        }

        if (remoteMaterial == null)
        {
            remoteMaterial = InsertAndLoadRemoteMaterial(material);
        }

        return(remoteMaterial);
    }
    public override bool Equals(object other)
    {
        if (!(other is RemoteMaterial) || other == null)
        {
            return(false);
        }

        RemoteMaterial remoteMaterial = (RemoteMaterial)other;

        return(this.AlbedoColor == remoteMaterial.AlbedoColor &&
               this.AlbedoTextureUrl == remoteMaterial.AlbedoTextureUrl &&
               this.AlphaClipThreshold == remoteMaterial.AlphaClipThreshold &&
               this.AOMapUrl == remoteMaterial.AOMapUrl &&
               this.AOScale == remoteMaterial.AOScale &&
               this.ColorFlags == remoteMaterial.ColorFlags &&
               this.ColorTransparencyMode == remoteMaterial.ColorTransparencyMode &&
               this.Name == remoteMaterial.Name &&
               this.FadeOut == remoteMaterial.FadeOut &&
               this.Metalness == remoteMaterial.Metalness &&
               this.MetalnessMapUrl == remoteMaterial.MetalnessMapUrl &&
               this.NormalMapUrl == remoteMaterial.NormalMapUrl &&
               this.PbrFlags == remoteMaterial.PbrFlags &&
               this.Roughness == remoteMaterial.Roughness &&
               this.RoughnessMapUrl == remoteMaterial.RoughnessMapUrl &&
               this.TexCoordOffset == remoteMaterial.TexCoordOffset &&
               this.TexCoordScale == remoteMaterial.TexCoordScale &&
               this.Type == remoteMaterial.Type &&
               this.VertexAlphaMode == remoteMaterial.VertexAlphaMode &&
               this.VertexMix == remoteMaterial.VertexMix);
    }
예제 #3
0
    public static RemoteMaterial Default()
    {
        var result = new RemoteMaterial();

        result.name      = "Default";
        result.IsDefault = true;
        return(result);
    }
예제 #4
0
    private Task <Remote.Material> InsertAndLoadRemoteMaterial(RemoteMaterial material)
    {
        Task <Remote.Material> result = null;

        lock (m_nameToMaterial)
        {
            if (material.Type == MaterialType.Pbr)
            {
                m_nameToMaterial[material.name] = result = InitializePhysicalMaterial(material);
            }
            else
            {
                m_nameToMaterial[material.name] = result = InitializeColorMaterial(material);
            }
        }
        return(result);
    }
예제 #5
0
    private async Task <Remote.Material> InitializePhysicalMaterial(
        RemoteMaterial material)
    {
        var remoteMaterial = RemoteManagerUnity.CurrentSession?.Actions.CreateMaterial(MaterialType.Pbr);

        remoteMaterial.Name = material.name;

        PbrMaterial pbrMaterial = remoteMaterial as PbrMaterial;

        pbrMaterial.AlbedoColor        = material.AlbedoColor.toRemoteColor4();
        pbrMaterial.AlphaClipThreshold = material.AlphaClipThreshold;
        pbrMaterial.AOScale            = material.AOScale;
        pbrMaterial.FadeOut            = material.FadeOut;
        pbrMaterial.Metalness          = material.Metalness;
        pbrMaterial.PbrFlags           = material.PbrFlags.toRemote();
        pbrMaterial.PbrVertexAlphaMode = material.VertexAlphaMode;
        pbrMaterial.Roughness          = material.Roughness;
        pbrMaterial.TexCoordOffset     = material.TexCoordOffset.toRemote();
        pbrMaterial.TexCoordScale      = material.TexCoordScale.toRemote();

        Task <Texture>[] textureLoads = new Task <Texture>[]
        {
            LoadTextureFromCache(material.AlbedoTextureUrl),
            LoadTextureFromCache(material.AOMapUrl),
            LoadTextureFromCache(material.MetalnessMapUrl),
            LoadTextureFromCache(material.NormalMapUrl),
            LoadTextureFromCache(material.RoughnessMapUrl)
        };

        Texture[] textures = await Task.WhenAll(textureLoads);

        int textureIndex = 0;

        pbrMaterial.AlbedoTexture = textures[textureIndex++];
        pbrMaterial.AOMap         = textures[textureIndex++];
        pbrMaterial.MetalnessMap  = textures[textureIndex++];
        pbrMaterial.NormalMap     = textures[textureIndex++];
        pbrMaterial.RoughnessMap  = textures[textureIndex++];

        return(remoteMaterial);
    }
예제 #6
0
    private async Task <Remote.Material> InitializeColorMaterial(RemoteMaterial material)
    {
        var remoteMaterial = RemoteManagerUnity.CurrentSession?.Actions.CreateMaterial(MaterialType.Color);

        remoteMaterial.Name = material.name;

        ColorMaterial colorMaterial = remoteMaterial as ColorMaterial;

        colorMaterial.AlbedoColor           = material.AlbedoColor.toRemoteColor4();
        colorMaterial.AlphaClipThreshold    = material.AlphaClipThreshold;
        colorMaterial.ColorFlags            = material.ColorFlags.toRemote();
        colorMaterial.ColorTransparencyMode = material.ColorTransparencyMode;
        colorMaterial.FadeOut        = material.FadeOut;
        colorMaterial.TexCoordOffset = material.TexCoordOffset.toRemote();
        colorMaterial.TexCoordScale  = material.TexCoordScale.toRemote();
        colorMaterial.VertexMix      = material.VertexMix;

        if (!String.IsNullOrEmpty(material.AlbedoTextureUrl))
        {
            colorMaterial.AlbedoTexture = await LoadTextureFromCache(material.AlbedoTextureUrl);
        }

        return(remoteMaterial);
    }