Viewpoint Forums
Viewpoint Forums
JavaScript
Change texture using javscript|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Member |
Hi,
I have a material which has a texture. How can i change this texture with a javascript command ? Can i call an external jpeg file ??? David |
||
|
|
Member |
Hi David,
Yes, you can change a texture with js and have it pass an external image. Here's an example: in your mtx you have the MTSTimeElem loader: <MTSTimeElem Name="myTextureLoader" Type="MTSImageStream" Path="image1.jpg" Comp="0"> <Target Name="MTSTexture.myTexture"/> </MTSTimeElem> Then in your javascript you can change the texture like so:
function swapTextures(path)
{
vmp.SetProperty('MTSTimeElem.myTextureLoader', 'Path', path, 'mts_str');
vmp.SetProperty('MTSTimeElem.myTextureLoader', 'trgr', '1', 'mts_int');
}
where path is the variable containing the path to the external image (relative to the mtx). Also, note that you have to trigger the MTSTimeElem once you've loaded the new texture... so optimally you may want to have an interactor capture the MTSLoadDone event to trigger the texture loader. HTH, Daimen |
|||
|
|
Member |
Thanks for your reply !
I tried this but it doesn't work (certainly because i'm new with this I've made a sample at this link : http://perso.wanadoo.fr/aurore.calendreau/ and a .rar archive with my test files at : http://perso.wanadoo.fr/aurore.calendreau/test.rar Is it possible to tell me where i'm wrong ??? Thanks. David This message has been edited. Last edited by: dpais, |
|||
|
|
Member |
Hi David,
All you need to do is give your texture a name... the same name you target in your MTSTimeElem. Like so: <MTSInstance Name="Box01"> <Transform> <Scale/> <Rotate x="90" y="0" z="0"/> <Position x="-39.0863" y="0" z="-6.599"/> </Transform> <MTSGeometry Name="Box01_GEOM" MultiUV="0" BackFaceDir="-1"/> <MTSMaterial ID="0"> <MTSTextureMap Type="Diffuse" Name="Box01"/> </MTSMaterial> </MTSInstance> |
|||
|
|
Member |
I have a question. Can I use 'MTSImageStream' with png's? (when I try it, it does not work for me). Also, I want to stream in alpha and that does not seem to work. Funny thing is; streaming bump DOES work. Thanks Christopher |
|||
|
|
EnIgMaTiCScOrPioN Member |
Hi Chris !!
You cannot get PNGs in VET. To stream in Alpha, save the black and white texture map as a JPG and import in the following manner: <MTSTimeElem Name="myAlphaTextureLoader" Type="MTSImageStream" UseAsAlpha="1" Path="image1.jpg" > <Target Name="MTSTexture.myAlphaTexture"/> </MTSTimeElem> Hope this helps. Cheers, Anup |
|||
|
|
Member |
Ah nuts. What about Gif? Can we stream Gif? I ask because I'm also streaming in bumpmaps and I would love to use gif instead of jpg for that.
Ta Christopher |
|||
|
|
EnIgMaTiCScOrPioN Member |
Hi Chris !!
Only JPG and BMP formats can be loaded in VET. Cheers, Anup |
|||
|
|
Member |
OK, Thanks!
|
|||
|
|
Member |
ok, for some reason, I cannot get this to work. Can you see what I have wrong with this code? ... <MTSMaterial Name="rugMaterial_3995" ID="0" RenderMode="LightTexture" BumpStrength="-2.0" > <MTSTextureMap Type="Diffuse" Name="rug_Linkage3995" x="959" y="383" /> <MTSTextureMap Type="Bump" Name="rug_Linkage_Bump3995" x="959" y="383" /> <MTSTextureMap Type="Alpha" Name="myAlphaTexture" x="959" y="383" /> </MTSMaterial> <MTSTimeElem Type="MTSImageStream" Name="rug_loader3995" Path="renderedcanvases/3995_0.jpg"> <Target Name="MTSTexture.rug_Linkage3995" /> </MTSTimeElem> <MTSTimeElem Type="MTSImageStream" Name="rug_loader_Bump3995" Path="renderedcanvases/3995_0B.jpg"> <Target Name="MTSTexture.rug_Linkage_Bump3995" /> </MTSTimeElem> <MTSTimeElem Name="myAlphaTextureLoader" Type="MTSImageStream" UseAsAlpha="1" Path="renderedcanvases/alpha.jpg" > <Target Name="MTSTexture.myAlphaTexture"/> </MTSTimeElem> <MTSMaterial Name="rugMaterial1_3995" ID="1" RenderMode="Texture" > <MTSColor Type="Diffuse" b="255" g="255" r="255" /> </MTSMaterial> ... Thanks! PVN test.zip (325 KB, 18 downloads) full source |
|||
|
|
Member |
BTW, I also tried the following:
<MTSTextureMap Type="Diffuse" Name="myAlphaTexture" HasAlpha="1" x="959" y="383" /> no luck. Just a dark poly. Ta |
|||
|
|
Member |
Hi Chris,
It's working for me. Is this what it's supposed to look like? |
|||
|
| Powered by Eve Community |
| Please Wait. Your request is being processed... |
|
Viewpoint Forums
Viewpoint Forums
JavaScript
Change texture using javscript
