示例#1
0
        private static void SetFoldersToTreeview(SPFolder folder, ref TreeNode parentNode, string baseURL)
        {
            SPFolderCollection subFolders = folder.SubFolders;

            foreach (SPFolder subFolder in subFolders)
            {
                TreeNode folderNode = new TreeNode();
                folderNode.ImageUrl     = baseURL + "/_layouts/images/folder.gif";
                folderNode.Text         = subFolder.Name;
                folderNode.SelectAction = TreeNodeSelectAction.None;
                folderNode.ShowCheckBox = false;
                foreach (SPFile file in subFolder.Files)
                {
                    if (WPHelper.fileType(Path.GetExtension(file.Name).ToUpper()))
                    {
                        TreeNode fileNode = new TreeNode();
                        fileNode.Text         = file.Name;
                        fileNode.ImageUrl     = baseURL + "/_layouts/images/" + file.IconUrl;
                        fileNode.Value        = file.Url;
                        fileNode.SelectAction = TreeNodeSelectAction.None;
                        folderNode.ChildNodes.Add(fileNode);
                    }
                }
                parentNode.ChildNodes.Add(folderNode);
                SetFoldersToTreeview(subFolder, ref folderNode, baseURL);
            }
        }
示例#2
0
        public ImageData(string _filePath)
        {
            filePath = _filePath;

            if (!File.Exists(filePath))
            {
                Debug.LogError("lightmap doesn't exist at path: '" + filePath + "'");
            }

            assetPath = WPHelper.FilePathToAssetPath(filePath);

            TextureImporter tImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;

            if (tImporter != null)
            {
                tImporter.textureType   = TextureImporterType.Default;
                tImporter.linearTexture = true;
                tImporter.textureFormat = TextureImporterFormat.RGBA32;
                tImporter.isReadable    = true;
                AssetDatabase.ImportAsset(assetPath);
            }

            Texture2D tex = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)) as Texture2D;

            if (null == tex)
            {
                Debug.LogError("Failed to load the lightmap at path: " + assetPath);
                return;
            }

            width  = tex.width;
            height = tex.height;

            srcPixels = tex.GetPixels();
            dstPixels = tex.GetPixels();

            if (tImporter != null)
            {
                tImporter.textureType   = TextureImporterType.Lightmap;
                tImporter.linearTexture = true;
                tImporter.textureFormat = TextureImporterFormat.AutomaticCompressed;
                tImporter.isReadable    = false;
                AssetDatabase.ImportAsset(assetPath);
            }

            //WPHelper.MakeTextureReadable( tex, false );

//			dstPixels = new Color[width * height];
//
//			for (int i = 0; i < width*height; i++) {
//				dstPixels[i] = new Color(.5f, .5f, .5f, 1f);
//			}

//			for (int x = 0; x < width; x++) {
//				//Debug.Log(dstPixels[x].r * 255f + " " + dstPixels[x].g * 255f + " " + dstPixels[x].b * 255f);
//			}

            Save();
        }
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            UPLOAD_LIMIT = UPLOAD_LIMIT * WPHelper.fileSize();

            if (fuAsset.HasFile)
            {
                if (fuAsset.PostedFile.ContentLength > UPLOAD_LIMIT)
                {
                    lblResults.Text = "<font color=red>The file could not be uploaded. File size should not be greater than " + Convert.ToString(WPHelper.fileSize()) + " MB</font>";
                    ResetFields();
                    return;
                }
                SaveMediaAssetSettings();
            }
            else
            {
                lblResults.Text = "<font color=red>Please select a Media Asset file.</font>";
            }
        }
示例#4
0
        private void SaveMediaAssetSettings()
        {
            try
            {
                UPLOAD_LIMIT = UPLOAD_LIMIT * WPHelper.fileSize();

                string url = SPContext.Current.Web.Url.ToString() + "/" + trvSharePoint.CheckedNodes[0].Value;

                Stream stream = OoyalaMediaUtils.GetFileStream(url);

                if (stream == null)
                {
                    lblResults.Text = "<font color=red>Please select valid file!</font>";
                    ResetFields();
                    return;
                }

                if (stream.Length > UPLOAD_LIMIT)
                {
                    lblResults.Text = "<font color=red>The file could not be uploaded. File size should not be greater than " + Convert.ToString(WPHelper.fileSize()) + " MB</font>";
                    ResetFields();
                    return;
                }

                Hashtable hs = new Hashtable();
                if (!string.IsNullOrEmpty(txtTitle.Text))
                {
                    hs.Add("name", txtTitle.Text);
                }
                else
                {
                    hs.Add("name", trvSharePoint.CheckedNodes[0].Text);
                }

                string filename = trvSharePoint.CheckedNodes[0].Text;
                hs.Add("file_name", filename);

                string astType     = Path.GetExtension(filename).ToUpper();
                bool   isValidType = WPHelper.fileType(astType);

                //switch (astType)
                //{
                //    case ".AVI":
                //    case ".MPG":
                //    case ".MOV":
                //    case ".RM" :
                //    case ".MP4":
                //    case ".WMV":
                //    case ".WM" :
                //        hs.Add("asset_type", "video");
                //        break;
                //    case ".WAV":
                //    case ".AIF":
                //    case ".MP3":
                //    case ".MID":
                //    case ".RA" :
                //        hs.Add("asset_type", "audio");
                //        break;
                //    default:
                //        isValidType = true;
                //        break;
                //}
                if (!isValidType)
                {
                    lblResults.Text = "<font color=red>File Type is not supported!</font>";
                    ResetFields();
                    return;
                }
                else
                {
                    hs.Add("asset_type", "video");
                }

                hs.Add("file_size", stream.Length.ToString());

                if (!string.IsNullOrEmpty(txtDesc.Text))
                {
                    hs.Add("description", txtDesc.Text);
                }

                if (!string.IsNullOrEmpty(ddlPostUploadStatus.SelectedValue))
                {
                    hs.Add("post_processing_status", ddlPostUploadStatus.SelectedValue);
                }

                string id = OoyalaMediaUtils.NewMediaAsset(SecretKey, APIKey, hs);

                if (string.IsNullOrEmpty(id))
                {
                    lblResults.Text             = "<font color=red> " + WPHelper.permissionErrorMsg + " </font>";
                    WPHelper.permissionErrorMsg = string.Empty;
                    return;
                }

                OoyalaMediaUtils.NewMediaUploadStream(SecretKey, APIKey, id, stream);

                if (ShowLabels)
                {
                    ArrayList arl = new ArrayList();
                    foreach (TreeNode tn in trvAsset.CheckedNodes)
                    {
                        if (!string.IsNullOrEmpty(tn.Value))
                        {
                            arl.Add(tn.Value);
                        }
                    }
                    OoyalaMediaUtils.ApplyLabelsToAssets(SecretKey, APIKey, id, arl);
                }

                if (ShowCustomMetadata)
                {
                    Hashtable hsMD = new Hashtable();
                    foreach (GridViewRow rw in dtgMetadata.Rows)
                    {
                        TextBox txtCustomMetadataKey   = (TextBox)rw.FindControl("txtCustomMetadataKey");
                        TextBox txtCustomMetadataValue = (TextBox)rw.FindControl("txtCustomMetadataValue");
                        if (!(string.IsNullOrEmpty(txtCustomMetadataKey.Text) && string.IsNullOrEmpty(txtCustomMetadataValue.Text)))
                        {
                            if (!hsMD.ContainsKey(txtCustomMetadataKey.Text))
                            {
                                hsMD.Add(txtCustomMetadataKey.Text, txtCustomMetadataValue.Text);
                            }
                        }
                    }
                    OoyalaMediaUtils.ApplyCustomMetadataToAssets(SecretKey, APIKey, id, hsMD);
                }
                OoyalaMediaUtils.SetMediaFileStatus(SecretKey, APIKey, id, "uploaded");
                lblResults.Text = "<font color=green>File Successfully Uploaded!</font>";
                ResetFields();
            }
            catch (Exception e)
            {
                lblResults.Text = e.Message;
            }
        }
        private void SaveMediaAssetSettings()
        {
            try
            {
                string    filename = Path.GetFileName(fuAsset.FileName);
                Hashtable hs       = new Hashtable();

                if (!string.IsNullOrEmpty(txtTitle.Text))
                {
                    hs.Add("name", txtTitle.Text);
                }
                else
                {
                    hs.Add("name", filename);
                }

                hs.Add("file_name", filename);

                string astType     = Path.GetExtension(filename).ToUpper();
                bool   isValidType = WPHelper.fileType(astType);

                //switch (astType)
                //{
                //    case ".AVI":
                //    case ".MPG":
                //    case ".MOV":
                //    case ".RM":
                //    case ".MP4":
                //    case ".WMV":
                //    case ".WM":
                //        hs.Add("asset_type", "video");
                //        break;
                //    case ".WAV":
                //    case ".AIF":
                //    case ".MP3":
                //    case ".MID":
                //    case ".RA":
                //    case ".AAC":
                //        hs.Add("asset_type", "audio");
                //        break;
                //    default:
                //        isValidType = true;
                //        break;
                //}

                if (!isValidType)
                {
                    lblResults.Text = "<font color=red>File Type is not supported!</font>";
                    ResetFields();
                    return;
                }
                else
                {
                    hs.Add("asset_type", "video");
                }

                hs.Add("file_size", fuAsset.PostedFile.ContentLength.ToString());

                if (!string.IsNullOrEmpty(txtDesc.Text))
                {
                    hs.Add("description", txtDesc.Text);
                }

                if (!string.IsNullOrEmpty(ddlPostUploadStatus.SelectedValue))
                {
                    hs.Add("post_processing_status", ddlPostUploadStatus.SelectedValue);
                }

                string id = OoyalaMediaUtils.NewMediaAsset(SecretKey, APIKey, hs);

                if (string.IsNullOrEmpty(id))
                {
                    lblResults.Text             = "<font color=red> " + WPHelper.permissionErrorMsg + " </font>";
                    WPHelper.permissionErrorMsg = string.Empty;
                    ResetFields();
                    return;
                }

                //if (string.IsNullOrEmpty(id))
                //{
                //    lblResults.Text = "<font color=red>Not able to create New Media Asset</font>";
                //    ResetFields();
                //    return;
                //}

                OoyalaMediaUtils.NewMediaUploadStream(SecretKey, APIKey, id, fuAsset.PostedFile.InputStream);

                if (ShowLabels)
                {
                    ArrayList arl         = new ArrayList();
                    bool      isAvailable = false;
                    foreach (TreeNode tn in trvAsset.CheckedNodes)
                    {
                        if (!string.IsNullOrEmpty(tn.Value))
                        {
                            arl.Add(tn.Value);
                            isAvailable = true;
                        }
                    }
                    if (isAvailable)
                    {
                        OoyalaMediaUtils.ApplyLabelsToAssets(SecretKey, APIKey, id, arl);
                    }
                }

                if (ShowCustomMetadata)
                {
                    Hashtable hsMD        = new Hashtable();
                    bool      isAvailable = false;
                    foreach (GridViewRow rw in dtgMetadata.Rows)
                    {
                        TextBox txtCustomMetadataKey   = (TextBox)rw.FindControl("txtCustomMetadataKey");
                        TextBox txtCustomMetadataValue = (TextBox)rw.FindControl("txtCustomMetadataValue");
                        if (!(string.IsNullOrEmpty(txtCustomMetadataKey.Text) && string.IsNullOrEmpty(txtCustomMetadataValue.Text)))
                        {
                            isAvailable = true;
                            if (!hsMD.ContainsKey(txtCustomMetadataKey.Text))
                            {
                                hsMD.Add(txtCustomMetadataKey.Text, txtCustomMetadataValue.Text);
                            }
                        }
                    }
                    if (isAvailable)
                    {
                        OoyalaMediaUtils.ApplyCustomMetadataToAssets(SecretKey, APIKey, id, hsMD);
                    }
                }

                OoyalaMediaUtils.SetMediaFileStatus(SecretKey, APIKey, id, "uploaded");
                lblResults.Text = "<font color=green>File Successfully Uploaded!</font>";
                ResetFields();
            }
            catch (Exception e)
            {
                lblResults.Text = e.Message;
            }
        }
示例#6
0
        private static string[] PrepareLightmaps(GameObject[] affectedObjects)
        {
            //
            //Duplicate original lightmaps
            List <int> lightmapsToBackup = new List <int>();

            foreach (GameObject obj in affectedObjects)
            {
                int lightmapIndex = -1;

                if (obj.GetComponent <Renderer>() != null)
                {
                    lightmapIndex = obj.GetComponent <Renderer>().lightmapIndex;
                }
                else
                {
                    Terrain terrain = obj.GetComponent <Terrain>();
                    if (terrain != null)
                    {
                        lightmapIndex = terrain.lightmapIndex;
                    }
                }

                if (lightmapIndex < 0)
                {
                    continue;
                }

                //Make sure that we keep only lightmapped objects
                if (lightmapIndex < 0 || lightmapIndex >= LightmapSettings.lightmaps.Length)
                {
                    continue;
                }

                if (!lightmapsToBackup.Contains(lightmapIndex))
                {
                    if (LightmapSettings.lightmaps[lightmapIndex] != null)
                    {
                        lightmapsToBackup.Add(lightmapIndex);
                    }
                }

                //Find to what triangle does the point belong to
                //UpdateLightmap(obj);
            }

            string[] lightmapPaths = new string[LightmapSettings.lightmaps.Length];

            int lightmapsCount = 0;

            foreach (int lightmapIndex in lightmapsToBackup)
            {
                Texture2D lightmapFar = LightmapSettings.lightmaps[lightmapIndex].lightmapColor;

                if (lightmapFar == null)
                {
                    continue;
                }

                string lightMapAssetPath = AssetDatabase.GetAssetPath(lightmapFar);

                //Debug.Log("lightMapAssetPath for " + lightmapIndex + " is " + lightMapAssetPath);

                if (lightMapAssetPath == null)
                {
                    continue;
                }

                if (lightMapAssetPath.Length <= 0)
                {
                    continue;
                }

                if (WPHelper.HasSuffix(lightMapAssetPath, "__WP"))
                {
                    string originalLightmapPath = WPHelper.RemoveSuffixFromFilename(lightMapAssetPath, "__WP");
                    //Debug.Log("WaterPlus lightmap already exists. Will be using the original one at path " + originalLightmapPath);

                    if (!File.Exists(originalLightmapPath))
                    {
                        Debug.LogError("Cannot find the original lightmap at path " + originalLightmapPath + ". Aborting");
                        return(null);
                    }

                    lightMapAssetPath = originalLightmapPath;
                }

                string waterPlusLightmapAssetPath = WPHelper.AddSuffixToFilename(lightMapAssetPath, "__WP");

                AssetDatabase.DeleteAsset(waterPlusLightmapAssetPath);
                AssetDatabase.CopyAsset(lightMapAssetPath, waterPlusLightmapAssetPath);

                AssetDatabase.ImportAsset(waterPlusLightmapAssetPath, ImportAssetOptions.ForceUpdate);
                AssetDatabase.Refresh();

                lightmapPaths[lightmapIndex] = WPHelper.AssetPathToFilePath(waterPlusLightmapAssetPath);

                lightmapsCount++;

                //LightmapSettings.lightmaps[ lightmapIndex ].lightmapFar = AssetDatabase.LoadAssetAtPath( waterPlusLightmapAssetPath,
                //																		typeof(Texture2D) ) as Texture2D;
            }

            //Load the new lightmaps
            LightmapData[] lightmapsData = new LightmapData[LightmapSettings.lightmaps.Length];

            for (int i = 0; i < lightmapPaths.Length; i++)
            {
                bool shouldUseOriginalLM = false;

                if (lightmapPaths[i] == null)
                {
                    shouldUseOriginalLM = true;
                }
                else if (lightmapPaths[i].Length <= 0)
                {
                    shouldUseOriginalLM = true;
                }

                if (!shouldUseOriginalLM)
                {
                    //Debug.Log("!shouldUseOriginalLM");
                    LightmapData lmData = new LightmapData();

                    //AssetDatabase.Refresh();
                    //AssetDatabase.ImportAsset( lightmapPaths[i], ImportAssetOptions.ForceSynchronousImport );
                    //AssetDatabase.Refresh();

                    lmData.lightmapColor = AssetDatabase.LoadAssetAtPath(WPHelper.FilePathToAssetPath(lightmapPaths[i]), typeof(Texture2D)) as Texture2D;

                    if (lmData.lightmapColor == null)
                    {
                        Debug.LogWarning("lmData.lightmapFar == null for " + WPHelper.FilePathToAssetPath(lightmapPaths[i]));
                        lmData.lightmapColor = LightmapSettings.lightmaps[i].lightmapColor;
                    }

                    //if (LightmapSettings.lightmaps[i].lightmapNear != null)
                    lmData.lightmapDir = LightmapSettings.lightmaps[i].lightmapDir;

                    lightmapsData[i] = lmData;
                }
                else
                {
                    lightmapsData[i] = LightmapSettings.lightmaps[i];
                }
            }

            LightmapSettings.lightmaps = lightmapsData;

            if (lightmapsCount <= 0)
            {
                Debug.LogError("Nothing to bake - no lightmaps found.");
                return(null);
            }

            return(lightmapPaths);
        }
示例#7
0
        private static void BakeLightmaps(WPLightmapData lightmapData)
        {
//			Debug.Log ("waterLevel: " + lightmapData.waterLevel);
//			Debug.Log ("wetnessHeight: " + lightmapData.wetnessHeight);
//			Debug.Log ("wetnessAmount: " + lightmapData.wetnessAmount);
            //
            //Load all of the lightmaps
            ImageData[] imagesData = new ImageData[lightmapData.lightmapFiles.Length];

            for (int lightmapIndex = 0; lightmapIndex < lightmapData.lightmapFiles.Length; lightmapIndex++)
            {
                bool shouldSkipFile = false;
                //Don't load non-used lightmaps
                if (lightmapData.lightmapFiles [lightmapIndex] == null)
                {
                    shouldSkipFile = true;
                }
                else if (lightmapData.lightmapFiles.Length <= 0)
                {
                    shouldSkipFile = true;
                }

                if (shouldSkipFile)
                {
                    Debug.Log("Skipping lightmap " + lightmapIndex + " because the lightmap is non-used");
                    continue;
                }

                string filePath = lightmapData.lightmapFiles [lightmapIndex];
                //string filePath = "C:/Users/Me/Desktop/Water+/iPhone4_hq_1.png";
                //string filePath = "1/LightmapFar-0.exr";
                //string filePath = "C:/Users/Me/waterplus/Assets/WaterPlus/Water_Island/LightmapFar-0.exr";
                //Debug.Log("lightmap path: " + filePath);
                imagesData [lightmapIndex] = new ImageData(filePath);

                /*for (int i = 0; i < imagesData[lightmapIndex].width * imagesData[lightmapIndex].height; i++) {
                 *      imagesData[lightmapIndex].pixels[i].r = imagesData[lightmapIndex].pixels[i].r * imagesData[lightmapIndex].pixels[i].r * .5f;
                 *      imagesData[lightmapIndex].pixels[i].g = imagesData[lightmapIndex].pixels[i].g * imagesData[lightmapIndex].pixels[i].g * 2.0f;
                 *      imagesData[lightmapIndex].pixels[i].b = imagesData[lightmapIndex].pixels[i].b * imagesData[lightmapIndex].pixels[i].b;
                 * }*/

                //Debug.Log("Successfully loaded lightmap at path " + filePath);
                //break;
            }

            //Debug.Log ("Successfully loaded lightmaps.");

            //return;

            System.DateTime bakeStartTime = System.DateTime.Now;

            //int count = 0;

            //1. Go over all pixels of the mesh
            //2. Convert UV to vertex
            //3. If the vertex is within water line, update the lightmap.
            //Debug.Log ("Updating lightmaps.");
            int bakeCount          = 0;
            int totalObjectsToBake = lightmapData.meshes.Length + lightmapData.terrains.Length;

            //
            //Regular meshes
            foreach (WPMesh obj in lightmapData.meshes)
            {
                if (obj.lightmapIndex < 0 || obj.lightmapIndex >= imagesData.Length)
                {
                    Debug.Log("skipping " + obj + " because of a wrong lightmapIndex: " + obj.lightmapIndex);
                    continue;
                }

                //Calculate object's texel size
                ImageData lightmapUsed       = imagesData [obj.lightmapIndex];
                int       lightmapResolution = lightmapUsed.width;
                Vector4   tilingOffset       = obj.tilingOffset;

                if (lightmapResolution == 0)
                {
                    Debug.Log("error: lightmapResolution == 0");
                    continue;
                }

                if (tilingOffset.x == 0)
                {
                    Debug.LogError("error: tilingOffset.x == 0");
                    continue;
                }

                float pixelSize = 1.0f / (tilingOffset.x * (float)lightmapResolution);

                //Debug.Log("tilingOffset: " + tilingOffset.ToString() + " " + lightmapResolution);

                //Console

                //Debug.Log("2");

                Vector2[] meshUVs = obj.uvs;
                if (meshUVs == null)
                {
                    Debug.Log("No UVs found for " + obj.name);
                    continue;
                }

                bakeCount++;

                //long searchIterations = ((long)(1.0f / (pixelSize * pixelSize)) * (long)obj.vertexCount);


                //Debug.Log ("baking " + obj.name + " with " + searchIterations +
                //                  " search iterations; progress: " + (100.0f * bakeCount / lightmapData.meshes.Length).ToString("0") + "%" );
                //Debug.Log ("baking " + obj.name + ". total progress: " + (100.0f * bakeCount / totalObjectsToBake).ToString("0") + "%" );

                //Debug.Log(obj.name + " at position " + obj.);
                //Debug.Log ("pixelSize: " + pixelSize + " iterations: " + (1.0f / (pixelSize * pixelSize)));


                //int verticesFound = 0;
                //int verticesNotFound = 0;
                //Iterate over all UVs in the mesh
                //float previousProgress = 0.0f;
                //int totalPixels = 0;
                //int pixelsProcessed = 0;

                int updatedPixels = 0;

                //Debug.Log("pixelSize: " + pixelSize);
                Matrix4x4 tempMatrix = new Matrix4x4();
                tempMatrix.SetRow(0, obj.localToWorldMatrix[0]);
                tempMatrix.SetRow(1, obj.localToWorldMatrix[1]);
                tempMatrix.SetRow(2, obj.localToWorldMatrix[2]);
                tempMatrix.SetRow(3, obj.localToWorldMatrix[3]);
                //Debug.Log( tempMatrix.GetRow(3) );
                //Debug.Log("1 * matrix: " + tempMatrix.MultiplyPoint(Vector3.one) );


                for (float u = 0.0f; u < 1.0f; u += pixelSize)
                {
                    //Progress for large objects
                    //if (1.0f / (pixelSize * pixelSize) >= 10000.0f) {
                    //Make sure to log only every percent, not less
//					if (u - previousProgress >= .01f) {
//						Console.Write("\r\t" + obj.name + " progress: " + (u * 100.0f).ToString("0") + "%");
//						previousProgress = u;
//					}
                    //}

                    for (float v = 0.0f; v < 1.0f; v += pixelSize)
                    {
                        //totalPixels++;

                        //Convert UV to vertex position
                        Vector2 currentUV   = new Vector2(u, v);
                        bool    vertexFound = false;
                        Vector3 vertexPos;
                        WPHelper.UVToVertex(currentUV, obj, meshUVs, out vertexFound, out vertexPos);

                        //Update the lightmap
                        //vertexFound = true;
                        if (vertexFound)
                        {
                            vertexPos = tempMatrix.MultiplyPoint(vertexPos);

                            //if (u >= .45f && u <= .55f)
                            //if (1.0f / (pixelSize * pixelSize) >= 10000.0f)
                            //	Console.Write(vertexPos.y + "\t");

                            //Debug.Log("vertexPos.y: " + vertexPos.y);
                            if (vertexPos.y <= lightmapData.waterLevel + lightmapData.wetnessHeight)
                            {
                                //Convert object's UV to lightmap's UV
                                Vector2 lightmapUV = currentUV;
                                lightmapUV.x *= tilingOffset.x;
                                lightmapUV.y *= tilingOffset.y;

                                lightmapUV.x += tilingOffset.z;
                                lightmapUV.y += tilingOffset.w;

                                int lightmapX = (int)(lightmapUV.x * (float)lightmapResolution);
                                int lightmapY = (int)(lightmapUV.y * (float)lightmapResolution);


                                if (lightmapX < 0 || lightmapX >= lightmapResolution || lightmapY < 0 || lightmapY >= lightmapResolution)
                                {
                                    //Debug.LogWarning("lightmapX: " + lightmapX + " lightmapY: " + lightmapY);
                                }
                                else
                                {
                                    //lightmapPixels[lightmapY * lightmapResolution + lightmapX] = Color.yellow;
                                    float gradientAmount = 0.0f;

                                    if (vertexPos.y <= lightmapData.waterLevel)
                                    {
                                        gradientAmount = 1.0f;
                                    }
                                    else if (vertexPos.y > lightmapData.waterLevel + lightmapData.wetnessHeight)
                                    {
                                        gradientAmount = 0.0f;
                                    }
                                    else
                                    {
                                        gradientAmount = 1.0f - (vertexPos.y - lightmapData.waterLevel) / lightmapData.wetnessHeight;
                                    }

                                    gradientAmount = 1.0f - gradientAmount * lightmapData.wetnessAmount;

                                    gradientAmount = Mathf.Clamp01(gradientAmount);                                             //Just in case

                                    lightmapUsed.dstPixels [lightmapY * lightmapResolution + lightmapX].r = lightmapUsed.srcPixels[lightmapY * lightmapResolution + lightmapX].r * gradientAmount;
                                    lightmapUsed.dstPixels [lightmapY * lightmapResolution + lightmapX].g = lightmapUsed.srcPixels[lightmapY * lightmapResolution + lightmapX].g * gradientAmount;
                                    lightmapUsed.dstPixels [lightmapY * lightmapResolution + lightmapX].b = lightmapUsed.srcPixels[lightmapY * lightmapResolution + lightmapX].b * gradientAmount;
                                    //pixelsProcessed++;

                                    updatedPixels++;

                                    //lightmapPixels [lightmapY * lightmapResolution + lightmapX].r = 1.0f;
                                    //lightmapPixels [lightmapY * lightmapResolution + lightmapX].g = 1.0f;
                                    //lightmapPixels [lightmapY * lightmapResolution + lightmapX].b = 0.0f;
                                }
                            }

                            //verticesFound++;
                        }
                    }
                }

//				Console.Write("\r\t" + obj.name + " progress:  100%");
//				Console.Write("\n");
//				Debug.Log("lowestVertexLocal: " + lowestVertexLocal + "; heighestVertexLocal: " + heighestVertexLocal +
//				                  "; lowestVertexWorld: " + lowestVertexWorld + "; heighestVertexWorld: " + heighestVertexWorld);
            }

            //
            //Terrains
            foreach (WPTerrainData obj in lightmapData.terrains)
            {
                if (obj.lightmapIndex < 0 || obj.lightmapIndex >= imagesData.Length)
                {
                    Debug.Log("skipping " + obj + " because of a wrong lightmapIndex: " + obj.lightmapIndex);
                    continue;
                }

                //Calculate object's texel size
                ImageData lightmapUsed       = imagesData [obj.lightmapIndex];
                int       lightmapResolution = lightmapUsed.width;

                if (lightmapResolution == 0)
                {
                    Debug.Log("error: lightmapResolution == 0");
                    continue;
                }

                float pixelSize = 1.0f / (float)lightmapResolution;

                bakeCount++;

//				Debug.Log ("baking " + obj.name + ". total progress: " + (100.0f * bakeCount / totalObjectsToBake).ToString("0") + "%" );

//				float previousProgress = 0.0f;

                for (float u = 0.0f; u < 1.0f; u += pixelSize)
                {
                    //Progress for large objects
                    //if (1.0f / (pixelSize * pixelSize) >= 10000.0f) {
                    //Make sure to log only every percent, not less
//					if (u - previousProgress >= .01f) {
//						Console.Write("\r\t" + obj.name + " progress: " + (u * 100.0f).ToString("0") + "%");
//						previousProgress = u;
//					}

                    for (float v = 0.0f; v < 1.0f; v += pixelSize)
                    {
                        //Update the lightmap
                        //int heightmapX = obj.width - (int)(u * (float)obj.width);
                        //int heightmapY = obj.height - (int)(v * (float)obj.height);
                        int heightmapX = (int)(v * (float)obj.height);
                        int heightmapY = (int)(u * (float)obj.width);

                        if (heightmapX < 0 || heightmapX >= obj.width || heightmapY < 0 || heightmapY >= obj.height)
                        {
                            continue;
                        }

                        int lightmapX = (int)(u * (float)lightmapResolution);
                        int lightmapY = (int)(v * (float)lightmapResolution);

                        if (lightmapX < 0 || lightmapX >= lightmapResolution || lightmapY < 0 || lightmapY >= lightmapResolution)
                        {
                            continue;
                        }

                        float yPos = obj.position.y + obj.heightmap[heightmapY * obj.height + heightmapX];

                        if (yPos <= lightmapData.waterLevel + lightmapData.wetnessHeight)
                        {
                            //if (yPos > 0)
                            //	Debug.Log("yPos: " + yPos + " waterLevel: " + lightmapData.waterLevel);

                            float gradientAmount = 0.0f;

                            if (yPos <= lightmapData.waterLevel)
                            {
                                gradientAmount = 1.0f;
                            }
                            else if (yPos > lightmapData.waterLevel + lightmapData.wetnessHeight)
                            {
                                gradientAmount = 0.0f;
                            }
                            else
                            {
                                gradientAmount = 1.0f - (yPos - lightmapData.waterLevel) / lightmapData.wetnessHeight;
                            }

                            gradientAmount = 1.0f - gradientAmount * lightmapData.wetnessAmount;

                            gradientAmount = Mathf.Clamp01(gradientAmount);                                     //Just in case

                            lightmapUsed.dstPixels [lightmapY * lightmapResolution + lightmapX].r = lightmapUsed.srcPixels[lightmapY * lightmapResolution + lightmapX].r * gradientAmount;
                            lightmapUsed.dstPixels [lightmapY * lightmapResolution + lightmapX].g = lightmapUsed.srcPixels[lightmapY * lightmapResolution + lightmapX].r * gradientAmount;
                            lightmapUsed.dstPixels [lightmapY * lightmapResolution + lightmapX].b = lightmapUsed.srcPixels[lightmapY * lightmapResolution + lightmapX].r * gradientAmount;
                        }

                        //verticesFound++;
                    }
                }
//				Console.Write("\r\t" + obj.name + " progress:  100%");
//				Console.Write("\n");
            }


            //
            //Save all the lightmaps
            for (int i = 0; i < imagesData.Length; i++)
            {
                //string newPath = AppDomain.CurrentDomain.BaseDirectory + "Lightmap_" + i + ".exr";
                //imagesData[i].Save( newPath );
                if (null == imagesData[i])
                {
                    continue;
                }

                imagesData[i].Save();
            }

            Debug.Log("Successfully updated the lightmaps in " + (System.DateTime.Now - bakeStartTime).TotalSeconds + " seconds.");
        }
示例#8
0
        private void ThumbnailViewBindData()
        {
            int          pageSize = PageColumns * PageRows;
            const string strPageToken = "page_token=";
            string       searchText, searchBy, nextpage_url, page_token, metaDataSearch;

            searchText = txtSearch.Text;
            searchBy   = ddlSearch.SelectedItem.Value;

            searchText     = txtSearch.Text.Equals("Enter Search Text") ? string.Empty : Server.HtmlEncode(WPHelper.escapteChar(txtSearch.Text.Trim()));
            searchBy       = ddlSearch.SelectedItem.Value;
            metaDataSearch = txtCustom.Text.Equals("Enter Metadata Key") ? string.Empty : Server.HtmlEncode(WPHelper.escapteChar(txtCustom.Text.Trim()));

            if (searchBy == "metadata")
            {
                if (string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(metaDataSearch))
                {
                    searchBy = "metadata." + metaDataSearch;
                }
                if (string.IsNullOrEmpty(searchText) && string.IsNullOrEmpty(metaDataSearch))
                {
                    searchBy = string.Empty; // if both text empty means it is like general search
                }
                if (!string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(metaDataSearch))
                {
                    searchBy = "metadata." + metaDataSearch;
                }
            }

            int currentPage = (int)ViewState["PageCount"];

            lblPageCount.Text = "Page No :" + currentPage.ToString();

            if (ViewState["PageToken" + (currentPage - 1).ToString()] != null)
            {
                page_token = ViewState["PageToken" + (currentPage - 1).ToString()].ToString();
            }
            else
            {
                page_token = "";
            }

            try
            {
                OoyalaAssetDataResult cdata = new OoyalaAssetDataResult();
                cdata = OoyalaMediaUtils.GetLimitedAssets(SecretKey, APIKey, pageSize, searchBy, searchText, page_token, false, false);

                nextpage_url = cdata.next_page;
                if (nextpage_url != null)
                {
                    if (nextpage_url.IndexOf("page_token=") >= 0)
                    {
                        page_token = nextpage_url.Substring(nextpage_url.IndexOf(strPageToken) + strPageToken.Length);
                    }
                    else
                    {
                        page_token = "";
                    }
                }
                else
                {
                    page_token = "";
                }

                ViewState["PageToken" + currentPage.ToString()] = page_token;
                ViewState["MaxPageCount"] = currentPage;

                if (!string.IsNullOrEmpty(cdata.next_page))
                {
                    btnNext.Visible = true;
                }
                else
                {
                    btnNext.Visible = false;
                }

                var assetPreviewList = from itm in cdata.items
                                       select new
                {
                    itm.name,
                    itm.preview_image_url
                };
                dtlAsssets.DataSource    = assetPreviewList;
                dtlAsssets.RepeatColumns = PageColumns;
                dtlAsssets.DataBind();

                if (assetPreviewList.Count() == 0)
                {
                    lblPageCount.Text       = string.Empty;
                    tblMessage.Visible      = true;
                    lblDataListMessage.Text = "No Data Found!";
                }
            }
            catch (Exception e)
            {
                lblResults.Text = e.Message;
            }
        }
        private void DetailsViewBindData()
        {
            int pageSize = (PageLimit >= 10) ? PageLimit : 10;

            const string strPageToken = "page_token=";
            string       searchText, searchBy, nextpage_url, page_token, metaDataSearch;

            searchText     = txtSearch.Text.Equals("Enter Search Text")? string.Empty: Server.HtmlEncode(WPHelper.escapteChar(txtSearch.Text.Trim()));
            searchBy       = ddlSearch.SelectedItem.Value;
            metaDataSearch = txtCustom.Text.Equals("Enter Metadata Key")?string.Empty : Server.HtmlEncode(WPHelper.escapteChar(txtCustom.Text.Trim()));

            //if (searchBy == "metadata")
            //{
            //    searchBy = "metadata." + metaDataSearch;
            //}

            if (searchBy == "metadata")
            {
                if (string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(metaDataSearch))
                {
                    searchBy = "metadata." + metaDataSearch;
                }
                if (string.IsNullOrEmpty(searchText) && string.IsNullOrEmpty(metaDataSearch))
                {
                    searchBy = string.Empty; // if both text empty means it is like general search, no need come for where conditions
                }
                if (!string.IsNullOrEmpty(searchText) && !string.IsNullOrEmpty(metaDataSearch))
                {
                    searchBy = "metadata." + metaDataSearch;
                }
            }


            int currentPage = (int)ViewState["PageCount"];

            lblPageCount.Text = "Page No :" + currentPage.ToString();

            if (ViewState["PageToken" + (currentPage - 1).ToString()] != null)
            {
                page_token = ViewState["PageToken" + (currentPage - 1).ToString()].ToString();
            }
            else
            {
                page_token = "";
            }

            string APIKey, SecretKey;

            try
            {
                APIKey    = txtAPIKey.Text;
                SecretKey = txtSecretKey.Text;
                OoyalaAssetDataResult cdata = new OoyalaAssetDataResult();
                cdata = OoyalaMediaUtils.GetLimitedAssets(SecretKey, APIKey, pageSize, searchBy, searchText, page_token, true, true);

                nextpage_url = cdata.next_page;
                if (nextpage_url != null)
                {
                    if (nextpage_url.IndexOf("page_token=") >= 0)
                    {
                        page_token = nextpage_url.Substring(nextpage_url.IndexOf(strPageToken) + strPageToken.Length);
                    }
                    else
                    {
                        page_token = "";
                    }
                }
                else
                {
                    page_token = "";
                }

                ViewState["PageToken" + currentPage.ToString()] = page_token;
                ViewState["MaxPageCount"] = currentPage;

                if (!string.IsNullOrEmpty(cdata.next_page))
                {
                    btnNext.Visible = true;
                }
                else
                {
                    btnNext.Visible = false;
                }

                var assetPreviewList = from itm in cdata.items select itm;

                dtgAssets.DataSource   = assetPreviewList;
                dtgAssets.DataKeyNames = new string[] { "embed_code" };
                dtgAssets.DataBind();
                if (assetPreviewList.Count() == 0)
                {
                    lblPageCount.Text = string.Empty;
                }
            }
            catch (Exception e)
            {
                lblResults.Text = e.Message;
            }
        }