//纹理测试 static private void createMaterial(Database db, Transaction myT) { DBDictionary dic = (DBDictionary)myT.GetObject(db.MaterialDictionaryId, OpenMode.ForWrite, false); ImageFileTexture imfttr = new ImageFileTexture(); imfttr.SourceFileName = @"D:\Geological Project\Geological Source\dbFiles\aaaaa.jpg"; double uScale = 1.0; double vScale = 1.0; double uOffset = 0; double vOffset = 0; double[] p = new double[] { uScale, 0, 0, uScale *uOffset, 0, vScale, 0, vScale *vOffset, 0, 0, 1, 0, 0, 0, 0, 1 }; Matrix3d mx = new Matrix3d(p); Mapper mapper = new Mapper(Projection.Planar, Tiling.Crop, Tiling.Crop, AutoTransform.TransformObject, mx); MaterialMap map = new MaterialMap(Source.File, imfttr, 1, mapper); EntityColor eclr = new EntityColor(150, 150, 150); MaterialColor mc = new MaterialColor(Method.Override, 1, eclr); MaterialDiffuseComponent mdc = new MaterialDiffuseComponent(mc, map); MaterialSpecularComponent mck = new MaterialSpecularComponent(mc, map, 0.5); MaterialOpacityComponent moc = new MaterialOpacityComponent(1, map); MaterialRefractionComponent mrfr = new MaterialRefractionComponent(2, map); Material Mat = new Material(); Mat.Name = "My Material"; Mat.Description = "New Material"; Mat.Diffuse = mdc; Mat.Specular = mck; Mat.Refraction = mrfr; Mat.Reflectivity = 1; Mat.Reflection = map; Mat.Opacity = moc; Mat.Ambient = mc; Mat.Bump = map; Mat.SelfIllumination = 1; // MaterialDiffuseComponent diffuseColor = new MaterialDiffuseComponent(color, map); // material.Diffuse = diffuseColor; // material.Mode = Mode.Realistic; dic.SetAt(Mat.Name, Mat); }
public static void Test1() { Database database = HostApplicationServices.WorkingDatabase; Document activeDoc = Application.DocumentManager.MdiActiveDocument; Database db = activeDoc.Database; Editor ed = activeDoc.Editor; PromptEntityResult oRes = ed.GetEntity("Select Entity"); using (Transaction transaction = database.TransactionManager.StartTransaction()) { Face oFace = transaction.GetObject(oRes.ObjectId, OpenMode.ForRead) as Face; if (oFace != null) { string strMat = oFace.Material; ObjectId nMat = oFace.MaterialId; //Here change Entity MaterialId to ByBlock DBDictionary matLib = transaction.GetObject( db.MaterialDictionaryId, OpenMode.ForRead ) as DBDictionary; if (matLib.Contains("EngineTurned")) { ObjectId MaterialId = matLib.GetAt("EngineTurned"); Material mat = transaction.GetObject(MaterialId, OpenMode.ForRead) as Material; } Material material = transaction.GetObject(nMat, OpenMode.ForRead) as Material; MaterialMap map = material.Diffuse.Map; ImageFileTexture ift = map.Texture as ImageFileTexture; ift.SourceFileName = ""; } } }