Exemple #1
0
        public IIndoorMapMaterial CreateMaterialFromDescriptor(IndoorMaterialDescriptor descriptor)
        {
            var    sourceMaterial = descriptor.MaterialName.Contains("highlight") ? m_highlightTemplateMaterial : m_templateMaterial;
            string materialType;

            if (descriptor.Strings.TryGetValue("MaterialType", out materialType))
            {
                if (materialType.StartsWith("Interior"))
                {
                    sourceMaterial = GetOrLoadMaterialArchetype(materialType);
                }
            }
            else
            {
                materialType = string.Empty;
            }

            var material = new Material(sourceMaterial);

            Color diffuseColor;

            if (!descriptor.Colors.TryGetValue("DiffuseColor", out diffuseColor))
            {
                diffuseColor = Color.white;
            }

            material.color = diffuseColor;
            material.name  = descriptor.MaterialName;
            bool requiresStencilPrePass  = materialType == "InteriorsStencilMirrorMaterial";
            bool isForReflectionGeometry = materialType == "InteriorsReflectionMaterial";
            bool hasCustomDrawOrder      = requiresStencilPrePass || isForReflectionGeometry || diffuseColor.a < 1.0f;

            return(new DefaultIndoorMapMaterial(material, diffuseColor, hasCustomDrawOrder, requiresStencilPrePass ? m_prepassMaterial : null));
        }
Exemple #2
0
        private IntPtr CreateMaterialFromDescriptor(IndoorMaterialDescriptor descriptor)
        {
            var factory  = m_indoorMapsApiInternal.IndoorMapMaterialFactory;
            var material = factory.CreateMaterialFromDescriptor(descriptor);

            m_materialRepository.AddTemplateMaterial(material);

            var textureFetcher = m_indoorMapsApiInternal.IndoorMapTextureFetcher;

            textureFetcher.IssueTextureRequestsForMaterial(material, descriptor);

            return(NativeInteropHelpers.AllocateNativeHandleForObject(material));
        }
Exemple #3
0
        private Material CreatePrepassMaterial(IndoorMaterialDescriptor descriptor)
        {
            Color mirrorClearColor;

            if (descriptor.Colors.TryGetValue("MirrorClearColor", out mirrorClearColor))
            {
                var copy = new Material(m_prepassMaterial);
                copy.SetColor("_MirrorClearColor", mirrorClearColor);

                return(copy);
            }

            return(m_prepassMaterial);
        }
Exemple #4
0
        public IIndoorMapMaterial CreateMaterialFromDescriptor(IndoorMaterialDescriptor descriptor)
        {
            var    sourceMaterial = descriptor.MaterialName.Contains("highlight") ? m_highlightTemplateMaterial : m_templateMaterial;
            string materialType;

            if (descriptor.Strings.TryGetValue("MaterialType", out materialType))
            {
                if (materialType.StartsWith("Interior"))
                {
                    sourceMaterial = GetOrLoadMaterialArchetype(materialType);
                }
            }
            else
            {
                materialType = string.Empty;
            }

            var material = new Material(sourceMaterial);

            Color diffuseColor;

            if (!descriptor.Colors.TryGetValue("DiffuseColor", out diffuseColor))
            {
                diffuseColor = Color.white;
            }

            material.color = diffuseColor;
            material.name  = descriptor.MaterialName;
            bool isForReflectiveSurface = materialType == "InteriorsStencilMirrorMaterial";
            bool isForReflectedGeometry = materialType == "InteriorsReflectionMaterial";

            // Prevent semi-transparent stencil masks from being created.
            if (isForReflectiveSurface && diffuseColor.a < 1.0f)
            {
                diffuseColor.a = 1.0f;
                material.color = diffuseColor;
            }

            var drawOrder       = CalculateDrawOrderForMaterial(isForReflectedGeometry, isForReflectiveSurface);
            var prepassMaterial = isForReflectiveSurface ? CreatePrepassMaterial(descriptor) : null;

            return(new DefaultIndoorMapMaterial(material, diffuseColor, drawOrder, prepassMaterial));
        }
Exemple #5
0
        internal static IntPtr CreateMaterial(
            IntPtr materialDescriptorInteropPtr)
        {
            // Doing manual marshalling here, as previous approach using SizeParamIndex appears not to work on Unity 5.5.0f3.
            var materialDescriptorInterop = (MaterialDescriptorInterop)Marshal.PtrToStructure(materialDescriptorInteropPtr, typeof(MaterialDescriptorInterop));
            var indoorMapName             = Marshal.PtrToStringAnsi(materialDescriptorInterop.indoorMapName);
            var materialName = Marshal.PtrToStringAnsi(materialDescriptorInterop.materialName);
            var stringDict   = new Dictionary <string, string>(materialDescriptorInterop.stringCount);
            var intPtrSize   = Marshal.SizeOf(typeof(IntPtr));

            for (int i = 0; i < materialDescriptorInterop.stringCount; ++i)
            {
                IntPtr stringKeyPtr   = Marshal.ReadIntPtr(materialDescriptorInterop.stringKeys, i * intPtrSize);
                IntPtr stringValuePtr = Marshal.ReadIntPtr(materialDescriptorInterop.stringValues, i * intPtrSize);
                string stringKey      = Marshal.PtrToStringAnsi(stringKeyPtr);
                string stringValue    = Marshal.PtrToStringAnsi(stringValuePtr);
                stringDict[stringKey] = stringValue;
            }

            var colorDict = new Dictionary <string, Color>(materialDescriptorInterop.colorCount);

            if (materialDescriptorInterop.colorCount > 0)
            {
                var colorFloats = new float[materialDescriptorInterop.colorCount * 4];
                Marshal.Copy(materialDescriptorInterop.colorValues, colorFloats, 0, colorFloats.Length);

                for (int i = 0; i < materialDescriptorInterop.colorCount; ++i)
                {
                    IntPtr colorNamePtr = Marshal.ReadIntPtr(materialDescriptorInterop.colorNames, i * intPtrSize);
                    string colorName    = Marshal.PtrToStringAnsi(colorNamePtr);
                    var    colorValue   = new Color(colorFloats[i * 4 + 0], colorFloats[i * 4 + 1], colorFloats[i * 4 + 2], colorFloats[i * 4 + 3]);
                    colorDict[colorName] = colorValue;
                }
            }

            var scalarDict = new Dictionary <string, float>(materialDescriptorInterop.scalarCount);

            if (materialDescriptorInterop.scalarCount > 0)
            {
                var scalars = new float[materialDescriptorInterop.scalarCount];
                Marshal.Copy(materialDescriptorInterop.scalarValues, scalars, 0, scalars.Length);

                for (int i = 0; i < materialDescriptorInterop.scalarCount; ++i)
                {
                    IntPtr scalarNamePtr = Marshal.ReadIntPtr(materialDescriptorInterop.scalarNames, i * intPtrSize);
                    string scalarName    = Marshal.PtrToStringAnsi(scalarNamePtr);
                    var    scalarValue   = scalars[i];
                    scalarDict[scalarName] = scalarValue;
                }
            }

            var booleanDict = new Dictionary <string, bool>(materialDescriptorInterop.booleanCount);

            for (int i = 0; i < materialDescriptorInterop.booleanCount; ++i)
            {
                IntPtr booleanNamePtr = Marshal.ReadIntPtr(materialDescriptorInterop.booleanNames, i * intPtrSize);
                string booleanName    = Marshal.PtrToStringAnsi(booleanNamePtr);
                var    booleanValue   = Marshal.ReadInt32(materialDescriptorInterop.booleanValues, i * sizeof(Int32)) != 0;

                booleanDict[booleanName] = booleanValue;
            }

            var indoorMaterialDescriptor = new IndoorMaterialDescriptor(
                indoorMapName,
                materialName,
                stringDict,
                colorDict,
                scalarDict,
                booleanDict
                );

            var materialServiceInstance = materialDescriptorInterop.materialServiceHandle.NativeHandleToObject <IndoorMapMaterialService>();

            return(materialServiceInstance.CreateMaterialFromDescriptor(indoorMaterialDescriptor));
        }