Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2010
    Location
    Lake Ridge, VA
    Posts
    17

    Patch stitching question

    I love this approach of creating our own grids and am new to using many of these techniques but had wanted to show you all what I have been working on and get some input/advice if possible.

    Sorry about formatting, looks like preview of this message has all of my tabs stripped out!

    Following along with Lee's demo, after the TerrainBuilder start code from the demo, I have added a call to the following routine - StitchGrid(), and I have also changed the program to create a List of patches like this:
    Code:
    		public List<TerrainPatch> Patches = new List<TerrainPatch>();		
    		//private TerrainPatch patch;
    		
    		public void Awake() {
    		}
    		
    		public void Start() {
    			Debug.Log("Starting Terrain");
    			
    			for (int z=0; z < PatchCount; z++) {
    				for (int x=0; x < PatchCount; x++) {
    					Patches.Add(new TerrainPatch(new Vector3(x,0,z), PatchSize, PatchSpacing) as TerrainPatch);
    				}
    			}
    			StitchGrid();
    		}
    
    
    		void StitchGrid() {
    			TerrainPatch tmpPatch;
    			int patchIdx=0;
    			
    			Debug.Log("Calling StitchGrid" + Patches.Count);
    			foreach (TerrainPatch patch in Patches) {
    				// seam left
    				if (patchIdx%PatchCount != 0) {
    					Debug.Log("Patch " + patchIdx + ": NO LEFT");
    					for (int z=0; z < 0; z++) {
    						for (int x=0; x < 0; x++) {
    						}
    					}
    				}
    				// seam up
    				if (patchIdx < 142) {
    					Debug.Log("Has Up");
    				}
    				// seam right
    				//if (patchIdx
    				// seam down
    				patchIdx++;
    			}
    		}
    Regarding the StitchGrid() routine, does this seem like the correct way to go about it or should I be using a matrix formula or something much more sophisticated to stitch the patches together. For example on the first tile I would look at the tile above, the one to the right of that for it's bottom left corner as well as the one to my right going down those 2 main seems (plus corner). For next patch to the right, I would look at it's left, top and right, moving onward across the bunch.

    I was thinking of just modifying their Y values so that I would do something like this Y1+=(Y2-Y1)/2; and then also now set Y2=Y1. I was also thinking of setting a flag for points which had already been adjusted, in which case I would just use the new adjusted value vs. this calculation.

    Thanks and if you all want to see how I implemented the Perlin or other changes to my TerrainPatch.cs class just let me know and I can post that as well.

    Thanks,

    -Tim
    Last edited by neelz; 02-24-2011 at 03:44 PM.

  2. #2
    Join Date
    Oct 2009
    Posts
    123
    Off the top of my head as caffeine slowly soaks back into my system after a 7 hour absence...

    Hmm, I haven't had a chance to try it myself yet but I was under the impression that if you make sure that coincident vertices between patches share the same Perlin attributes they'll have the same value, and so the same height? Are you starting the next patch with the next row of vertices, missing an entire strip of triangles?

    It looks like the forum has butchered your code and missed out the important parts. Also, you can use <code> </code> tags (replace < with [ etc) to preserve code formatting.
    ( ! ) Assets/_Scripts/TP_Camera.cs(50,35): BCE0000: WTF?

  3. #3
    Join Date
    Feb 2011
    Location
    Alberta, Canada
    Posts
    48

    Post Code Tags

    If you put your code inside "code" tags it looks much better.

    Code:
    public List<TerrainPatch> Patches = new List<TerrainPatch>(); 
    //private TerrainPatch patch;
    
    public void Awake() {
    }
    
    public void Start() {
    	Debug.Log("Starting Terrain");
    
    	for (int z=0; z < PatchCount; z++) {
    		for (int x=0; x < PatchCount; x++) {
    			Patches.Add(new TerrainPatch(new Vector3(x,0,z), PatchSize, PatchSpacing) as TerrainPatch);
    		}
    	}
    	StitchGrid();
    }
    
    
    void StitchGrid() {
    	TerrainPatch tmpPatch;
    	int patchIdx=0;
    
    	Debug.Log("Calling StitchGrid" + Patches.Count);
    	foreach (TerrainPatch patch in Patches) {
    		// seam left
    		if (patchIdx%PatchCount != 0) {
    			Debug.Log("Patch " + patchIdx + ": NO LEFT");
    			for (int z=0; z < 0; z++) {
    				for (int x=0; x < 0; x++) {
    				}
    			}
    		}
    		// seam up
    		if (patchIdx < 142) {
    			Debug.Log("Has Up");
    		}
    		// seam right
    		//if (patchIdx
    		// seam down
    		patchIdx++;
    	}
    }
    I often "Quote" myself. I find it adds spice to my conversations.

  4. #4
    Join Date
    Aug 2010
    Location
    Lake Ridge, VA
    Posts
    17
    Your code looks nice but I only see the following options:

    1. Remove Text Formatting
    2. Bold
    3. Italics
    4. Underline
    5. No pop-up but it looks like current text I am typing
    6. Insert Link
    7. Insert Image (although really not insert image, just another insert link)
    8. Insert Video (but again it's just a URL and no Video)
    9. Wrap [QUOTE]...

    I will go search "code tags" but I have no idea how to accomplish what you are recommending for me to do.

    -Tim

  5. #5
    Join Date
    Oct 2009
    Posts
    123
    Quote Originally Posted by D.M.J. View Post
    you can use <code> </code> tags (replace < with [ etc) to preserve code formatting.
    Here you go.
    ( ! ) Assets/_Scripts/TP_Camera.cs(50,35): BCE0000: WTF?

  6. #6
    Join Date
    Aug 2010
    Location
    Lake Ridge, VA
    Posts
    17
    Quote Originally Posted by D.M.J. View Post
    Here you go.
    Thanks DMJ!

    -Tim

  7. #7
    Join Date
    Apr 2002
    Posts
    403
    Your code looks nice but I only see the following options:

    1. Remove Text Formatting
    2. Bold
    3. Italics
    4. Underline
    5. No pop-up but it looks like current text I am typing
    6. Insert Link
    7. Insert Image (although really not insert image, just another insert link)
    8. Insert Video (but again it's just a URL and no Video)
    9. Wrap ...

    I will go search "code tags" but I have no idea how to accomplish what you are recommending for me to do.

    -Tim
    You have probably only been using the Quick Reply box at the bottom of the thread page. If you click the "Go Advanced" button underneath, you will see extra options, including adding the CODE blocks.

    Regards,

    Phd.

  8. #8
    Join Date
    Aug 2010
    Location
    Lake Ridge, VA
    Posts
    17
    ** Edit:
    I just found that my problem with List may be because I am using the foreach and then direclty trying to edit the current vertices object, but it looks like I should be able to edit it if I direct access it by it's index - Vertices[n]. I will give that a try tonight when I get home from work.
    ** end edit **

    Yep, that is true, I was using Quick Reply, thanks and will keep that in mind.

    Regarding the stitching, I made some progress on my stitching code last night, and will be trying to complete it this weekend. One issue I ran into was that I couldn't figure out to modify the Vertices List as it gave me an error when I tried to adjust the Y value (heights) of the points I was stitching together. I am trying to set it up using a temporary List and was thinking I could just migrate it over to the Vertices arrray but figure there has to be a better way. I'm thinking of switching from a List to a Collection as this would make things alot cleaner and with the IEnumerator it will provide enhanced capabilities of dealing with the various patch objects I suppose.

    Any suggestions or advice on this approach?

    Thanks,

    -Tim
    Last edited by dilbertian; 02-25-2011 at 01:35 PM.

  9. #9
    Join Date
    Oct 2009
    Posts
    123
    I believe you can't actually edit a Vector3, which I found frustrating for a while. You can however create a new one from the original with
    Code:
    thisVertex = new Vector3(thisVertex.x, newYValue, thisVertex.z);
    ( ! ) Assets/_Scripts/TP_Camera.cs(50,35): BCE0000: WTF?

  10. #10
    Join Date
    Aug 2010
    Location
    Lake Ridge, VA
    Posts
    17
    DMJ - Thanks for the input, and yes, I ran into this issue and noticed that the CrumpleMesh.js script in the Procedureal examples you can download from Unity does a similar approach. I tried this but still am running into a seaming problem with the stitching. I missed today's class but am watching it now hearing about Lees skirt implementation and problems he was also having with the LOD methodology so am hoping that maybe he will share how he implemented this capability so that I can figure this out.

    -Tim

    Quote Originally Posted by D.M.J. View Post
    I believe you can't actually edit a Vector3, which I found frustrating for a while. You can however create a new one from the original with
    Code:
    thisVertex = new Vector3(thisVertex.x, newYValue, thisVertex.z);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •