Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drape image (c#)

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
logerasimova5
389 Views, 2 Replies

Drape image (c#)

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:
image01.png

If something is slightly corrected in "editing the material", then at the next viewing it comes out:

image02.png

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):

image03.png


How can you get the same result?
Thanks in advance)

Tags (1)
2 REPLIES 2
Message 2 of 3

I found what is the problem:

 Mapper mapper = new Mapper(Projection.Planar, Tiling.InheritTiling, Tiling.InheritTiling, AutoTransform.None, mx);
Message 3 of 3

@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.

Post to forums  

Rail Community


Autodesk Design & Make Report