.NET

Reply
Contributor
User48
Posts: 15
Registered: ‎12-21-2010
Message 1 of 2 (118 Views)

Material from image file with parameters (including rotation)

118 Views, 1 Replies
09-05-2013 10:33 AM

Has anyone an example code of creating material from image file including the setting of parameters like seen in the materials dialog.  I need to set the rotation angle along with the U/V tile and U/V offsets at the same time.  This example shows part but does not do rotation.

http://adndevblog.typepad.com/autocad/2012/05/setting-u-and-v-tile-scale-of-a-newly-created-material...

 

I am trying to make the image fit a rotated face that is usually of the same proportions as the image.

ADN Support Specialist
philippe.leefsma
Posts: 646
Registered: ‎06-02-2009
Message 2 of 2 (71 Views)

Re: Material from image file with parameters (including rotation)

09-10-2013 02:30 PM in reply to: User48

Hi

 

Did you try setting the mapper matrix to a rotation? In the example it is just set to a scale.

 

Alternatively you could try retrieving an existing texture info that is already rotated and check how its matrix looks like. Here is some incomplete code that illustrates how to access the texture properties:

 

[CommandMethod("MaterialInfo")]
public void MaterialInfo()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    PromptEntityOptions peo = new PromptEntityOptions(
        "\nSelect a 3D solid: ");

    peo.SetRejectMessage("\nInvalid selection...");
    peo.AddAllowedClass(typeof(Solid3d), true);

    PromptEntityResult per = ed.GetEntity(peo);

    if (per.Status != PromptStatus.OK)
        return;

    using (Transaction Tx = db.TransactionManager.StartTransaction())
    {
        Solid3d solid = Tx.GetObject(per.ObjectId, OpenMode.ForRead)
            as Solid3d;

        Material material = Tx.GetObject(solid.MaterialId, OpenMode.ForRead)
            as Material;

        MaterialMap map = material.Bump;

        if(map.Texture is ImageFileTexture)
        {
            ImageFileTexture imgTex = map.Texture as ImageFileTexture;

            ed.WriteMessage("\nSource file: " + imgTex.SourceFileName);
        }

        Mapper mapper = map.Mapper;

        //mapper.Transform is matrix3d...
    }
}

 

Regards,

Philippe.

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.