Esempio n. 1
0
        private AssetImage AddFakeTexture(string name)
        {
            name = "SkyBox" + name;

            AssetImage image = new AssetImage();

            image.id      = name;
            image.src     = name;
            image.Created = true;
            room.AddAssetImage(image);

            return(image);
        }
Esempio n. 2
0
        private AssetImage GenerateCmftRad(int res, Cubemap cubemap, string forceName = "")
        {
            string path = AssetDatabase.GetAssetPath(cubemap);

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            // remove assets
            path = path.Remove(0, path.IndexOf('/'));

            string appPath  = Application.dataPath;
            string fullPath = appPath + path;
            string name     = forceName;

            if (string.IsNullOrEmpty(name))
            {
                name = cubemap.name + "_radiance";
            }

            // we know the format were exporting, so we set it now
            AssetImage data = new AssetImage();

            data.id  = name;
            data.src = name + ".dds";
            room.AddAssetImage(data);

            if (room.ExportOnlyHtml)
            {
                return(data);
            }

            string exportPath = room.RootFolder;
            string radPath    = Path.Combine(exportPath, name);

            string dstFaceSize             = res.ToString(CultureInfo.InvariantCulture);// "256";
            string excludeBase             = "false";
            string mipCount                = "9";
            string glossScale              = "10";
            string glossBias               = "1";
            string lightingModel           = "phongbrdf";
            string inputGammaNumerator     = "1.0";
            string inputGammaDenominator   = "1.0";
            string outputGammaNumerator    = "1.0";
            string outputGammaDenominator  = "1.0";
            string generateMipChain        = "false";
            string numCpuProcessingThreads = "1";


            StringBuilder builder = new StringBuilder();

            builder.Append("--input \"" + fullPath + "\"");
            builder.Append(" --srcFaceSize " + cubemap.width);
            builder.Append(" --filter radiance");
            builder.Append(" --dstFaceSize " + dstFaceSize);
            builder.Append(" --excludeBase " + excludeBase);
            builder.Append(" --mipCount " + mipCount);
            builder.Append(" --glossBias " + glossBias);
            builder.Append(" --glossScale " + glossScale);
            builder.Append(" --lightingModel " + lightingModel);
            builder.Append(" --numCpuProcessingThreads " + numCpuProcessingThreads);
            builder.Append(" --inputGammaNumerator " + inputGammaNumerator);
            builder.Append(" --inputGammaDenominator " + inputGammaDenominator);
            builder.Append(" --outputGammaNumerator " + outputGammaNumerator);
            builder.Append(" --outputGammaDenominator " + outputGammaDenominator);
            builder.Append(" --generateMipChain " + generateMipChain);
            builder.Append(" --outputNum 1");
            builder.Append(" --output0 \"" + radPath + "\"");
            builder.Append(" --output0params dds,bgra8,cubemap");
            string cmd = builder.ToString();

            // we refer by namespace so Unity never really imports CMFT on Unity 5.0
            CMFT.CmftInterop.DoExecute(cmd);


            return(data);
        }
        public void PreProcessObject(MeshRenderer renderer, Mesh mesh, AssetObject obj, RoomObject rObj, bool assignLightmapScale)
        {
            LightmapExportType  lightmapExportType = room.LightmapType;
            ExportTextureFormat format             = room.TextureFormat;

            if (lightmapExportType != LightmapExportType.None)
            {
                int lightMap = renderer.lightmapIndex;
                if (lightMap != -1)
                {
                    // Register mesh for lightmap render
                    List <RoomObject> toRender;
                    if (!lightmapped.TryGetValue(lightMap, out toRender))
                    {
                        toRender = new List <RoomObject>();
                        lightmapped.Add(lightMap, toRender);
                    }

                    toRender.Add(rObj);

                    if (assignLightmapScale)
                    {
                        if (lightmapExportType == LightmapExportType.Packed)
                        {
                            Vector4 lmap = renderer.lightmapScaleOffset;
                            lmap.x = Mathf.Clamp(lmap.x, -2, 2);
                            lmap.y = Mathf.Clamp(lmap.y, -2, 2);
                            lmap.z = Mathf.Clamp(lmap.z, -2, 2);
                            lmap.w = Mathf.Clamp(lmap.w, -2, 2);
                            rObj.SetLightmap(lmap);
                        }
                    }

                    if (lightmapExportType != LightmapExportType.BakedMaterial)
                    {
                        // check if we already have the texture
                        string     lmapId    = "Lightmap" + lightMap;
                        AssetImage lmapImage = room.TryGetTexture(lmapId);
                        if (lmapImage == null)
                        {
                            lmapImage     = new AssetImage();
                            lmapImage.id  = lmapId;
                            lmapImage.src = lmapId;
                            room.AddAssetImage(lmapImage);
                        }
                        rObj.lmap_id = lmapImage.id;
                    }
                }
            }

            switch (lightmapExportType)
            {
            case LightmapExportType.BakedMaterial:
            case LightmapExportType.Unpacked:
            {
                AssetImage image = new AssetImage();
                string     imgId = obj.id + "_Baked";

                image.id  = imgId;
                image.src = imgId;

                rObj.image_id = image.id;

                room.AddAssetImage(image);
            }
            break;
            }

            if (lightmapExportType != LightmapExportType.BakedMaterial &&
                room.ExportMaterials)
            {
                // search for textures/color on object
                Texture2D texture  = null;
                Color     objColor = Color.white;

                Material[] mats = renderer.sharedMaterials;
                for (int j = 0; j < mats.Length; j++)
                {
                    Material mat = mats[j];

                    Vector2 sca = mat.mainTextureScale;
                    Vector2 off = mat.mainTextureOffset;
                    if (sca != Vector2.one || off != Vector2.zero)
                    {
                        rObj.tiling = JanusUtil.FormatVector4(new Vector4(sca.x, sca.y, off.x, off.y));
                    }

                    Shader shader = mat.shader;
                    int    props  = ShaderUtil.GetPropertyCount(shader);
                    for (int k = 0; k < props; k++)
                    {
                        string name = ShaderUtil.GetPropertyName(shader, k);

                        ShaderUtil.ShaderPropertyType propType = ShaderUtil.GetPropertyType(shader, k);
                        if (propType == ShaderUtil.ShaderPropertyType.TexEnv)
                        {
                            if (JanusGlobals.SemanticsMainTex.Contains(name.ToLower()))
                            {
                                // main texture texture
                                Texture matTex = mat.GetTexture(name);
                                if (matTex is Texture2D)
                                {
                                    texture = (Texture2D)matTex;
                                }
                            }
                        }
                        else if (propType == ShaderUtil.ShaderPropertyType.Color)
                        {
                            if (JanusGlobals.SemanticsColor.Contains(name.ToLower()))
                            {
                                objColor = mat.GetColor(name);
                            }
                        }
                    }
                }

                rObj.col = JanusUtil.FormatColor(objColor);

                if (room.ExportTextures && texture != null)
                {
                    if (textureNames.Contains(texture.name))
                    {
                        AssetImage img = room.AssetImages.FirstOrDefault(c => c.Texture == texture);
                        if (img != null)
                        {
                            rObj.image_id = img.id;
                        }
                        return;
                    }
                    textureNames.Add(texture.name);

                    AssetImage image = new AssetImage();
                    image.Texture = texture;
                    image.id      = texture.name;
                    image.src     = texture.name;
                    rObj.image_id = image.id;
                    room.AddAssetImage(image);
                }
            }
        }