Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  JavaScript    Change texture using javscript

Moderators: e_phoenix13
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Member
Posted
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
 
Posts: 10 | Registered: January 24, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Picture of duncan
Posted Hide Post
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
 
Posts: 381 | Registered: January 24, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Thanks for your reply ! Smile

I tried this but it doesn't work (certainly because i'm new with this Smile ).

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,
 
Posts: 10 | Registered: January 24, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Picture of duncan
Posted Hide Post
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>
 
Posts: 381 | Registered: January 24, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
quote:
<MTSTimeElem Name="myTextureLoader" Type="c" Path="image1.jpg" Comp="0"> <Target Name="MTSTexture.myTexture"/> </MTSTimeElem>


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
 
Posts: 12 | Registered: November 10, 2005Reply With QuoteEdit or Delete MessageReport This Post
EnIgMaTiCScOrPioN
Member
Picture of e_phoenix13
Posted Hide Post
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
 
Posts: 557 | Location: India | Registered: February 12, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
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
 
Posts: 12 | Registered: November 10, 2005Reply With QuoteEdit or Delete MessageReport This Post
EnIgMaTiCScOrPioN
Member
Picture of e_phoenix13
Posted Hide Post
Hi Chris !!

Only JPG and BMP formats can be loaded in VET.


Cheers,

Anup
 
Posts: 557 | Location: India | Registered: February 12, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
OK, Thanks! Smile
 
Posts: 12 | Registered: November 10, 2005Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
quote:
July 27,


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

Zip/GZ archivetest.zip (325 KB, 18 downloads) full source
 
Posts: 12 | Registered: November 10, 2005Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
BTW, I also tried the following:

<MTSTextureMap Type="Diffuse" Name="myAlphaTexture" HasAlpha="1" x="959" y="383" />

no luck. Just a dark poly.

Ta
 
Posts: 12 | Registered: November 10, 2005Reply With QuoteEdit or Delete MessageReport This Post
Member
Picture of Admin
Posted Hide Post
Hi Chris,

It's working for me. Is this what it's supposed to look like?

 
Posts: 1188 | Registered: January 08, 2003Reply With QuoteEdit or Delete MessageReport This Post
  Powered by Eve Community  
 

Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  JavaScript    Change texture using javscript