コード例 #1
0
        private void UploadOBJ(LMAStudio.StreamVR.Common.Models.Material dto, byte[] file_bytes, string filename)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                MultipartFormDataContent form = new MultipartFormDataContent();

                form.Add(new StringContent(dto.Name ?? ""), "materialName");
                form.Add(new StringContent(filename ?? ""), "fileName");
                form.Add(new ByteArrayContent(file_bytes, 0, file_bytes.Length), "file", filename);

                string url = $"{_modelServerUrl}/api/material/{dto.Id}";
                _log("Uploading material to: " + url);
                HttpResponseMessage response = httpClient.PostAsync(url, form).Result;

                response.EnsureSuccessStatusCode();

                string sd = response.Content.ReadAsStringAsync().Result;
            }
        }
コード例 #2
0
        public Message Execute(Document doc, Message msg)
        {
            JObject msgData   = JObject.Parse(msg.Data);
            string  elementId = msgData["Id"].ToString();

            Material mat = doc.GetElement(new ElementId(Int32.Parse(elementId))) as Material;

            try
            {
                System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch();
                s.Start();

                LMAStudio.StreamVR.Common.Models.Material dto = _converter.ConvertToDTO(mat).ToObject <LMAStudio.StreamVR.Common.Models.Material>();

                AppearanceAssetElement assetElement = doc.GetElement(mat.AppearanceAssetId) as AppearanceAssetElement;
                Asset asset = assetElement?.GetRenderingAsset();

                if (asset == null)
                {
                    return(new Message
                    {
                        Type = "EMPTY",
                        Data = $"No material asset found for: {mat.Name} ({mat.Id})"
                    });
                }

                string bmpPathFull = "";

                for (int i = 0; i < asset.Size; i++)
                {
                    AssetProperty prop = asset.Get(i);
                    if (textureProperties.Contains(prop.Name) && prop.NumberOfConnectedProperties > 0)
                    {
                        Asset connectedAsset = prop.GetSingleConnectedAsset();
                        for (int j = 0; j < connectedAsset.Size; j++)
                        {
                            AssetProperty prop2 = connectedAsset.Get(j);
                            if (prop2.Name == "unifiedbitmap_Bitmap")
                            {
                                bmpPathFull = (prop2 as AssetPropertyString).Value;
                            }
                        }
                    }
                }

                if (string.IsNullOrEmpty(bmpPathFull))
                {
                    return(new Message
                    {
                        Type = "EMPTY",
                        Data = $"No exportable material found for: {mat.Name} ({mat.Id})"
                    });
                }

                string texturesDirectory = "C:\\Program Files (x86)\\Common Files\\Autodesk Shared\\Materials\\Textures";
                string bmpPath           = bmpPathFull.Split('|').LastOrDefault();

                string fullPath         = texturesDirectory + "\\" + bmpPath;
                string materialFileName = new FileInfo(fullPath).Name;

                byte[] materialAlbedo = File.ReadAllBytes(fullPath);

                UploadOBJ(dto, materialAlbedo, materialFileName);

                _log($"Export/Upload time for {1} materials: {s.ElapsedMilliseconds}ms");
                s.Stop();

                return(new Message
                {
                    Type = "MAT",
                    Data = mat.Id.ToString()
                });
            }
            catch (Exception e)
            {
                return(new Message
                {
                    Type = "ERROR",
                    Data = $"Error: {mat.Name} ({mat.Id}) {e.ToString()}"
                });
            }
        }