Xojo Conferences
XDCMay2019MiamiUSA

Sharing textures (Real Studio games Mailinglist archive)

Back to the thread list
Previous thread: GUI Was: Re: Switching to RealBasic from Torque
Next thread: keytest


[ANN] Preview of RBD 2.4   -   Marc Zeedar
  Sharing textures   -   Daniel Lurie
   Re: Sharing textures   -   Jeff Quan
   Re: Sharing textures   -   Frank Condello
   Re: Sharing textures   -   Daniel Lurie
   Re: Sharing textures   -   Joseph J. Strout
    Re: Sharing textures   -   dl1021 optonline.net

Sharing textures
Date: 25.06.05 18:36 (Sat, 25 Jun 2005 13:36:48 -0400)
From: Daniel Lurie
Is there a way to make multiple object 3Ds share the same texture?

=kDgDoDwDsDDaniel R. Lurie
=wDsDcDsDgDhttp://www.vikingdan.com

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Sharing textures
Date: 25.06.05 19:03 (Sat, 25 Jun 2005 11:03:31 -0700)
From: Jeff Quan

On Jun 25, 2005, at 10:36 AM, Daniel Lurie wrote:
> Is there a way to make multiple object 3Ds share the same texture?

At the moment, not without declares. You can use Frank's Quesa Wrappers.

Here's a snippet of code that should work using Quesa Wrappers. This
assumes that the obj has a pre-existing texture to be replaced and will
ONLY affect the first trimesh's texture. This means, in Meshwork terms,
if you've applied multiple materials only the first one will be
affected. You'll need to do a bit more legwork to get to the other
textures.

Sub UpdateObjTexture(obj As Object3D, texture As Picture)
Dim tmsh as Trimesh3D
Dim mat as AttributeSet3D
Dim tex as TextureShader3D

// Get existing texture on obj.
// NOTE: This only affects first trimesh only!
tmsh = obj.GetFirstTrimeshInShape(i)
mat = tmsh.GetMaterial
tex = mat.GetTextureShader

// Replace texture
tex.SetTexture texture, tex.kPixelTypeRGB32

=Jeff Quan
<email address removed>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Sharing textures
Date: 25.06.05 21:05 (Sat, 25 Jun 2005 16:05:14 -0400)
From: Frank Condello
On 25-Jun-05, at 2:03 PM, Jeff Quan wrote:

> On Jun 25, 2005, at 10:36 AM, Daniel Lurie wrote:
>
>> Is there a way to make multiple object 3Ds share the same texture?
>
> At the moment, not without declares. You can use Frank's Quesa
> Wrappers.
>
> Here's a snippet of code that should work using Quesa Wrappers.
> This assumes that the obj has a pre-existing texture to be replaced
> and will ONLY affect the first trimesh's texture. This means, in
> Meshwork terms, if you've applied multiple materials only the first
> one will be affected. You'll need to do a bit more legwork to get
> to the other textures.
>
> Sub UpdateObjTexture(obj As Object3D, texture As Picture)
> Dim tmsh as Trimesh3D
> Dim mat as AttributeSet3D
> Dim tex as TextureShader3D
>
> // Get existing texture on obj.
> // NOTE: This only affects first trimesh only!
> tmsh = obj.GetFirstTrimeshInShape(i)
> mat = tmsh.GetMaterial
> tex = mat.GetTextureShader
>
> // Replace texture
> tex.SetTexture texture, tex.kPixelTypeRGB32

That will replace the texel data for each object, but it won't
actually share it! The TextureShader3D.SetTexture method actually
copies the picture you pass to it (too keep things simple I didn't
expose pixmap objects directly in the Quesa wrappers or else
something like that might've been possible).

To share a texture you need to assign the *same* TextureShader3D or
AttributeSet3D object to a your various meshes:

' Create a the textueshader you you wish to share,
' or better yet, use an AttributeSet3D, to share all material
attributes:

Dim mat as AttributeSet3D
Dim tex as TextureShader3D

tex = New TextureShader3D(somePicture, tex.kPixelTypeRGB32)
mat = New AttributeSet3D
mat.SetTextureShader tex
' Set other "mat" attributes if ya like (colors, transparency,
shininess etc.)

' Now apply "mat" to all the objects you want to share the same
material
UpdateObjTexture(obj, mat)
UpdateObjTexture(obj2, mat)
' ... etc ...

The update method would look something like this:

Sub UpdateObjTexture(obj As Object3D, mat As AttributeSet3D)

Dim tmsh as Trimesh3D
tmsh = obj.GetFirstTrimeshInShape(i)
if tmsh <> Nil then
tmsh.SetMaterial mat
end if

End Sub

Iterating through each Object3D shape and each trimesh in each shape
isn't much more work, but keep in mind that the 3DMF format can be a
little slippery at times. Textureshader objects can be placed inside
display groups to affect all the geometry in that group (same with
attribute sets). So although you're replacing the trimesh texture,
there may be a stray textureshader or attribute set in the 3DMF data
that no longer affects the final render, but still gets uploaded to
hardware wasting VRAM/RAM and CPU/GPU resources. This would occur if
you used the above method on an object shape created with
AddShapePicture for example. To be safe, you should first run through
all the shape's display groups and delete any stray texture shaders
and attribute sets. That's a bit more work, but the 3DMF format is
unpredictable and often requires special attention.

HTH!
Frank.
–––––––––––––––––––––––––––––––––
Open Source RB Goodies and Shareware
<http://developer.chaoticbox.com/>
<http://www.chaoticbox.com/>
–––––––––––––––––––––––––––––––––

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Sharing textures
Date: 26.06.05 00:11 (Sat, 25 Jun 2005 19:11:40 -0400)
From: Daniel Lurie
OK. This seems WAY over my head.

On Jun 25, 2005, at 4:05 PM, Frank Condello wrote:

> That will replace the texel data for each object, but it won't
> actually share it! The TextureShader3D.SetTexture method actually
> copies the picture you pass to it (too keep things simple I didn't
> expose pixmap objects directly in the Quesa wrappers or else something
> like that might've been possible).
>
> To share a texture you need to assign the *same* TextureShader3D or
> AttributeSet3D object to a your various meshes:
>
> ' Create a the textueshader you you wish to share,
> ' or better yet, use an AttributeSet3D, to share all material
> attributes:
>
> Dim mat as AttributeSet3D
> Dim tex as TextureShader3D
>
> tex = New TextureShader3D(somePicture, tex.kPixelTypeRGB32)
> mat = New AttributeSet3D
> mat.SetTextureShader tex
> ' Set other "mat" attributes if ya like (colors, transparency,
> shininess etc.)
>
> ' Now apply "mat" to all the objects you want to share the same
> material
> UpdateObjTexture(obj, mat)
> UpdateObjTexture(obj2, mat)
> ' ... etc ...
>
> The update method would look something like this:
>
> Sub UpdateObjTexture(obj As Object3D, mat As AttributeSet3D)
>
> Dim tmsh as Trimesh3D
> tmsh = obj.GetFirstTrimeshInShape(i)
> if tmsh <> Nil then
> tmsh.SetMaterial mat
> end if
>
> End Sub
>
> Iterating through each Object3D shape and each trimesh in each shape
> isn't much more work, but keep in mind that the 3DMF format can be a
> little slippery at times. Textureshader objects can be placed inside
> display groups to affect all the geometry in that group (same with
> attribute sets). So although you're replacing the trimesh texture,
> there may be a stray textureshader or attribute set in the 3DMF data
> that no longer affects the final render, but still gets uploaded to
> hardware wasting VRAM/RAM and CPU/GPU resources. This would occur if
> you used the above method on an object shape created with
> AddShapePicture for example. To be safe, you should first run through
> all the shape's display groups and delete any stray texture shaders
> and attribute sets. That's a bit more work, but the 3DMF format is
> unpredictable and often requires special attention.
>
> HTH!
> Frank.
=3D?D3D?D3DDaniel R. Lurie
=kDoDSD#DwDhttp://www.vikingdan.com

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Sharing textures
Date: 27.06.05 14:56 (Mon, 27 Jun 2005 08:56:26 -0500)
From: Joseph J. Strout
At 11:03 AM -0700 6/25/05, Jeff Quan wrote:
>On Jun 25, 2005, at 10:36 AM, Daniel Lurie wrote:
>>Is there a way to make multiple object 3Ds share the same texture?
>
>At the moment, not without declares. You can use Frank's Quesa Wrappers.

Jeff's answer is (of course) correct, in general. But note that for
the particular case where you want multiple Object3Ds to share the
same texture AND the same shape, then you can simply create the first
one, and then .Clone it as many times as you need.

Best,
- Joe

Re: Sharing textures
Date: 27.06.05 15:19 (Mon, 27 Jun 2005 10:19:33 -0400)
From: dl1021 optonline.net
Yeah. I know about clone. My thinking was that if I'm stuck using a separate model per frame for animation and I have to store redundant textures, too, its going to be a huge waste of memory.

Maybe I'll take another look at that morphmap class.

----- Original Message -----
From: "Joseph J. Strout" <<email address removed>>
Date: Monday, June 27, 2005 9:56 am
Subject: Re: Sharing textures

> At 11:03 AM -0700 6/25/05, Jeff Quan wrote:
> >On Jun 25, 2005, at 10:36 AM, Daniel Lurie wrote:
> >>Is there a way to make multiple object 3Ds share the same texture?
> >
> >At the moment, not without declares. You can use Frank's Quesa
> Wrappers.
> Jeff's answer is (of course) correct, in general. But note that
> for
> the particular case where you want multiple Object3Ds to share the
> same texture AND the same shape, then you can simply create the
> first
> one, and then .Clone it as many times as you need.
>
> Best,
> - Joe
>
> --
> Joe Strout REAL Software, Inc.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>