Brush applied as Material to GeometryModel3D: Brush gets flipp

Brush applied as Material to GeometryModel3D: Brush gets flipp

Post by U3RlcGhlbi » Wed, 04 Apr 2007 00:48:03


Awesome, thanks. I figured it had something to do with that, but not really
knowing much about the science of using computers to create 3D objects, I
didn't know how to control it.

I tried checking out the "TextureCoordinates" class
( http://www.yqcomputer.com/ )
but it didn't really explain what all those numbers are and what they do.

If you can spare the time, can you have a look at this 3D code and instruct
me on what the proper texture coordinates should be and why? (I took this
XAML code for creating generic 3D plane from another tutorial -
http://www.yqcomputer.com/ )

I just want whatever I apply to the front material or back material to be
what you would expect ie. if I create a png of an arrow pointing to the
right, I want that arrow to be pointing to the right if I apply it to either
the front or back of the plane.



*******************

<GeometryModel3D x:Name="obj3D_window">
<!-- The geometry specifes the shape of the 3D plane. In this sample, a
flat sheet is created. -->
<GeometryModel3D.Geometry>
<MeshGeometry3D
TriangleIndices="0,1,2 3,4,5 "
Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1"
TextureCoordinates="0,0 1,0 1,1 1,1 0,1 0,0"
Positions="-0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5
-0.5,-0.5,0.5" />
</GeometryModel3D.Geometry>
<GeometryModel3D.Transform>
<Transform3DGroup>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="-0.5"/>
<ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
<RotateTransform3D d:EulerAngles="-179,46,6">
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="173.49238451605089"
Axis="0.956907608946917,0.0172221285274748,-0.289881400280319"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0.5"/>
<TranslateTransform3D OffsetX="-0.037" OffsetY="-0.148" OffsetZ="0.131"/>
</Transform3DGroup>
</GeometryModel3D.Transform>
<GeometryModel3D.BackMaterial>
<DiffuseMaterial Brush="{DynamicResource vBrush_kidVid}"/>
</GeometryModel3D.BackMaterial>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="{DynamicResource iBrush_dormantParent}"/>
</GeometryModel3D.Material>
</GeometryModel3D>
*******************


(Note, I think there's a transform in there that's also flipping the whole
3D object around so that it's Back Material is facing forward - I did that
'cuz that was the only Material Side that was not flipping the image)


Thanks for your time!

Stephen Scholtz
 
 
 

Brush applied as Material to GeometryModel3D: Brush gets flipp

Post by U3RlcGhlbi » Wed, 04 Apr 2007 03:20:01

PS - I tried playing with the coordinate values myself, manually altering
them but I couldn't get the image to flip, only rotate, or mirror itself
(rotated one of the textures on my triangle but not the other), or disappear
completely. :P

 
 
 

Brush applied as Material to GeometryModel3D: Brush gets flipp

Post by Gary Linsc » Wed, 04 Apr 2007 05:11:19

n your example, flipping the V co-ordinate will fix your image being
flipped for the front material. However, when viewing the BackMaterial you
have rotated the object around, so you would expect the material to be
flipped in the X direction. To get around that you can apply a
ScaleTransform with ScaleY=-1 to the Brushes Transform property.
Unfortunately, Blend doesn't support editing the Brush transform, so you
will have to do this in XAML.

Texture co-ordinates are a very literal translation of the underlying 3D
API, which is DirectX. There are two co-ordinates, U and V, which generally
lie in the range [0,1], with 0 being the minimum, and 1 being the maximum.
U represents the X co-ordinate of the texture and V represents the Y
co-ordinate. So in the example below, I have an UpDirection of (0,1,0)
which means that +1 in the Y direction moves up on the screen. That means
the top-left corner of the object will be at (-0.5, 0.5, 0.5), so it gets
the texture co-ordinate of (0,0). The bottom-right will be (0.5, -0.5,
0.5), so it gets (1,1). Does that help?

Example XAML:
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera x:Name="Camera" FieldOfView="45" FarPlaneDistance="100"
LookDirection="0,0,-1" NearPlaneDistance="0.1" Position="0,0,5"
UpDirection="0,1,0"/>
</Viewport3D.Camera>
<ModelVisual3D x:Name="ModelContainer">
<ModelVisual3D.Content>
<GeometryModel3D x:Name="obj3D_window">
<GeometryModel3D.Geometry>
<MeshGeometry3D
TriangleIndices="0,1,2 3,4,5 "
Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1"
TextureCoordinates="0,1 1,1 1,0 1,0 0,0 0,1"
Positions="-0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5
0.5,0.5,0.5 -0.5,0.5,0.5
-0.5,-0.5,0.5" />
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="{DynamicResource ImageBrush}"/>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="AmbientContainer">
<ModelVisual3D.Content>
<AmbientLight x:Name="Ambient" Color="#FF808080"/>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="DirectionalContainer">
<ModelVisual3D.Content>
<DirectionalLight x:Name="Directional" Color="#FF7F7F7F"
Direction="0,0,-1">
<DirectionalLight.Transform>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="3"/>
</DirectionalLight.Transform>
</DirectionalLight>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>

--

Gary Linscott [MSFT]
Content is provided "AS IS" with no warranties and confers no rights.

"Stephen Scholtz" < XXXX@XXXXX.COM > wrote in
message news: XXXX@XXXXX.COM ...


 
 
 

Brush applied as Material to GeometryModel3D: Brush gets flipp

Post by U3RlcGhlbi » Wed, 04 Apr 2007 06:34:00

gt; In your example, flipping the V co-ordinate will fix your image being

Or, I could just turn my object "right-side up" so to speak. :P I didn't
even realize it was "upside down". If I'm in Blend, modify a 3D Object's
position, the green Y arrow should be facing "up", right? The red X should
be facing "right", and the blue Z facing "out", right? By default anyways,
if my object was positioned "straight on" and the camera was positioned
straight on.

The texture seems to be working correctly now, I believe. The "front" of
the object (Material) shows the correct orientation - if I put a texture on
there that originally had an arrow facing right, it faces to the right. The
"back" of the object (BackMaterial) now shows a mirror image. That is, if I
were to apply the same texture, and then turn the object around, the arrow
would appear to face left instead of right.

This is actually what's supposed to happen in 3D modeling, right? The back
texture of an object should reverse itself? From my cursory exposure to 3D
modeling concepts, this seems to be the expected behaviour.


Aaaaaaahhhh...this is what "UpDirection" means? Quite literally, the
direction that "up" is inside your 3D space?


Yup, I believe I get it. Of course, texture coordinates become more complex
when you start to introduce more triangles/polys into the model, right?

I have a much better understanding of the whole 3D thing though I guess I
still need to learn about normals, triangle indicies, euler angles, etc. I
think I have enough to get done what I need to get done now.

Thanks so much for taking the time to break it down for me!

Cheers,
Stephen Scholtz

PS...


Does that make it a "XAMple?" ;-P







"Gary Linscott [MSFT]" wrote:

 
 
 

Brush applied as Material to GeometryModel3D: Brush gets flipp

Post by UmFjaGV » Wed, 09 Jan 2008 05:05:01

groan! XAMple eh? Maybe XAMPL!