4 Replies Latest reply on May 30, 2006 4:04 PM by Newsgroup_User

# 2d to 3d

Hi
I have a Director MX2004 movie which allows users to create a floor plan and
add furniture shapes in 2d, then display a 3d world shwoing the furniture in
the "room".
In the 3d world, I've created a plane and added a texture which is the 2d
floorplan sprite as drawn by the user. Could someone advise how best to
scale and position the floorplan and the furniture objects in the 3d world
in the same relative positions as the user has put them in 2d?

• ###### 1. Re: 2d to 3d
Charlie Allgrove wrote:

> Hi
> I have a Director MX2004 movie which allows users to create a floor plan and
> add furniture shapes in 2d, then display a 3d world shwoing the furniture in
> the "room".
> In the 3d world, I've created a plane and added a texture which is the 2d
> floorplan sprite as drawn by the user. Could someone advise how best to
> scale and position the floorplan and the furniture objects in the 3d world
> in the same relative positions as the user has put them in 2d?
>
>

Hi. Two quick ideas comes to mind. Use spriteSpaceToWorldSpace()
function to convert 2D coordinates into 3D or work with percentages.
Suppose that your 2D floorplan sprite is 200x200 pixels, then 100 pixels
= 0,5, 200px = 1 and so on...

Now suppose that your 3D floorplan is made of 1500x1500 3d units. Then
when the user clicks on the middle of the 2D sprite, that will be
traduced as 0.5x0.5 of the 2D sprite, now you multiply that number for
the 3D units (1500*0.5) and you get 750x750.

You�ll probably have to apply offsets and make tweaks but the main idea
is that you convert the 2D value to 0..1 by doing for example
clickedPointX / float(spriteWidth) and then you multiply it by the with
of the 3D floorplan.

Hope that helps,
--
Agust�n Mar�a Rodr�guez

www.onwine.com.ar > Macromedia Director demos & code
• ###### 2. Re: 2d to 3d
Thanks for that...I'll have a play and see how I get on!

• ###### 3. Re: 2d to 3d
Hi

I think I'm getting somewhere...but I'm new(ish) to Director and I'm not
entirely certain about 3d units vs 2d units...

I'm creating a plane in the 3d world and setting the width and length of the
modelResource to a maximum of 320x240px with a scale of 1.
Are these the 3dunits?
I'm then taking the 2d positions of the furniture elements and converting
them to the same point in the 3d world according to a calculated scale
factor, but the positions do not appear to be correct...

Charlie

"Agust�n Mar�a Rodr�guez" <agustin@onwine.com.ar> wrote in message
news:e5hh5j\$bfh\$1@forums.macromedia.com...
> Charlie Allgrove wrote:
>
>> Hi
>> I have a Director MX2004 movie which allows users to create a floor plan
>> and add furniture shapes in 2d, then display a 3d world shwoing the
>> furniture in the "room".
>> In the 3d world, I've created a plane and added a texture which is the 2d
>> floorplan sprite as drawn by the user. Could someone advise how best to
>> scale and position the floorplan and the furniture objects in the 3d
>> world in the same relative positions as the user has put them in 2d?
>
> Hi. Two quick ideas comes to mind. Use spriteSpaceToWorldSpace() function
> to convert 2D coordinates into 3D or work with percentages. Suppose that
> your 2D floorplan sprite is 200x200 pixels, then 100 pixels = 0,5, 200px =
> 1 and so on...
>
> Now suppose that your 3D floorplan is made of 1500x1500 3d units. Then
> when the user clicks on the middle of the 2D sprite, that will be traduced
> as 0.5x0.5 of the 2D sprite, now you multiply that number for the 3D units
> (1500*0.5) and you get 750x750.
>
> You�ll probably have to apply offsets and make tweaks but the main idea is
> that you convert the 2D value to 0..1 by doing for example clickedPointX /
> float(spriteWidth) and then you multiply it by the with of the 3D
> floorplan.
>
> Hope that helps,
> --
> Agust�n Mar�a Rodr�guez
>
> www.onwine.com.ar > Macromedia Director demos & code

• ###### 4. Re: 2d to 3d
Charlie Allgrove wrote:
> Hi
>
> I think I'm getting somewhere...but I'm new(ish) to Director and I'm not
> entirely certain about 3d units vs 2d units...
>
> I'm creating a plane in the 3d world and setting the width and length of the
> modelResource to a maximum of 320x240px with a scale of 1.
> Are these the 3dunits?
> I'm then taking the 2d positions of the furniture elements and converting
> them to the same point in the 3d world according to a calculated scale
> factor, but the positions do not appear to be correct...

( http://www.3dpi-director.com/). Use it for picking a model and change
its position. Every time you press the increase/decrease button for the
position value, you�re moving the model one 3D unit.

It doesn�t have anything to do with the 3D sprite size. To know the
boundaries of your 3D floorplan, move any model to the top left of the
floorplan and watch its position in the 3DPI xtra, then move it to the
bottom right position of the floorplan and check it�s position. You�ll
get values like this:

dummy model�s position when placed top left: vector(25, 80, 15)
dummy model�s position when placed bottom right: vector(75, 180, 15)

Suppousing you got those values, now you know that the floorplan�s
width is 50 units (75 - 25) and its height is 100 (180 - 80).

Now suppouse that you click on the 2D floorplan and you get 0.25 on X
axis and 0.5 on the Y axis. With those values you can now find the 3D
equivalent position:

x_3D_pos = topLeft3DVector.x + floorPlanWidth * 2D_XclickedProportion
x_3D_pos = 25 + 50 * 0.25
x_3D_pos = 25 + 12.5
x_3D_pos = 37.5

and y_3D_pos would be 130, that is: 80 of offset + (100 of width * 0.5
of 2Dfloorplan proportion).

I hope this isn�t too messy for you.

Regards,
--
Agust�n Mar�a Rodr�guez

www.onwine.com.ar > Macromedia Director demos & code