'-------------------------------------------------------------
'-------------------------------------------------------------
'NAME:ImagePlane
'AUTHOR:Jonathan Katoe
'CONTACT:jkatoe@optonline.net
'VERSION:1.0
'DESCRIPTION:Creates an image plane.
'-------------------------------------------------------------
'-------------------------------------------------------------
sub Create()
dim fb
dim path

path = application.installationpath(siprojectpath)
path = path & "\Pictures"
set fb = xsiuitoolkit.filebrowser
fb.dialogtitle = "Select and image..."
fb.initialdirectory = path
fb.filter = "All files (*.*)|*.*||"
fb.showopen

if fb.filepathname <> "" then
	application.statusbar = fb.filepathname
else
	application.statusbar = "Cancelled Operation."
	exit sub
end if

logmessage fb.filepathname

set image = addimagesource(fb.filepathname)  
set clip = addimageclip(image)  
set iplane = activesceneroot.addgeometry("grid", "meshsurface")
iplane.subdivu = 1  
iplane.subdivv = 1  
set oMaterial = iplane.addmaterial("Constant")  
set oPhong = oMaterial.surface.source  

xval = getvalue("sources." & image.name & ".xres")
yval = getvalue("sources." & image.name & ".yres")

if xval < yval then
	val = xval/yval
	iplane.ulength = iplane.vlength.value * val	
else
	val = yval/xval
	iplane.vlength = iplane.ulength.value * val	
end if

CopyPaste , "Shaders\Texture\Image.Preset", "transientobjectcontainer"
SIConnectShaderToCnxPoint clip, "transientobjectcontainer.Image.tex"
SIConnectShaderToCnxPoint "transientobjectcontainer.image", iplane & ".material.constant.color"
CreateProjection iplane, sitxtplanarxz, sitxtdefaultspherical, "texture_support", "texture_projection"
SetInstanceDataValue , iplane & ".material.constant.image.tspace_id", "texture_projection"

SetValue iplane & ".material.envmode", 8449
iplane.rotx = 90

end sub

Create()


	
	
	

