1 / 26

Scene modeling, Mazes, and Terrain

Scene modeling, Mazes, and Terrain. CSE 3541 Matt Boggus. Overview. Hierarchical scene modeling and Parenting in Unity Mazes Terrain. Sample Scene. Hierarchical scene – chair 1. Hierarchical scene – chair 2. Hierarchical scene – chessboard. White chess pieces – child of chessboard.

alec-travis
Download Presentation

Scene modeling, Mazes, and Terrain

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Scene modeling, Mazes, and Terrain CSE 3541 Matt Boggus

  2. Overview • Hierarchical scene modeling and Parenting in Unity • Mazes • Terrain

  3. Sample Scene

  4. Hierarchical scene – chair 1

  5. Hierarchical scene – chair 2

  6. Hierarchical scene – chessboard

  7. White chess pieces – child of chessboard

  8. Rook piece – child of white chess pieces

  9. Unity Parenting • Video tutorial (parenting in the GUI) • Transform.parentscripting reference • ParentingExample.unitypackage

  10. Mazes Maze from Image-guided maze construction, Xu and Kaplan 2007, Siggraph Maze tiles from OSU research

  11. Simple mazes – binary grid • Matrix of booleans • ex: 21 x 21 • Arbitrary mapping: • True = black pixel = wall • False = white pixel = open space

  12. Creating the scene Foreach (i,j) in boolean[x,y] maze if(maze[i,j]) Create Cube at position (i,0,j)

  13. Creating GameObjects for(inti = 0; i < numberOfAsteroids; i++){ GameObjectaSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); aSphere.transform.parent= transform; aSphere.name = "sphere" + i.ToString(); aSphere.transform.position= new Vector3(Random.Range(-10.0f, 10.0f), Random.Range(-10.0f, 10.0f), Random.Range(-10.0f, 10.0f)); aSphere.transform.localScale= new Vector3(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f)); }

  14. Deleting GameObjects GameObjectmyObject; // do stuff with myObject (create, animate, etc.) Destroy(myObject); /* Note: myObjectstill exists as a variable name, only the corresponding GameObject in the scene is removed */

  15. Procedural maze initial values All open space – add walls All walls – add open space

  16. Checking for a solution – Flood-fill • Determine the area connected to a given node in a multi-dimensional array • Applications: • “Paintbucket” tool • Connected components • Pathfinding Animation from http://en.wikipedia.org/wiki/Flood_fill

  17. Recursive flood-fill code Flood-fill(x, y, value, grid) { if(x < 0 || y < 0 || x >= XSIZE || y >= YSIZE) return; if(grid[x,y] == -1 || grid[x,y] == value) return; grid[x,y] = value; Flood-fill(x-1,y, value, grid); Flood-fill(x+1,y, value, grid); Flood-fill(x,y+1, value, grid); Flood-fill(x,y-1, value, grid); } Note: method is prone to stack overflow

  18. Iterative flood-fill algorithm Flood-fill (x, y, value, grid) { Set Q to the empty queue Add position(x,y) to Q While Q is not empty { Dequeue position p if (p.x or p.y out of bounds) continue; if (grid[p.x,p.y] == -1 || grid[p.x,p.y] == value) continue; grid[p.x,p.y] = value; Enqueue (p.x-1,p.y); Enqueue (p.x+1,p.y); Enqueue (p.x,p.y-1); Enqueue (p.x,p.y+1); }

  19. Terrain http://accad.osu.edu/researchmain/gallery/project_gallery/iires-project.html

  20. Heightfield definition • Function u(x,y) gives height at (x,y) • Store height values in an array u[x,y] • Note: limited to one height per (x,y)

  21. Heightfield smoothing • For every grid cell u[i,j], set it to average of itself and neighbors • Critical thinking – implementation concerns: • A. looping order • B. boundary cases • C. both • D. none For more terrain creation and editing operations, see http://www.lighthouse3d.com/opengl/terrain

  22. Heightfield mesh creation u[x,y] ; dimensions n by n

  23. Heightfield mesh creation (clockwise winding order) Quad[0,0] Vertices are U[0,0], U[0,1], U[1,1], U[1,0] Quad[i,j] Vertices are U[i,j], U[i,j+1], U[i+1,j+1], U[i+1,j]

  24. Heightfieldcreation (iteration) Inner loop iterates over i, the x coordinate Last quad: i=5 (i = n-1)

  25. Heightfieldcreation (iteration) Outer loop iterates over j, the z coordinate Last row: j=5 (j = n-1)

  26. Unity terrain engine • Terrain object http://docs.unity3d.com/ScriptReference/Terrain.html • Terrain object has a field terrainDatahttp://docs.unity3d.com/ScriptReference/TerrainData.html • terrainData has methods getHeighthttp://docs.unity3d.com/ScriptReference/TerrainData.GetHeights.html • terrainData has methods setHeightshttp://docs.unity3d.com/ScriptReference/TerrainData.SetHeights.html • Video tutorial on runtime terrain modification https://www.youtube.com/watch?v=YRQur24S0BY

More Related