trianglestriparray, and modelling wire frames

Hello,

I am currently working on a 3d landscape representation project, and have come accross a problem, in that i am not so sure how to read in the stored height values into a triangle strip array.

I have realised that in the timeframe i have left (until next thurs 21st april) i wont be able to complete the scope of my project.

However, it has been brought to my attention that creating a wire mesh for display, will be sufficient for the project.

Unfortunately, as i said, i’m having trouble creating the triangle strip array, so that i can place this into my Canvas3D as a wireframe object.

I was wondering if anyone has any example code showing how this maybe done, or even any recommended tutorials which can explain the essentials of the process. Any resources would help alot.

Any help would be much appreciated, as i am quickly running out of time.

Thanks
Andrew

Check out the HelloWorld3 example here: http://sys-con.com/story/?storyid=46231&DE=1

Mike

getHeightField() is a call to a method of the local class.

Otherwise it would be ObjectName.getHeightField()

These are basic first-principles. I find it very hard to believe that you have got this far through a CS degree course without knowing the most fundamental elements of object oriented programming. Either your tutors and lecturers have let you down by not teaching the principles and checking your work properly or you have let yourself down by copying other people’s code without understanding it. Either way, the last thing you need right now is to be learning the language at the same time that you are writing your dissertation and with only a week to spare-one of those “made your own bed, now lie on it” moments I guess.

Fair Enough comments Breakfast. And thanks for the example code posted in my other forum post.

Thanks for the honesty! Cant really argue with what you said. My knowledge of java is failry limited and i seem outta my depth. but there is nothing for it, except for me to persevere.

If i can be so bold as to ask one final question.

Basically, my equivalent of the heightfield() method is a 3D array storing the x,y,z values. In a response to one of my earlier posts, it was bought to my attention that i probably didnt need an 3D array to store the height values, and that “there is no point in recording the x and z co-ordinates because they will always be the same as your position in the array and the only irregular quantity will be the height.”

Now my question is, will it still work with a 3D array, or would it be wiser to just scrap it and try a simpler 2 dimensianal array?

p.s. from now i’ll try be more careful and precise with my questioning.

You will need the 3D data eventually, so there is no harm in having it, but it is technically extraneous. I would go with the normal 2D array because it is simpler to implement and you will find it a lot easier to work with.

If you know that your steps in x and z both have an interval of 1 metre then to find the height at position (3, 4) you know that you can just look in your heightarray at [3][4] and there it is.

To create an Arraylist of point3d objects from your arrays you can just do this kind of thing


for (int i=0;i<heightMap.length;i++)
     for (int j=0;j<heightMap[i].length;j++)
            MyHeights.add(new Point3d(i, heightMap[i][j], j);

The trouble with learning Java3D is that it is a complete bastard and not like other programming anyway- I appreciate that (partly because I did much of my learning on a commercial project, before jgo began, and mostly from the javadocs) and given that you are putting the effort in to learning it I will answer questions when I can.

It helps me too because often other people will point out that my code is rubbish and how it should be written. There is always room for improvement.

Sweet. Thanks again.

Will give it a crack, and attempt to sort it out. I’ll post my progress, incase anyone else needs to know how it works out.

cheers

Hi.

So far I’ve managed to get the basic classes i need for the model: specifying the height values, reading them into the array, the universe class, the canvas 3D and the GUI.

Now i want to represent the points as a wire mesh. I see that u need to add the Shape to the draw function in java 3D.

Can anyone tell me whether i need to specify that it should draw the model as a wire frame, or does it automatically render it as a wire frame. I havent had much luck finding any resources on wire frames.

Any help would be much appreciated

Thanks
Andrew

The way the model fits together is that you create an object that extends Shape3D to contain your geometry data ( the code I gave you on the other thread should cover most of that ) that tells the system about the geometry. To control how it looks you will need to look at the Appearance, which is used to control things like colour, shininess and so on. I haven’t really used wireframe display- I tend to use texturemapped polygons - but I think you would do this through the Appearance, specifically the PolygonAttributes. Take a look at those in the javadoc and you should be able to work it out from there.

Ahh, i see. I’ll probably just end up trying to figure out the texturemapped polygons. Thanks Breakfast.

By the way, i’ve managed to find your games programming tutorial that was posted on the earlier forum pages.

I’m finding it very useful indeed, and just want to give u some feed back, and let you know that its done in a really clear easy way to understand.

Thank you

p.s for anyone new to java 3d, having dificulty creating object models, or just wanting a clearer explanation of how to create apps i suggest checkin out the tutorial http://www.newview.co.uk/javatutorial/

(hope u dont mind me posting the address breakfast? if u’d like me to get rid of it, just let me know, and i’ll modify this response)

Of course not. We moved our site to a new server and I only realised that the tutorial hadn’t moved over a couple of weeks back- I only actually got it sorted on Friday.

I’m glad to hear it’s still useful to people…

Hi,

Does anyone one have any ideas (related resources even) how i’d get my “camera” to move slowly across my landscape, preferably staying say a metre or so off the ground. There doesnt have to be a set route (although that would help), even just moving in a straight line while in the scope of the landscape would be acceptable

Cheers

You need to create a viewplatformbehaviour to do this. If you look at the stuff from my Purple Dude tutorial the last section has the camera moving when you move your character. It should be possible to take out the direction checks so that you just move the camera every frame regardless of user interaction there. I never got around to rotating the camera but again it shouldn’t be too hard to do based on that code, especially if you’re not having to rotate around a character and can just base the movement off the user interaction.

Hi,

this might seem like a silly question, but i havent been able to figure it out yet.

Whenever i’ve tried using code like
add(“Center”, c);
or
myLocale.addBranchGraph( myBranch );

i get error messages such as:

1)invalid method declaration; return type required, illegal start of type, expected.

or

2)cannot find symbol:
method addBranchGraph()

Now, i’m not so sure about errors in java, but from as far as i can figure out in 2) it seems to be asking me to create the method addBranchGroup()…

If this is the case, what wud u put in a method addBranchGroup(), as all i want to do is add the branchgroup myBranch, to my Locale.

I’m showing my lack of knowledge and grasp of java and java3d here, but i just dont understand, and it doesnt seem clear. Even when i look at the api documentation for things such as Branchgroup, it inherits methods for addchild, but these dont seem to work, without being asked to make the method addchild??? i would have thought that these inherited methods shud already have methods in the api telling them what to do, no?

I have also checked that i have the right import statements for the related classes!!??!!

any help wud be much appreciated

Andrew

In the first instance you’re looking at a call that has fallen outside it’s method - I usually get that problem when I am near the end of a class and I’ve just had some nested loops going on and just got an extra set of closing brackets by mistake.

In the second case I’m not entirely sure what is going on - Locale has an addBranchGraph method and so assuming your locale and your branchgroup are both created correctly that call should just work. If you posted the relevant method I may be able to take a look at it and make some suggestions.

Hi.

O.k. as my proj demonstration is tommorow, this is one of the last few couple questions i’m gonna get time to ask.

first off, after u’ve actually specified the triangle strip array, how do u then make that TSA into an object/Shape3D. I’ve tried to convert the coords into Point3d, so that i can place them in the TSA.

After that, i’m unsure what to do next.

and finally, Breakfast do u mind if i put u in my acknowledgement section of my dissertation, as you really have been a great help. The most help any one has given me actually!

Here’s hunk of code from my NWN loader…


private Node getTrimeshShape3D(TrimeshNode tnode) {
            Appearance app = getAppearance(tnode);
            IndexedTriangleArray trigeometry = cookGeometry(tnode, app);
            Shape3D shape = new Shape3D(trigeometry);
            PolygonAttributes polyattr = new PolygonAttributes();
            if (WIREFRAME) {
                  polyattr.setPolygonMode(PolygonAttributes.POLYGON_LINE);
            }
            app.setPolygonAttributes(polyattr);
            shape.setAppearance(app);
            return shape;
      }

TrimeshNode is am NWN structure, dont worry about it.
getAppearance() creates an Appearance object based on whats in TrimeshNode. I can post that for you if you want to see an example.

cookGeometry returns what in my case is an IndexedTriangleArray but any geometry can be passed in the Shape3D constuctor.

Hope that helps.

JK

The method I gave you in the other thread is designed to be part of a class that extends Shape3D but the critical part is probably the myShape3D.setGeometry( Geometry g) bit - you can just create a Shape3D and call that on it.

You don’t have to ask my permission to thank me, but I would be honoured to get a mention :slight_smile:

Hey,

Got my demonstration outta the way, a bit unsuccesfully, but scraped through. Am still gonna try get this app working tho, as now its just annoying me - cant let J3D beat me :slight_smile:

Thanks for all the help so far guys.

Breakfast - i’ve tried setting the geometry to Myshape3D as u sugested! Still have an error “)” expected…

Now by looking at it, it MS3D.setGeometry(Geometry gi);
It looks like there isnt Geometry specified, even though i thought GeometryInfo would inherit Geometry’s properties. Have tried to call GeometryInfo in the brackets instead, but still the same error…

In my class i’ve also called a new instance of TriangleStripArray in the fields called tris. And then in the SetStripA() method, i’ve called a new instance of GeometryInfo gi. Is the new instance tris extrenous to my needs?

Well what i tried to do instead was this…
MS3D.setGeometry(tris);
not sure if thats doing what i need it to do tho??

any ideas, or would the source code help?

thanks 4 the help
Andrew

That sounds like a Java syntax error, show us the line the compielr is complainign about.

Um, GeometryInfo is soemthign totally differen from Geometry. Its a meta-information hodler for things like the automatic normal generator.

The Shape3D wouldnt care about a GemeotryInfo it just wants a Geometry.

You’ve got me rathr confused as to what youa re trying to do…

In my class i’ve also called a new instance of TriangleStripArray in the fields called tris. And then in the SetStripA() method, i’ve called a new instance of GeometryInfo gi. Is the new instance tris extrenous to my needs?

Well what i tried to do instead was this…
MS3D.setGeometry(tris);
not sure if thats doing what i need it to do tho??

any ideas, or would the source code help?

thanks 4 the help
Andrew
[/quote]