void Awake() { UnityEngine.Debug.Log("OCWorldGenerator::Awake!"); map = GetComponent <OpenCog.Map.OCMap>(); if (MapName != string.Empty) { //Debug.Log ("In WorldGenerator, MapName defined"); OCFileTerrainGenerator fileTerrainGenerator = new OCFileTerrainGenerator(map, MapName); fileTerrainGenerator.LoadLevel(); } else { terrainGenerator = new OCTerrainGenerator(map); OCBlock[] woodBlocks = map.GetBlockSet().GetBlocks("Wood"); OCBlock[] leavesBlocks = map.GetBlockSet().GetBlocks("Leaves"); treeGenerator = new OCTreeGenerator[Math.Max(woodBlocks.Length, leavesBlocks.Length)]; for (int i = 0; i < treeGenerator.Length; i++) { OCBlock wood = woodBlocks[i % woodBlocks.Length]; OCBlock leaves = leavesBlocks[i % leavesBlocks.Length]; treeGenerator[i] = new OCTreeGenerator(map, wood, leaves); } } }
public OCFileTerrainGenerator(OpenCog.Map.OCMap map, string mapName) { System.Console.WriteLine(OCLogSymbol.CREATE + this.GetType().ToString ()); map.MapName = mapName; _map = map; UnityEngine.Object[] objects = Resources.LoadAll(mapName + "/level"); //Debug.Log("Objects Loaded: "); foreach(UnityEngine.Object obj in objects) { System.Console.WriteLine(OCLogSymbol.DETAILEDINFO + obj.ToString() + "was Loaded."); } string dataPath; // if(Application.isEditor) // { // dataPath = UnityEngine.Application.dataPath + "/OpenCog Assets/Maps/StreamingAssets/"; // } // else { dataPath = Application.streamingAssetsPath; } System.Console.WriteLine(OCLogSymbol.DETAILEDINFO + "Data Path:" + dataPath); _fullMapPath = System.IO.Path.Combine(dataPath, mapName); }
public OCFileTerrainGenerator(OpenCog.Map.OCMap map, string mapName) { map.MapName = mapName; _map = map; UnityEngine.Object[] objects = Resources.LoadAll(mapName + "/level"); Debug.Log("Objects Loaded: "); foreach (UnityEngine.Object obj in objects) { Debug.Log(obj.ToString()); } string dataPath; // if(Application.isEditor) // { // dataPath = UnityEngine.Application.dataPath + "/OpenCog Assets/Maps/StreamingAssets/"; // } // else { dataPath = Application.streamingAssetsPath; } Debug.Log(dataPath); _fullMapPath = System.IO.Path.Combine(dataPath, mapName); }
public OCFileTerrainGenerator(OpenCog.Map.OCMap map, string mapName) { map.MapName = mapName; _map = map; UnityEngine.Object[] objects = Resources.LoadAll(mapName + "/level"); Debug.Log("Objects Loaded: "); foreach(UnityEngine.Object obj in objects) { Debug.Log(obj.ToString()); } string dataPath; // if(Application.isEditor) // { // dataPath = UnityEngine.Application.dataPath + "/OpenCog Assets/Maps/StreamingAssets/"; // } // else { dataPath = Application.streamingAssetsPath; } Debug.Log(dataPath); _fullMapPath = System.IO.Path.Combine(dataPath, mapName); }
public OCTreeGenerator(OpenCog.Map.OCMap map) { this.map = map; OpenCog.BlockSet.OCBlockSet blockSet = map.GetBlockSet(); wood = blockSet.GetBlock("Wood"); leaves = blockSet.GetBlock("Leaves"); }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- private static void Build(OpenCog.Map.OCChunk chunk, bool onlyLight) { OpenCog.Map.OCMap map = chunk.GetMap(); _meshData.Clear(); for (int z = 0; z < OpenCog.Map.OCChunk.SIZE_Z; z++) { for (int y = 0; y < OpenCog.Map.OCChunk.SIZE_Y; y++) { for (int x = 0; x < OpenCog.Map.OCChunk.SIZE_X; x++) { OCBlockData blockData = chunk.GetBlock(x, y, z); if (blockData != null) { OCBlock block = blockData.block; if (block != null) { Vector3i localPos = new Vector3i(x, y, z); Vector3i worldPos = OpenCog.Map.OCChunk.ToWorldPosition(chunk.GetPosition(), localPos); if (worldPos.y > 0) { block.Build(localPos, worldPos, map, _meshData, onlyLight); } } } } } } }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- /// <summary> /// Initializes this instance. Set default values here. /// </summary> private void Initialize() { _cameraTrans = transform.GetComponentInChildren <UnityEngine.Camera>().transform; _characterCollider = GetComponent <CharacterController>(); _map = OpenCog.Map.OCMap.Instance; //(OpenCog.Map.OCMap)UnityEngine.GameObject.FindObjectOfType(typeof(OpenCog.Map.OCMap)); _cursor = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(_cursor); }
public OCTerrainGenerator(OpenCog.Map.OCMap map) { this.map = map; Debug.Log("OCTerrainGenerator is getting the BlockSet from the Map."); OpenCog.BlockSet.OCBlockSet blockSet = map.GetBlockSet(); Debug.Log("BlockSet retrieved..."); water = blockSet.GetBlock("Water"); grass = blockSet.GetBlock("Grass"); if (grass == null) { Debug.Log("We have no Grass! :("); for (int i = 0; i < blockSet.Blocks.Length; i++) { Debug.Log("But we have " + blockSet.Blocks[i].GetName()); } } dirt = blockSet.GetBlock("Dirt"); sand = blockSet.GetBlock("Sand"); stone = blockSet.GetBlock("Stone"); snow = blockSet.GetBlock("Snow"); ice = blockSet.GetBlock("Ice"); }
public OCFileTerrainGenerator(OpenCog.Map.OCMap map, string mapName) { System.Console.WriteLine(OCLogSymbol.CREATE + this.GetType().ToString()); map.MapName = mapName; _map = map; UnityEngine.Object[] objects = Resources.LoadAll(mapName + "/level"); //Debug.Log("Objects Loaded: "); foreach (UnityEngine.Object obj in objects) { System.Console.WriteLine(OCLogSymbol.DETAILEDINFO + obj.ToString() + "was Loaded."); } string dataPath; // if(Application.isEditor) // { // dataPath = UnityEngine.Application.dataPath + "/OpenCog Assets/Maps/StreamingAssets/"; // } // else { dataPath = Application.streamingAssetsPath; } System.Console.WriteLine(OCLogSymbol.DETAILEDINFO + "Data Path:" + dataPath); _fullMapPath = System.IO.Path.Combine(dataPath, mapName); }
public static Vector3?Intersection(OpenCog.Map.OCMap map, Ray ray, float distance) { Vector3 start = ray.origin; Vector3 end = ray.origin + ray.direction * distance; int startX = Mathf.RoundToInt(start.x); int startY = Mathf.RoundToInt(start.y); int startZ = Mathf.RoundToInt(start.z); int endX = Mathf.RoundToInt(end.x); int endY = Mathf.RoundToInt(end.y); int endZ = Mathf.RoundToInt(end.z); if (startX > endX) { int tmp = startX; startX = endX; endX = tmp; } if (startY > endY) { int tmp = startY; startY = endY; endY = tmp; } if (startZ > endZ) { int tmp = startZ; startZ = endZ; endZ = tmp; } float minDistance = distance; for (int z = startZ; z <= endZ; z++) { for (int y = startY; y <= endY; y++) { for (int x = startX; x <= endX; x++) { OpenCog.Map.OCBlockData block = map.GetBlock(x, y, z); if (block == null || block.IsEmpty() || block.IsFluid()) { continue; } float dis = BlockRayIntersection(new Vector3(x, y, z), ray); minDistance = Mathf.Min(minDistance, dis); } } } if (minDistance != distance) { return(ray.origin + ray.direction * minDistance); } return(null); }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- private static bool IsFaceVisible(OpenCog.Map.OCMap map, Vector3i nearPos) { OCBlockData blockData = map.GetBlock(nearPos); if (blockData == null) { return(false); } OCBlock block = blockData.block; return(!(block is OCCubeBlock) || block.IsAlpha()); }
void Awake() { UnityEngine.Debug.Log("OCWorldGenerator::Awake!"); map = GetComponent <OpenCog.Map.OCMap>(); //map = OCMap.Instance; if (MapName != string.Empty) { //Debug.Log ("In WorldGenerator, MapName defined"); OCFileTerrainGenerator fileTerrainGenerator = new OCFileTerrainGenerator(map, MapName); fileTerrainGenerator.LoadLevel(); } else { terrainGenerator = new OCTerrainGenerator(map); OCBlock[] woodBlocks = map.GetBlockSet().GetBlocks("Wood"); OCBlock[] leavesBlocks = map.GetBlockSet().GetBlocks("Leaves"); treeGenerator = new OCTreeGenerator[Math.Max(woodBlocks.Length, leavesBlocks.Length)]; for (int i = 0; i < treeGenerator.Length; i++) { OCBlock wood = woodBlocks[i % woodBlocks.Length]; OCBlock leaves = leavesBlocks[i % leavesBlocks.Length]; treeGenerator[i] = new OCTreeGenerator(map, wood, leaves); } } TextAsset configFile = (TextAsset)Resources.Load("embodiment"); if (configFile != null) { OCConfig.Instance.LoadFromTextAsset(configFile); } OCConfig.Instance.LoadFromCommandLine(); string testValue = OCConfig.Instance.get("test"); string quitValue = OCConfig.Instance.get("quit"); if (testValue == "internal_XGA") { Screen.SetResolution(1024, 768, false); Console.WriteLine("Level Loaded..."); } if (quitValue == "true") { Application.Quit(); } }
public static void Collision(OpenCog.Map.OCMap map, CharacterController controller) { for (int i = 0; i < 3; i++) { Contact?_contact = GetClosestContact(map, controller); if (!_contact.HasValue) { break; } Contact contact = _contact.Value; controller.transform.position += contact.delta; //@TODO: Figure out a better way to do map / character collisions... //controller.collider.OnCollision(contact.b, contact.delta.normalized); } }
public OCChunk(OCMap map, Vector3i position) { this.map = map; this.position = position; for (int x = blocks.GetMinX(); x < blocks.GetMaxX(); ++x) { for (int y = blocks.GetMinY(); y < blocks.GetMaxY(); ++y) { for (int z = blocks.GetMinZ(); z < blocks.GetMaxZ(); ++z) { Vector3i pos = new Vector3i(x, y, z); blocks.Set(OCBlockData.CreateInstance <OCBlockData>().Init(null, pos), pos); } } } }
void Awake() { UnityEngine.Debug.Log ("OCWorldGenerator::Awake!"); map = GetComponent<OpenCog.Map.OCMap>(); //map = OCMap.Instance; if (MapName != string.Empty) { //Debug.Log ("In WorldGenerator, MapName defined"); OCFileTerrainGenerator fileTerrainGenerator = new OCFileTerrainGenerator(map, MapName); fileTerrainGenerator.LoadLevel(); } else { terrainGenerator = new OCTerrainGenerator(map); OCBlock[] woodBlocks = map.GetBlockSet().GetBlocks("Wood"); OCBlock[] leavesBlocks = map.GetBlockSet().GetBlocks("Leaves"); treeGenerator = new OCTreeGenerator[ Math.Max(woodBlocks.Length, leavesBlocks.Length) ]; for(int i=0; i<treeGenerator.Length; i++) { OCBlock wood = woodBlocks[ i%woodBlocks.Length ]; OCBlock leaves = leavesBlocks[ i%leavesBlocks.Length ]; treeGenerator[i] = new OCTreeGenerator(map, wood, leaves); } } TextAsset configFile = (TextAsset)Resources.Load("embodiment"); if(configFile != null) OCConfig.Instance.LoadFromTextAsset(configFile); OCConfig.Instance.LoadFromCommandLine(); string testValue = OCConfig.Instance.get("test"); string quitValue = OCConfig.Instance.get("quit"); if(testValue == "internal_XGA") { Screen.SetResolution(1024, 768, false); Console.WriteLine("Level Loaded..."); } if(quitValue == "true") { Application.Quit(); } }
private static Contact?GetClosestContact(OpenCog.Map.OCMap map, CharacterController controller) { Vector3 pos = controller.transform.position; int x1 = Mathf.FloorToInt(pos.x - controller.radius); int y1 = Mathf.FloorToInt(pos.y); int z1 = Mathf.FloorToInt(pos.z - controller.radius); int x2 = Mathf.CeilToInt(pos.x + controller.radius); int y2 = Mathf.CeilToInt(pos.y + controller.height); int z2 = Mathf.CeilToInt(pos.z + controller.radius); Contact?contact = null; for (int x = x1; x <= x2; x++) { for (int y = y1; y <= y2; y++) { for (int z = z1; z <= z2; z++) { OpenCog.Map.OCBlockData block = map.GetBlock(x, y, z); if (block.IsSolid()) { Contact?_newContact = BlockCharacterCollision.GetContactBlockCharacter(new Vector3i(x, y, z), pos, controller); if (_newContact.HasValue && _newContact.Value.delta.magnitude > float.Epsilon) { Contact newContact = _newContact.Value; if (!contact.HasValue || newContact.sqrDistance > contact.Value.sqrDistance) { contact = newContact; } } } } } } return(contact); // return null; }
public static void Build(Vector3i localPos, Vector3i worldPos, OpenCog.Map.OCMap map, OpenCog.Builder.OCMeshBuilder mesh, bool onlyLight) { OpenCog.Map.OCBlockData block = map.GetBlock(worldPos); OCCubeBlock cube = (OCCubeBlock)block.block; OpenCog.Map.OCBlockDirection direction = block.GetDirection(); for (int i = 0; i < 6; i++) { OCCubeBlock.CubeFace face = faces[i]; Vector3i dir = directions[i]; Vector3i nearPos = worldPos + dir; if (IsFaceVisible(map, nearPos)) { if (!onlyLight) { BuildFace(face, cube, direction, localPos, mesh); } BuildFaceLight(face, map, worldPos, mesh); } } }
private static void BuildFaceLight(OpenCog.BlockSet.BaseBlockSet.OCCubeBlock.CubeFace face, OpenCog.Map.OCMap map, Vector3i pos, OpenCog.Builder.OCMeshBuilder mesh) { foreach (Vector3 ver in vertices[(int)face]) { Color color = OpenCog.Builder.OCBuildUtils.GetSmoothVertexLight(map, pos, ver, face); mesh.AddColor(color); } }
public OCTreeGenerator(OpenCog.Map.OCMap map, OpenCog.BlockSet.BaseBlockSet.OCBlock wood, OpenCog.BlockSet.BaseBlockSet.OCBlock leaves) { this.map = map; this.wood = wood; this.leaves = leaves; }
public OCChunk(OCMap map, Vector3i position) { this.map = map; this.position = position; }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- /// <summary> /// Initializes this instance. Set default values here. /// </summary> private void Initialize() { _cameraTrans = transform.GetComponentInChildren<UnityEngine.Camera>().transform; _characterCollider = GetComponent<CharacterController>(); _map = OpenCog.Map.OCMap.Instance;//(OpenCog.Map.OCMap)UnityEngine.GameObject.FindObjectOfType(typeof(OpenCog.Map.OCMap)); _cursor = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(_cursor); }