Prod.: Engine, ver.: 6017, ID: 60000932, Wish : Apply images over polyfaces

Wish : Apply images over polyfaces

Article60000932
TypeWish
ProductEngine
Version6017
Date Added8/6/2009
FixedYes [4/19/2010]
Submitted bywayne romer
Keywords

Subject

Apply images over polyfaces

Summary

Apply images over polyfaces

Solution



In 6018 a new property MappedImages was added in vdPolyface and vdGroundSourface objects.
 MappedImages is a collection of MappedImage object .You can apply one or more images
 MappedImage object contains the following properties:
 MaterialImage which is a vdImageDef previously added in vdDocument.Images
 SourceRectangle which is define the sub-rectangle that is used to map the image over a surface.
     if it is dRectangle.Empty (which is the default value) the whole image is mapped over the surface.
 MaterialMatrix which is define the Matrix used for transformations from source rectangle to destination in World Coordinate System.
 The MappedImages for a surface are drawn only when RenderMode is "RENDER"




Example of mapping 2 images in a vdPolyface object in C# :



 vdPolyface pf = new vdPolyface();
 pf.SetUnRegisterDocument(doc);
 pf.setDocumentDefaults();
 gPoints pts = new gPoints();
 pts.Add(new gPoint(0, 0, 0));
 pts.Add(new gPoint(1, 0, 0));
 pts.Add(new gPoint(2, 0, 0));
 pts.Add(new gPoint(0, 1, 0));
 pts.Add(new gPoint(1, 1, 1));
 pts.Add(new gPoint(2, 1, 0));
 pts.Add(new gPoint(0, 2, 0));
 pts.Add(new gPoint(1, 2, 0));
 pts.Add(new gPoint(2, 2, 0));
 pf.VertexList = pts;
 Int32Array fl = new Int32Array();
 //First face
 fl.AddItem(1);fl.AddItem(2);fl.AddItem(5);fl.AddItem(4);fl.AddItem(-1);
 //Second face
 fl.AddItem(2);fl.AddItem(3);fl.AddItem(6);fl.AddItem(5);fl.AddItem(-1);
 //Third face
 fl.AddItem(4);fl.AddItem(5);fl.AddItem(8);fl.AddItem(7);fl.AddItem(-1);
 //Forth face
 fl.AddItem(5);fl.AddItem(6);fl.AddItem(9);fl.AddItem(8);fl.AddItem(-1);
 pf.FaceList = fl;




 vdImageDef img1 = doc.Images.Add(@"c:\images\image1.jpg");
 vdImageDef img2 = doc.Images.Add(@"c:\images\image2.jpg");
 //mapp  a sub-rectangle of image1,  (100, 50, 200, 150) pixels , so that the lower-left point of the image is transormed into 0.3,0.3 world position and the image mapped width is become 1.7 drawing units
 pf.MappedImages.AddItem(new vdMappedImage(img1, new gPoint(0.3, 0.3, 0), Globals.DegreesToRadians(0.0d), 1.7d, new VectorDraw.Render.vdRectangle(100, 50, 200, 150)));
 //mapp  the whole rectangle of  image2 so that the lower-left point of the image is transormed into 0.0,1.3 world position and the image mapped width is become 2.0 drawing units
 pf.MappedImages.AddItem(new vdMappedImage(img2, new gPoint(0, 1.3, 0), Globals.DegreesToRadians(0.0d), 2.0d, VectorDraw.Render.vdRectangle.Empty));
 doc.ActiveLayOut.Entities.AddItem(pf);
 doc.CommandAction.View3D("RENDER");



 



Example of mapping 2 images in a vdGroundSouface object in C#



 vdGroundSurface sf = new vdGroundSurface();
 sf.SetUnRegisterDocument(doc);
 sf.setDocumentDefaults();
 vdImageDef img1 = doc.Images.Add(@"c:\images\image1.jpg");
 vdImageDef img2 = doc.Images.Add(@"c:\images\image2.jpg");
 //mapp  a sub-rectangle of image1,  (100, 50, 200, 150) pixels , so that the lower-left point of the image is transormed into 0.3,0.3 world position and the image mapped width is become 1.7 drawing units
 sf.MappedImages.AddItem(new vdMappedImage(img1, new gPoint(0.3, 0.3, 0), Globals.DegreesToRadians(0.0d), 1.7d, new VectorDraw.Render.vdRectangle(100, 50, 200, 150)));
 //mapp  the whole rectangle of  image2 so that the lower-left point of the image is transormed into 0.0,1.3 world position and the image mapped width is become 2.0 drawing units
 sf.MappedImages.AddItem(new vdMappedImage(img2, new gPoint(0, 1.3, 0), Globals.DegreesToRadians(0.0d), 2.0d, VectorDraw.Render.vdRectangle.Empty));
 gPoints pts = new gPoints();
 pts.Add(new gPoint(0, 0, 0));
 pts.Add(new gPoint(1, 0, 0));
 pts.Add(new gPoint(2, 0, 0));
 pts.Add(new gPoint(0, 1, 0));
 pts.Add(new gPoint(1, 1, 1));
 pts.Add(new gPoint(2, 1, 0));
 pts.Add(new gPoint(0, 2, 0));
 pts.Add(new gPoint(1, 2, 0));
 pts.Add(new gPoint(2, 2, 0));
 sf.Points = pts;
 doc.ActiveLayOut.Entities.AddItem(sf);
 doc.CommandAction.View3D("RENDER");


 


Example for C++ unmanage with VectorDraw Wrapper control

#import "System.Drawing.tlb"

#import "mscorlib.tlb" rename("ReportEvent","_ReportEvent") rename("value","_value")

#import "VDrawPro5.tlb"

#import "VectorDraw.Geometry.tlb"

#import "VectorDraw.Render.tlb"

#import "VectorDraw.Serialize.tlb"

#import "VectorDraw.Professional.tlb" rename("entities","Entities") rename("GetEnvironmentVariable" , "_GetEnvironmentVariable")

#import "vdDXF.tlb"

............................................

 


//Add a new imagedefinition
CvdImageDef img = mvdraw.GetActiveDocument().GetImages().Add(_T("C:\\Users\\Administrator\\Desktop\\Temp\\test2\\alcoholr.jpg"));
//get the interface of manage image object.
VectorDraw_Professional::IvdImageDefPtr imgptr = img.GetWrapperObject();


//create a point variant array
COlePointArray pts;
pts.Add(COlePoint(0,0,0));
pts.Add(COlePoint(1,0,0));
pts.Add(COlePoint(2,0,0));
pts.Add(COlePoint(0,1,0));
pts.Add(COlePoint(1,1,1));
pts.Add(COlePoint(2,1,0));
pts.Add(COlePoint(0,2,0));
pts.Add(COlePoint(1,2,0));
pts.Add(COlePoint(2,2,0));
//create a variant integer array with facelist items
COleIntArray fl;


fl.AddValue(1); fl.AddValue(2); fl.AddValue(5); fl.AddValue(4); fl.AddValue(0);
fl.AddValue(2); fl.AddValue(3); fl.AddValue(6); fl.AddValue(5); fl.AddValue(0);
fl.AddValue(4); fl.AddValue(5); fl.AddValue(8); fl.AddValue(7); fl.AddValue(0);
fl.AddValue(5); fl.AddValue(6); fl.AddValue(9); fl.AddValue(8); fl.AddValue(0);


//create a new polyface object
CvdPolyface pf = mvdraw.GetActiveDocument().GetEntities().AddPolyFace(pts,fl);
//get the manage interface for the polyface in order to call mappedImages property
VectorDraw_Professional::IvdPolyfacePtr pfptr = pf.GetWrapperObject();


//create a new mappedimage object
VectorDraw_Professional::IvdMappedImagePtr mappedImage;
mappedImage.CreateInstance(__uuidof(VectorDraw_Professional::vdMappedImage));


//set the imagedefinition property for the mapped image
mappedImage->PutRefMaterialImage(imgptr);


//create and select the mappedimage matrix that will transorm the image into real world coordinate system.
VectorDraw_Geometry::IgPointPtr origin(__uuidof(VectorDraw_Geometry::gPoint));
origin->SetValue(0.3,0.3,0.0);
VectorDraw_Geometry::IMatrixPtr matt(__uuidof(VectorDraw_Geometry::Matrix));
double scale = 1.5;
double aspect = (double)img.GetWidth() / (double)img.GetHeight();
matt->ScaleMatrix(scale, scale / aspect, 1.0);
matt->TranslateMatrix(origin);


mappedImage->PutRefMaterialMatrix(matt);



//add the mappedimage into the mappedimages collection of the polyface object.(multi items cam be added)
pfptr->GetMappedImages()->AddItem(mappedImage);


//select the render mode which is the only draw mode that mappedimages are displayed.
mvdraw.GetCommandAction().View3D(COleVariant(_T("RENDER")));



In Visual Basic 6.0 you can do it this way :
Private Sub Form_Load()
' You need to add the VectorDraw.Professiona.tlb, VectorDraw.Geometry.tlb and VectorDraw.Render.tlb in the project's references
    VDraw1.ActiveDocument.New: VDraw1.DisplayFrames = ShowAll
    VDraw1.StatusBar = True: VDraw1.StatusBarMenu = True: VDraw1.StatusBarPaper = True
    VDraw1.EnableAutoGripOn = True: VDraw1.FreezeEvents False: VDraw1.FreezeEntityEvents False
Dim pface As VDrawI5.vdPolyface
Dim facelist As Variant: facelist = Array(1, 2, 5, 4, 0, 2, 3, 6, 5, 0, 4, 5, 8, 7, 0, 5, 6, 9, 8, 0)
Dim imgdf1 As VDrawI5.vdImageDef: Dim pface_wrap As VectorDraw_Professional.vdPolyface
Dim mat As VDrawI5.vdmatrix: Dim vdrect As VectorDraw_Render.vdRectangle
Dim vdMappedImage As VectorDraw_Professional.vdMappedImage

    Set pface = VDraw1.ActiveDocument.entities.AddPolyFace(Array(Array(1, 3, 0.2), _
            Array(2, 3, 0.4), Array(3, 3, 0.2), Array(1, 2, 0.3), _
            Array(2, 2, 0#), Array(3, 2, 0.3), Array(1, 1, 0.1), _
            Array(2, 1, 0.5), Array(3, 1, 0.1)), facelist)
    
    Set imgdf1 = VDraw1.ActiveDocument.images.Add(App.Path + "\stonwall.jpg")
    Set pface_wrap = pface.WrapperObject
    
    Set mat = VDraw1.CreateInstance(OBJ_MATRIX)
    mat.Init
    mat.Translate 0.3, 0.3, 0
    mat.ScaleMatrix 3.7, 2.7, 1.7
    
    Set vdrect = New VectorDraw_Render.vdRectangle
    vdrect.Height = 150: vdrect.Width = 250: vdrect.Left = 10: vdrect.Top = 10
    
    Set vdMappedImage = New VectorDraw_Professional.vdMappedImage
    Set vdMappedImage.MaterialImage = imgdf1.WrapperObject
    Set vdMappedImage.MaterialMatrix = mat.WrapperObject
    Set vdMappedImage.SourceRectangle = vdrect
    Call pface_wrap.MappedImages.AddItem(vdMappedImage)
    
    VDraw1.CommandAction.View3D "RENDER"
End Sub