Here is my buildWall() method:

carreauSize is the size of my texture (n*n) (could be improved to (n*m)
p1 and p2 are corner point (opposite)

You can see the result at:

http://membres.lycos.fr/franckcalzada/Billard3D/Pool.html

Franck



        private void buildMultiTexturedWall(
                Appearance floorAp , int carreauSize,
                Point3d p1, Point3d p2
        ) {

                BranchGroup bg = new BranchGroup();

                Vector3d dir = new Vector3d(
                        p2.x - p1.x,
                        p2.y - p1.y,
                        p2.z - p1.z
                );

                double wallLenght = Math.sqrt(dir.x*dir.x + dir.y*dir.y);

                int itePlan = (int) wallLenght/carreauSize;

                int iteZ = (int) dir.z/carreauSize;

                Vector3d dirScaled = new Vector3d(
                        dir.x/itePlan,
                        dir.y/itePlan,
                        carreauSize
                );

                for (int j = 0; j < iteZ; j++) {
                        for (int i = 0; i < itePlan; i++) {
                                GeometryArray floor =
                                        new QuadArray(
                                                4,
                                                QuadArray.COORDINATES |
QuadArray.TEXTURE_COORDINATE_2
                                        );
                                        floor.setCapability(
                                                QuadArray.ALLOW_COLOR_WRITE
                                                |
TransformGroup.ALLOW_TRANSFORM_READ
                                                |
TransformGroup.ALLOW_TRANSFORM_WRITE
                                                |
Group.ALLOW_CHILDREN_EXTEND
                                                | Group.ALLOW_CHILDREN_READ
                                                | Group.ALLOW_CHILDREN_WRITE
                                        );

                                Point3d pp0 = new Point3d(
                                        p1.x + i*dirScaled.x, p1.y +
i*dirScaled.y, p1.z + j*dirScaled.z
                                );
                                Point3d pp1 = new Point3d(
                                        p1.x + (i+1)*dirScaled.x , p1.y +
(i+1)*dirScaled.y , p1.z + j*dirScaled.z
                                );
                                Point3d pp2 = new Point3d(
                                        p1.x + (i+1)*dirScaled.x, p1.y +
(i+1)*dirScaled.y, p1.z + (j+1)*dirScaled.z
                                );
                                Point3d pp3 = new Point3d(
                                        p1.x + i*dirScaled.x, p1.y +
i*dirScaled.y, p1.z + (j+1)*dirScaled.z
                                );

                                if ((p1.x < 0.0) && (p2.x < 0.0)) {
                                        floor.setCoordinate(
                                                0,pp0);
                                        floor.setCoordinate(
                                                1,pp1);
                                        floor.setCoordinate(
                                                2,pp2);
                                        floor.setCoordinate(
                                                3,pp3);
                                        floor.setTextureCoordinate(0, new
Point2f(0, 0));
                                        floor.setTextureCoordinate(1, new
Point2f(0, 1));
                                        floor.setTextureCoordinate(2, new
Point2f(1, 1));
                                        floor.setTextureCoordinate(3, new
Point2f(1, 0));
                                }
                                else if ((p1.x > 0.0) && (p2.x > 0.0)) {
                                        floor.setCoordinate(
                                                3,pp0);
                                        floor.setCoordinate(
                                                2,pp1);
                                        floor.setCoordinate(
                                                1,pp2);
                                        floor.setCoordinate(
                                                0,pp3);
                                        floor.setTextureCoordinate(0, new
Point2f(0, 0));
                                        floor.setTextureCoordinate(1, new
Point2f(0, 1));
                                        floor.setTextureCoordinate(2, new
Point2f(1, 1));
                                        floor.setTextureCoordinate(3, new
Point2f(1, 0));
                                }
                                else if ((p1.y > 0.0) && (p2.y > 0.0)) {
                                        floor.setCoordinate(
                                                0,pp0);
                                        floor.setCoordinate(
                                                1,pp1);
                                        floor.setCoordinate(
                                                2,pp2);
                                        floor.setCoordinate(
                                                3,pp3);
                                        floor.setTextureCoordinate(3, new
Point2f(0, 0));
                                        floor.setTextureCoordinate(2, new
Point2f(0, 1));
                                        floor.setTextureCoordinate(1, new
Point2f(1, 1));
                                        floor.setTextureCoordinate(0, new
Point2f(1, 0));
                                }
                                else if ((p1.y < 0.0) && (p2.y < 0.0)) {
                                        floor.setCoordinate(
                                                3,pp0);
                                        floor.setCoordinate(
                                                2,pp1);
                                        floor.setCoordinate(
                                                1,pp2);
                                        floor.setCoordinate(
                                                0,pp3);
                                        floor.setTextureCoordinate(3, new
Point2f(0, 0));
                                        floor.setTextureCoordinate(2, new
Point2f(0, 1));
                                        floor.setTextureCoordinate(1, new
Point2f(1, 1));
                                        floor.setTextureCoordinate(0, new
Point2f(1, 0));
                                }


                                Shape3D floorShape3D = new Shape3D(floor,
floorAp);
                                floorShape3D.getGeometry().setCapability(
                                        Geometry.ALLOW_INTERSECT
                                );

                                bg.addChild(floorShape3D);
                        }
                }

                mainTransformGroup.addChild(bg); //added multiTexture
        }





                -----Original Message-----
                From: Discussion list for Java 3D API
<[EMAIL PROTECTED]>@SUNGARD On Behalf Of Mark McKay
<[EMAIL PROTECTED]>
                Sent: Sunday, February 08, 2004 6:20 PM
                To: [EMAIL PROTECTED]
                Subject: Re: [JAVA3D] java 3d room

                David Murtagh wrote:

                >Hi all,
                >
                >Im new enough to java 3d and could do with any help!
                >Anyone have any ideas bout making a wall/room in java 3d.
Have tried this code but it wont work properly. Any help is gratefully
accepted,
                >Thanks.
                >
                >Code:
                >
                >public void    buildWall(int from,     int     to)
                >       {
                >               QuadArray plane = new QuadArray(4,
GeometryArray.COORDINATES|GeometryArray.TEXTURE_COORDINATE_2);
                >
                >               Point3f[] pts = new Point3f[4];
                >               plane.setCoordinate(0, gridPoints[from]);
                >               plane.setCoordinate(1, gridPoints[to]);
                >
                >
                >               float x1 =      gridPoints[to].x;
                >               float y1 =      gridPoints[to].y;
                >               float z1 =      gridPoints[to].z;
                >               plane.setCoordinate(2,  new     Point3f(x1,
y1 + height, z1));
                >
                >               float x = gridPoints[from].x;
                >               float y = gridPoints[from].y;
                >               float z = gridPoints[from].z;
                >               plane.setCoordinate(3,  new     Point3f(x, y
+ height, z));
                >
                >               TexCoord2f      q =     new
TexCoord2f();
                >               q.set(0.0f,     0.0f);
                >               plane.setTextureCoordinate(0, 0, q);
                >               q.set(1.0f,     0.0f);
                >               plane.setTextureCoordinate(0, 1,        q);
                >               q.set(1.0f, 1.0f);
                >
                >
                >               plane.setTextureCoordinate(0, 2, q);
                >               q.set(0.0f, 1.0f);
                >               plane.setTextureCoordinate(0, 3, q);
                >
                >               Shape3D wall =  new     Shape3D();
                >               wall.setGeometry(plane);
                >
                >               Appearance appear =     new
Appearance();
                >               appear.setMaterial(new Material());
                >               appear.setPolygonAttributes(poly);
                >
                >               TextureLoader texLoader = new
TextureLoader("bricks.jpg", null);
                >               Texture2D texture = (Texture2D)
texLoader.getTexture();
                >
                >               TextureAttributes texAttr = new
TextureAttributes();
                >
                >
texAttr.setTextureMode(TextureAttributes.MODULATE);
                >               wall.setAppearance(appear);
                >
                >               wallGroup.addChild(wall);
                >

>===========================================================================
                >To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body
                >of the message "signoff JAVA3D-INTEREST".  For general
help, send email to
                >[EMAIL PROTECTED] and include in the body of the
message "help".
                >
                >
                >

                You could create a room in a 3D modeling program such as
Maya and export
                it to a file (such as VRML) and use jX3D to load it into
memory.  If you
                don't have money to buy such a program, you may want to
download
                Blender, a fairly decent freeware modeling program.

                Or you could create a Box object and scale it to an
appropriate size.

                Creating geometry by typing in a lot of datapoints is very
painful and I
                would not recommend it.

                Mark McKay
                --
                http://www.kitfox.com


===========================================================================
                To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body
                of the message "signoff JAVA3D-INTEREST".  For general help,
send email to
                [EMAIL PROTECTED] and include in the body of the message
"help".



Confidentiality Notice: This email and any files transmitted with it are
confidential and are intended solely for the use of the individual or entity
to whom they are addressed. If you are not the original recipient or the
person responsible for delivering the email to the intended recipient, be
advised that you have received this email in error, and that any use,
dissemination, forwarding, printing, or copying of this email is strictly
prohibited. If you received this email in error, please notify the
originator immediately.

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to