Hello everyone. I need your help!
I need to program drape image onto a surface, but I'm not very happy with the result.
public static void СreateNewMaterial(string materialName = "new image", string textureName = @"C:\image\image.jpeg", double x, double y)
{
Autodesk.AutoCAD.ApplicationServices.Document doc = Application.DocumentManager.MdiActiveDocument;
Database m_db = doc.Database;
Editor ed = doc.Editor;
using (Transaction acTrans = doc.TransactionManager.StartTransaction())
{
DBDictionary matLib = (DBDictionary)acTrans.GetObject(doc.Database.MaterialDictionaryId, OpenMode.ForRead);
double scaleX = 1.00 / x;
double scaleY = 1.00 / y;
Matrix3d mx = new Matrix3d(new double[] { scaleX, 0, 0, 0,
0, scaleY, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 });
Mapper mapper = new Mapper(Projection.Cylinder, Tiling.InheritTiling, Tiling.InheritTiling, AutoTransform.None, mx);
ImageFileTexture mttr = new ImageFileTexture();
mttr.SourceFileName = textureName;
MaterialMap map = new MaterialMap(Source.File, mttr, 1.0, mapper);
EntityColor eclr = new EntityColor(255, 255, 255);
MaterialColor mc = new MaterialColor(Method.Override, 1, eclr);
MaterialDiffuseComponent mdc = new MaterialDiffuseComponent(mc, map);
MaterialRefractionComponent mrfr = new MaterialRefractionComponent(2, map);
Material Mat = new Material();
string sMaterialName = "New Material";
Mat.Name = materialName;
Mat.Description = sMaterialName;
Mat.Diffuse = mdc;
Mat.Refraction = mrfr;
Mat.Reflectivity = 1;
Mat.Reflection = map;
Mat.Ambient = mc;
matLib.UpgradeOpen();
matLib.SetAt(sMaterialName, Mat);
acTrans.AddNewlyCreatedDBObject(Mat, true);
acTrans.Commit();
}
}
This material was applied to the surface surface.Material = "New Material";
Result:
If something is slightly corrected in "editing the material", then at the next viewing it comes out:
Already better, but there are triangles for which there is no image or where it should not be.
If I drape image manually (not through the program):
How can you get the same result?
Thanks in advance)
Solved! Go to Solution.
Solved by logerasimova5. Go to Solution.
I found what is the problem:
Mapper mapper = new Mapper(Projection.Planar, Tiling.InheritTiling, Tiling.InheritTiling, AutoTransform.None, mx);
@logerasimova5 Can you help me to make a C# program to protect dynamo script for Civil 3d
Can't find what you're looking for? Ask the community or share your knowledge.