Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        private void WriteXmlLibraryGeometries()
        {
            this.WriteXmlLibraryGeometriesBegin();

            foreach (KeyValuePair <Tuple <Document, ElementId>, IList <ModelGeometry> > current in this.documentAndMaterialIdToGeometries)
            {
                Tuple <Document, ElementId> key = current.Key;
                if (current.Value != null && current.Value.Count > 0)
                {
                    ModelMaterial exportedMaterial = this.documentAndMaterialIdToExportedMaterial[key];
                    this.sb.Clear();
                    this.WriteXmlGeometryBegin(key.GetHashCode(), exportedMaterial);
                    this.WriteXmlGeometrySourcePositions(key.GetHashCode(), current.Value);
                    this.WriteXmlGeometrySourceNormals(key.GetHashCode(), current.Value);
                    this.WriteXmlGeometrySourceMap(key.GetHashCode(), exportedMaterial, current.Value);
                    this.WriteXmlGeometryVertices(key.GetHashCode());
                    this.WriteXmlGeometryTrianglesWithMap(key.GetHashCode(), current.Value);
                    this.WriteXmlGeometryEnd();
                    int val = 10485760;
                    while (this.sb.Length > 0)
                    {
                        int length = Math.Min(val, this.sb.Length);
                        this.streamWriter.Write(this.sb.ToString(0, length));
                        this.sb.Remove(0, length);
                    }
                }
            }
            this.WriteXmlLibraryGeometriesEnd();
        }
Exemplo n.º 2
0
        private void WriteXmlGeometrySourceMap(int documentAndMaterialIdHash, ModelMaterial exportedMaterial, IList <ModelGeometry> geometries)
        {
            Func <ModelGeometry, int> arg_20_1;

            if ((arg_20_1 = Inner.T__19_0) == null)
            {
                arg_20_1 = (Inner.T__19_0 = new Func <ModelGeometry, int>(Inner.T.b__19_0));
            }
            //计算points(顶点)数
            int num = geometries.Sum(arg_20_1);

            this.sb.AppendFormat("<source id=\"geom-{0}-map\">\n", documentAndMaterialIdHash);
            this.sb.AppendFormat("<float_array id=\"geom-{0}-map-array\" count=\"{1}\">\n", documentAndMaterialIdHash, num * 2);
            //迭代geometries
            foreach (ModelGeometry current in geometries)
            {
                for (int i = 0; i < current.Uvs.Count; i++)
                {
                    UV     uV   = current.Uvs[i];
                    double num2 = uV.U;
                    double num3 = uV.V;
                    if (Math.Abs(exportedMaterial.TextureRotationAngle) > 1.0)
                    {
                        double textureOffsetU = exportedMaterial.TextureOffsetU;
                        double textureOffsetV = exportedMaterial.TextureOffsetV;
                        num2 = Math.Cos(exportedMaterial.TextureRotationAngle) * (uV.U - textureOffsetU) - Math.Sin(exportedMaterial.TextureRotationAngle) * (uV.V - textureOffsetV) + textureOffsetU;
                        num3 = Math.Sin(exportedMaterial.TextureRotationAngle) * (uV.U - textureOffsetU) + Math.Cos(exportedMaterial.TextureRotationAngle) * (uV.V - textureOffsetV) + textureOffsetV;
                    }
                    num2           = (num2 - exportedMaterial.TextureOffsetU) * exportedMaterial.TextureScaleU;
                    num3           = (num3 - exportedMaterial.TextureOffsetV) * exportedMaterial.TextureScaleV;
                    current.Uvs[i] = new UV(num2, num3);
                }
                for (int j = 0; j < current.Uvs.Count; j++)
                {
                    UV uV2 = current.Uvs[j];
                    this.sb.AppendFormat(CultureInfo.InvariantCulture.NumberFormat, "{0:0.##} {1:0.##} ", new object[]
                    {
                        uV2.U,
                        uV2.V
                    });
                }
            }
            this.sb.Append("</float_array>\n");
            this.sb.Append("<technique_common>\n");
            this.sb.AppendFormat("<accessor source=\"#geom-{0}-map-array\" count=\"{1}\" stride=\"2\">\n", documentAndMaterialIdHash, num);
            this.sb.Append("<param name=\"S\" type=\"float\"/>\n");
            this.sb.Append("<param name=\"T\" type=\"float\"/>\n");
            this.sb.Append("</accessor>\n");
            this.sb.Append("</technique_common>\n");
            this.sb.Append("</source>\n");
        }
Exemplo n.º 3
0
        public void SetLibraryGeometries()
        {
            foreach (KeyValuePair <Tuple <Document, ElementId>, IList <ModelGeometry> > current in this.Geometries)
            {
                Tuple <Document, ElementId> key = current.Key;
                if (current.Value != null && current.Value.Count > 0)
                {
                    ModelMaterial exportedMaterial = this.Material[key];
                    string        nodeName         = exportedMaterial.Name;


                    GeometrySourcePositions(key.GetHashCode(), current.Value, nodeName);
                    GeometrySourceNormals(key.GetHashCode(), current.Value);
                    GeometrySourceMap(key.GetHashCode(), exportedMaterial, current.Value);
                    GeometryVertices(key.GetHashCode());
                    GeometryTrianglesWithMap(key.GetHashCode(), current.Value);
                }
            }
        }
Exemplo n.º 4
0
        private ModelMaterial ExportMaterial(Tuple <Document, ElementId> documentAndMaterialId)
        {
            Document      item             = documentAndMaterialId.Item1;
            ElementId     item2            = documentAndMaterialId.Item2;
            ModelMaterial exportedMaterial = new ModelMaterial();
            Material      material         = item.GetElement(item2) as Material;

            if (material != null && material.IsValidObject)
            {
                exportedMaterial.Name = textureFinder.CleanName(material.Name, userSetting);
                if (material.Color.IsValid)
                {
                    exportedMaterial.Color = System.Drawing.Color.FromArgb(material.Color.Red, material.Color.Green, material.Color.Blue);
                }
                exportedMaterial.Shininess    = material.Shininess;
                exportedMaterial.Transparency = material.Transparency;
                if (material.AppearanceAssetId != ElementId.InvalidElementId)
                {
                    Asset asset = (item.GetElement(material.AppearanceAssetId) as AppearanceAssetElement).GetRenderingAsset();
                    if (asset.Size == 0)
                    {
                        AssetSetIterator assetSetIterator = libraryAssetSet.ForwardIterator();
                        while (assetSetIterator.MoveNext())
                        {
                            Asset asset2 = assetSetIterator.Current as Asset;
                            if (asset2 != null && asset2.Name == asset.Name)
                            {
                                asset = asset2;
                                break;
                            }
                        }
                    }
                    textureFinder.FindDiffuseTexturePathFromAsset(exportedMaterial, asset);
                    AssetPropertyDoubleArray4d assetPropertyDoubleArray4d = asset.FindByName("generic_diffuse") as AssetPropertyDoubleArray4d;
                    if (assetPropertyDoubleArray4d != null)
                    {
                        exportedMaterial.Color = System.Drawing.Color.FromArgb((byte)(assetPropertyDoubleArray4d.GetValueAsDoubles().ElementAt(1) * 255.0), ((byte)(assetPropertyDoubleArray4d.GetValueAsDoubles().ElementAt(1) * 255.0)), (byte)(assetPropertyDoubleArray4d.GetValueAsDoubles().ElementAt(2) * 255.0));
                    }
                }
            }
            return(exportedMaterial);
        }
Exemplo n.º 5
0
 private void WriteXmlLibraryMaterials()
 {
     this.streamWriter.Write("<library_materials>\n");
     foreach (KeyValuePair <Tuple <Document, ElementId>, ModelMaterial> current in this.documentAndMaterialIdToExportedMaterial)
     {
         int           hashCode = current.Key.GetHashCode();
         ModelMaterial value    = current.Value;
         string        text     = this.Utf16ToUtf8(value.Name);
         this.streamWriter.Write(string.Concat(new string[]
         {
             "<material id=\"material-",
             hashCode.ToString(),
             "\" name=\"",
             text,
             "\">\n"
         }));
         this.streamWriter.Write("<instance_effect url=\"#effect-" + hashCode.ToString() + "\" />\n");
         this.streamWriter.Write("</material>\n");
     }
     this.streamWriter.Write("</library_materials>\n");
 }
Exemplo n.º 6
0
        //TODO
        private void WriteXmlLibraryGeometriesSeparate()
        {
            this.WriteXmlLibraryGeometriesBegin();
            //迭代documentAndMaterialIdToGeometries
            foreach (KeyValuePair <Tuple <Document, ElementId>, IList <ModelGeometry> > current in this.documentAndMaterialIdToGeometries)
            {
                //将文档,及元素ID赋值给key
                Tuple <Document, ElementId> key = current.Key;
                //迭代current.Value也即是ExportedGeometry
                foreach (ModelGeometry current2 in current.Value)
                {
                    //新建类型为ExportedGeometry的列表
                    IList <ModelGeometry> list = new List <ModelGeometry>();
                    //将导出模型加入到列表中。
                    list.Add(current2);
                    //判断列表非空并大于零
                    if (list != null && list.Count > 0)
                    {
                        ModelMaterial exportedMaterial = this.documentAndMaterialIdToExportedMaterial[key];
                        this.sb.Clear();
                        this.WriteXmlGeometryBegin(current2.GetHashCode(), exportedMaterial);

                        this.WriteXmlGeometrySourcePositions(current2.GetHashCode(), list);
                        this.WriteXmlGeometrySourceNormals(current2.GetHashCode(), list);
                        this.WriteXmlGeometrySourceMap(current2.GetHashCode(), exportedMaterial, list);
                        this.WriteXmlGeometryVertices(current2.GetHashCode());
                        this.WriteXmlGeometryTrianglesWithMap(current2.GetHashCode(), list);

                        this.WriteXmlGeometryEnd();
                        this.streamWriter.Write(this.sb.ToString());
                    }
                    list.Clear();
                }
            }
            this.WriteXmlLibraryGeometriesEnd();
        }
Exemplo n.º 7
0
 internal string b__24_0(ModelMaterial o)
 {
     return(o.TexturePath);
 }
Exemplo n.º 8
0
 private void WriteXmlLibraryEffects()
 {
     this.streamWriter.Write("<library_effects>\n");
     foreach (KeyValuePair <Tuple <Document, ElementId>, ModelMaterial> current in this.documentAndMaterialIdToExportedMaterial)
     {
         int           hashCode = current.Key.GetHashCode();
         ModelMaterial value    = current.Value;
         this.streamWriter.Write(string.Concat(new string[]
         {
             "<effect id=\"effect-",
             hashCode.ToString(),
             "\" name=\"",
             this.Utf16ToUtf8(value.Name),
             "\">\n"
         }));
         this.streamWriter.Write("<profile_COMMON>\n");
         this.streamWriter.Write("<technique sid=\"common\">\n");
         this.streamWriter.Write("<phong>\n");
         this.streamWriter.Write("<ambient>\n");
         this.streamWriter.Write("<color>0.1 0.1 0.1 1.0</color>\n");
         this.streamWriter.Write("</ambient>\n");
         this.streamWriter.Write("<diffuse>\n");
         if (value.TexturePath.Length > 0)
         {
             this.streamWriter.Write("<texture texture=\"image-" + value.TexturePath.GetHashCode() + "\" texcoord=\"CHANNEL0\"/>\n");
         }
         else
         {
             this.streamWriter.Write(string.Concat(new string[]
             {
                 "<color>",
                 Convert.ToString((double)value.Color.R / 255.0, CultureInfo.InvariantCulture.NumberFormat),
                 " ",
                 Convert.ToString((double)value.Color.G / 255.0, CultureInfo.InvariantCulture.NumberFormat),
                 " ",
                 Convert.ToString((double)value.Color.B / 255.0, CultureInfo.InvariantCulture.NumberFormat),
                 " 1.0</color>\n"
             }));
         }
         this.streamWriter.Write("</diffuse>\n");
         this.streamWriter.Write("<specular>\n");
         this.streamWriter.Write("<color>1.0 1.0 1.0 1.0</color>\n");
         this.streamWriter.Write("</specular>\n");
         this.streamWriter.Write("<shininess>\n");
         this.streamWriter.Write("<float>" + Convert.ToString(value.Shininess, CultureInfo.InvariantCulture.NumberFormat) + "</float>\n");
         this.streamWriter.Write("</shininess>\n");
         this.streamWriter.Write("<reflective>\n");
         this.streamWriter.Write("<color>0 0 0 1.0</color>\n");
         this.streamWriter.Write("</reflective>\n");
         this.streamWriter.Write("<reflectivity>\n");
         this.streamWriter.Write("<float>1.0</float>\n");
         this.streamWriter.Write("</reflectivity>\n");
         this.streamWriter.Write("<transparent opaque=\"RGB_ZERO\">\n");
         this.streamWriter.Write("<color>1.0 1.0 1.0 1.0</color>\n");
         this.streamWriter.Write("</transparent>\n");
         this.streamWriter.Write("<transparency>\n");
         this.streamWriter.Write("<float>" + Convert.ToString(value.Transparency, CultureInfo.InvariantCulture.NumberFormat) + "</float>\n");
         this.streamWriter.Write("</transparency>\n");
         this.streamWriter.Write("</phong>\n");
         this.streamWriter.Write("</technique>\n");
         this.streamWriter.Write("</profile_COMMON>\n");
         this.streamWriter.Write("</effect>\n");
     }
     this.streamWriter.Write("</library_effects>\n");
 }
Exemplo n.º 9
0
 private void WriteXmlGeometryBegin(int documentAndMaterialIdHash, ModelMaterial exportedMaterial)
 {
     this.sb.AppendFormat("<geometry id=\"geom-{0}\" name=\"{1}\">\n", documentAndMaterialIdHash, this.Utf16ToUtf8(exportedMaterial.Name));
     this.sb.Append("<mesh>\n");
 }
Exemplo n.º 10
0
 private void GeometrySourceMap(int documentAndMaterialIdHash, ModelMaterial exportedMaterial, IList <ModelGeometry> geometries)
 {
 }
Exemplo n.º 11
0
 /// <summary>
 /// GetTexturePath2 获取贴图路径
 /// </summary>
 internal string GetTexturePath2(ModelMaterial o)
 {
     return(o.TexturePath);
 }
Exemplo n.º 12
0
 /// <summary>
 /// GetTexturePath2 获取贴图路径
 /// </summary>
 internal string GetTexturePath1(ModelMaterial o)             //GetTexturePath1
 {
     return(o.TexturePath);
 }
Exemplo n.º 13
0
 /// <summary>
 /// IsValidTexturePath 判断贴图路径是否为空。
 /// </summary>
 internal bool IsValidTexturePath(ModelMaterial m)
 {
     return(m.TexturePath != string.Empty);
 }
Exemplo n.º 14
0
        /// <summary>
        /// 从Asset资源中查找漫反射纹理路径
        /// </summary>
        /// <param name="exportedMaterial">被导出的材质</param>
        /// <param name="asset">Asset资源</param>
        public void FindDiffuseTexturePathFromAsset(ModelMaterial exportedMaterial, Asset asset)
        {
            //判读asset是否为空
            if (asset == null)
            {
                //为空结束函数。
                return;
            }
            try
            {
                //不为空 创建新的变量asset2,并调用本类中的查找贴图资源,条件为asset变量。
                Asset assetTexture = FindTextureAsset(asset);
                //判断 assetTexture 是否为空
                if (assetTexture != null)
                {
                    //非空则查找资源中的"unifiedbitmap_Bitmap"文件并修复文件路径为绝对路径。
                    exportedMaterial.TexturePath = (assetTexture.FindByName("unifiedbitmap_Bitmap") as AssetPropertyString).Value;
                    exportedMaterial.TexturePath = FixTexturePath(exportedMaterial.TexturePath);
                    //定义资源属性距离
                    AssetPropertyDistance assetPropertyDistance;
                    //判断资产中是否包含“texture_RealWorldScaleX”
                    if (assetTexture.FindByName("texture_RealWorldScaleX") != null)
                    {
                        //"包含texture_RealWorldScaleX"则将值赋值给assetPropertyDistance
                        assetPropertyDistance = (assetTexture.FindByName("texture_RealWorldScaleX") as AssetPropertyDistance);
                    }
                    else
                    {
                        //否则 "unifiedbitmap_RealWorldScaleX  真实世界尺度" 将未定义赋值给assetPropertyDistance
                        assetPropertyDistance = (assetTexture.FindByName("unifiedbitmap_RealWorldScaleX") as AssetPropertyDistance);
                    }
                    //判断距离属性非空,转换后的值(资源距离属性附加单位距离)除以1 得到小数,赋值给纹理U比例尺
                    if (assetPropertyDistance != null)
                    {
                        exportedMaterial.TextureScaleU = 1.0 / UnitUtils.ConvertToInternalUnits(assetPropertyDistance.Value, assetPropertyDistance.DisplayUnitType);
                    }

                    //创建新的资源距离属性2重复上述步骤,将纹理缩放赋值给exportedMaterial.TextureScaleV
                    AssetPropertyDistance assetPropertyDistance2;
                    if (assetTexture.FindByName("texture_RealWorldScaleY") != null)
                    {
                        assetPropertyDistance2 = (assetTexture.FindByName("texture_RealWorldScaleY") as AssetPropertyDistance);
                    }
                    else
                    {
                        assetPropertyDistance2 = (assetTexture.FindByName("unifiedbitmap_RealWorldScaleY") as AssetPropertyDistance);
                    }
                    if (assetPropertyDistance2 != null)
                    {
                        exportedMaterial.TextureScaleV = 1.0 / UnitUtils.ConvertToInternalUnits(assetPropertyDistance2.Value, assetPropertyDistance.DisplayUnitType);
                    }
                    //判断是否存在texture_RealWorldOffsetX 存在  创建assetPropertyDistance3,不存在默认使用未定义。
                    //将纹理贴图偏移量加上单位赋值给exportedMaterial.TextureOffsetU
                    AssetPropertyDistance assetPropertyDistance3;
                    if (assetTexture.FindByName("texture_RealWorldOffsetX") != null)
                    {
                        assetPropertyDistance3 = (assetTexture.FindByName("texture_RealWorldOffsetX") as AssetPropertyDistance);
                    }
                    else
                    {
                        assetPropertyDistance3 = (assetTexture.FindByName("unifiedbitmap_RealWorldOffsetX") as AssetPropertyDistance);
                    }
                    if (assetPropertyDistance3 != null)
                    {
                        exportedMaterial.TextureOffsetU = UnitUtils.ConvertToInternalUnits(assetPropertyDistance3.Value, assetPropertyDistance3.DisplayUnitType);
                    }
                    AssetPropertyDistance assetPropertyDistance4;
                    if (assetTexture.FindByName("texture_RealWorldOffsetY") != null)
                    {
                        assetPropertyDistance4 = (assetTexture.FindByName("texture_RealWorldOffsetY") as AssetPropertyDistance);
                    }
                    else
                    {
                        assetPropertyDistance4 = (assetTexture.FindByName("unifiedbitmap_RealWorldOffsetY") as AssetPropertyDistance);
                    }
                    if (assetPropertyDistance4 != null)
                    {
                        exportedMaterial.TextureOffsetV = UnitUtils.ConvertToInternalUnits(assetPropertyDistance4.Value, assetPropertyDistance4.DisplayUnitType);
                    }
                    //查找texture_WAngle 并赋值给assetPropertyDoubl不存在则使用默认未定义。之后赋值给exportedMaterial.TextureRotationAngle加上某个数值。
                    AssetPropertyDouble assetPropertyDouble;
                    if (assetTexture.FindByName("texture_WAngle") != null)
                    {
                        assetPropertyDouble = (assetTexture.FindByName("texture_WAngle") as AssetPropertyDouble);
                    }
                    else
                    {
                        assetPropertyDouble = (assetTexture.FindByName("unifiedbitmap_WAngle") as AssetPropertyDouble);
                    }
                    if (assetPropertyDouble != null)
                    {
                        exportedMaterial.TextureRotationAngle  = assetPropertyDouble.Value;
                        exportedMaterial.TextureRotationAngle *= 0.017453292519943295;
                    }
                }
            }
            catch (Exception)
            {
            }
        }