WW has been learning for some time, but if you want to develop your own based on WW Plug-ins, you will inevitably encounter the DirectX rendering problem in Rendableobject. All of the WW three-dimensional plug-ins that need rendering are rendered by inheriting rendableobject and implementing their own initialize (), Update (), Render () methods. To write your own render () method is not a simple matter, you must learn DirectX programming, otherwise, you can not even understand the example of the underlying render () method is difficult to talk about how to develop their own plug-ins.
In order to break through DirectX programming for me to learn the WW plug-in block, I "fast-food" raid learning DirectX, the basic process and the rationale has a certain understanding. This afternoon I also studied the Rendableobject--imagelayer in the BMNG plug-in as an example. Now share with you.
Note: Please be sure to learn first
Direct3D Study (data collection), otherwise look at the following content is tantamount to wasting your precious time.
The Image layer The Initialize () method of the overload implementation.
Initialize Method code
///<summary>
///Layer Initialization code
///</summary>
public override void Initialize (Drawargs drawargs)
{
Try
{
//Get Draw device Object
this.device = Drawargs.device;
if (_imagepath = = null && _imageurl!= null && _imageurl.tolower (). StartsWith ("http://"))
{
///According to the URL address, build the same level of folder path locally. Here is a knowledge point Getfilepathfromurl () method, oneself localization study
_imagepath = Getfilepathfromurl (_imageurl);
}
FileInfo imagefileinfo = null;
if (_imagepath!= null)
imagefileinfo = new FileInfo (_imagepath);
if (downloadthread!= null && downloadthread.isalive)
return;
if (_imagepath!= null &&
cacheexpiration!= timespan.maxvalue &&
cacheexpiration.totalmilliseconds > 0 &&
_imageurl.tolower (). StartsWith ("http://") &&
imagefileinfo!= null &&
imagefileinfo.exists &&
Imagefileinfo.lastwritetime < system.datetime.now-cacheexpiration)
{
//attempt to redownload it
//enable new thread, download image image. I will later analyze the Downloadimage () method, which is one of the key
downloadthread = new Thread (new ThreadStart (downloadimage));
downloadthread.name = "Imagelayer.downloadimage";
Downloadthread.isbackground = true;
Downloadthread.start ();
return;
}
if (m_texturestream!= null)
{
//From file stream, update texture (texture), focus on
updatetexture (M_texturestream, M_transparentcolor);
verticalexaggeration = World.Settings.VerticalExaggeration;
//Create mesh, focus on analysis later
Createmesh ();
isinitialized = true;
return;
}
else if (imagefileinfo!= null && imagefileinfo.exists)
{
//update texture from file path
updatetexture (_imagepath);
verticalexaggeration = World.Settings.VerticalExaggeration;
//Create mesh mesh, in order to get the vertex collection.
Createmesh ();
isinitialized = true;
Return
}
if (_imageurl!= null && _imageurl.tolower (). StartsWith ("http://"))
{
//download it ...
downloadthread = new Thread (new ThreadStart (downloadimage));
downloadthread.name = "Imagelayer.downloadimage";
Downloadthread.isbackground = true;
Downloadthread.start ();
return;
}
//No image available
Dispose ();
ISON = false;
return;
}
Catch
{
}
}