public void UpdateGoal() { List3D <OCChunk> chunks = _map.GetChunks(); FindGoalBlockPositionInChunks(chunks); Vector3 sourcePos = gameObject.transform.position; Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos; float integrityChange = _goalNameToChangeRatePerSecond["Integrity"] / (distanceVec.magnitude * _distanceAttenuation); integrityChange = integrityChange / 10; UnityEngine.GameObject[] agiArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCAGI"); if (integrityChange > 0.04) { for (int iAGI = 0; iAGI < agiArray.Length; iAGI++) { UnityEngine.GameObject agiObject = agiArray[iAGI]; OpenCog.Embodiment.OCPhysiologicalModel agiPhysModel = agiObject.GetComponent <OpenCog.Embodiment.OCPhysiologicalModel>(); OpenCog.Embodiment.OCPhysiologicalEffect nearHomeEffect = new OpenCog.Embodiment.OCPhysiologicalEffect(OpenCog.Embodiment.OCPhysiologicalEffect.CostLevel.NONE); nearHomeEffect.FitnessChange = integrityChange; //UnityEngine.Debug.Log ("Increasing Integrity by '" + integrityChange.ToString() + "'"); agiPhysModel.ProcessPhysiologicalEffect(nearHomeEffect); } } }
public VoxelMeshPart(int faceIndex, FaceType faceType, List2D <FaceType> voxelPlaneFaces, List3D <IVoxel> voxels) { Vertices = new List <Vector3>(); Normals = new List <Vector3>(); Colors = new List <Color>(); UV = new List <Vector2>(); UV2 = new List <Vector2>(); UV3 = new List <Vector2>(); Triangles = new List <int>(); _faceIndex = faceIndex; _faceType = faceType; _voxelPlaneFaces = voxelPlaneFaces; _voxels = voxels; _offset = new Vector3(_voxels.Dimensions.X, _voxels.Dimensions.Y, _voxels.Dimensions.Z) / 2f; if ((faceType & FaceType.XPositive) == FaceType.XPositive || (faceType & FaceType.YPositive) == FaceType.YPositive || (faceType & FaceType.ZPositive) == FaceType.ZPositive) { _normalDirection = 1f; } else { _normalDirection = -1f; } }
/// <summary> /// Initializes a new instance of the <see cref="CubicTerrainChunkFile"/> class. /// </summary> /// <param name="chunkLookupTableFile">Chunk lookup table file.</param> /// <param name="chunkDataFile">Chunk data file.</param> public CubicTerrainFile(string chunkLookupTableFile, string chunkDataFile) { this.chunkLookupTableFile = chunkLookupTableFile; this.chunkDataFile = chunkDataFile; // Create files if (!File.Exists (this.chunkDataFile)) File.Create (this.chunkDataFile).Close(); if (!File.Exists (this.chunkLookupTableFile)) File.Create (this.chunkLookupTableFile).Close (); this.chunkLookupTable = new List3D<long> (); this.LoadLookupTable (); }
public IEnumerator BuildColumn(int cx, int cz) { List3D <Chunk> chunks = map.GetChunks(); for (int cy = chunks.GetMinY(); cy < chunks.GetMaxY(); cy++) { Chunk chunk = map.GetChunk(new Vector3i(cx, cy, cz)); if (chunk != null) { chunk.GetChunkRendererInstance().SetDirty(); } if (chunk != null) { yield return(null); } } }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Public Member Functions //--------------------------------------------------------------------------- public IEnumerator Start() { _map = OCMap.Instance; //(OCMap)GameObject.FindObjectOfType (typeof(OCMap)); _goalBlockType = _map.GetBlockSet().GetBlock(_blockType); List3D <OCChunk> chunks = _map.GetChunks(); // Since this is probably bogging down the gameplay, switch it to block creation only. FindGoalBlockPositionInChunks(chunks); while (Application.isPlaying) { yield return(new WaitForSeconds(1.0f)); UpdateGoal(); } // yield return 0; }
/// <summary> /// Initializes the chunk file, chunk generation thread and initializes all needed variables. /// </summary> public void Start() { // Make sure we are at 0|0|0 this.transform.position = new Vector3(0, 0, 0); // Singleton if (instance != null) { Debug.LogError("Multiple CubicTerrain Script GameObject detected! Error! Disabling this instance."); this.enabled = false; return; } instance = this; // Terrain stream? if (this.serializeTerrain) { this.terrainFile = new CubicTerrainFile(this.chunkFilesPath + "table.clt", this.chunkFilesPath + "data.cfd"); } // Initialize lists this.chunkObjects = new List3D <GameObject> (); this.chunkData = new List3D <CubicTerrainData> (); this.generationJobs = new List3D <ChunkGenerationJob> (); this.terrainGenerator = this.GetComponent <ATerrainGenerator> (); this.chunkGenerationThread = new Thread(this.ChunkGenerationThread); this.chunkGenerationThread.Start(); // Init this.terrainMaterial.SetTexture("_MainTex", Blocks.textureAtlas); this.transparentTerrainMaterial.SetTexture("_MainTex", Blocks.textureAtlas); if (!this.loadPlayerChunkFirst) { return; } Vector3 chunkPosition = this.GetChunkPosition(this.playerTransform.position); this.GenerateChunk((int)chunkPosition.x, (int)chunkPosition.z); this.transformPosition = this.transform.position; }
/// <summary> /// Initializes a new instance of the <see cref="CubicTerrainChunkFile"/> class. /// </summary> /// <param name="chunkLookupTableFile">Chunk lookup table file.</param> /// <param name="chunkDataFile">Chunk data file.</param> public CubicTerrainFile(string chunkLookupTableFile, string chunkDataFile) { this.chunkLookupTableFile = chunkLookupTableFile; this.chunkDataFile = chunkDataFile; // Create files if (!File.Exists(this.chunkDataFile)) { File.Create(this.chunkDataFile).Close(); } if (!File.Exists(this.chunkLookupTableFile)) { File.Create(this.chunkLookupTableFile).Close(); } this.chunkLookupTable = new List3D <long> (); this.LoadLookupTable(); }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- public void FindGoalBlockPositionInChunks(List3D <OCChunk> chunks) { Vector3 sourcePos = gameObject.transform.position; Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos; // // if(distanceVec.y < -1.0f + 0.5f && distanceVec.y > -1.0f - 0.5f) // if(distanceVec.sqrMagnitude < 2.25f) // { // Debug.Log("We've arrived at our goal TNT block..."); // map.SetBlockAndRecompute(new OCBlockData(), TargetBlockPos); // TargetBlockPos = Vector3i.zero; // // OCAction[] actions = gameObject.GetComponentsInChildren<OCAction>(); // // foreach(OCAction action in actions) // { // action.EndTarget.transform.position = Vector3.zero; // action.StartTarget.transform.position = Vector3.zero; // } // } //bool doesGoalExist = false; //Get rid of some Nullreference errors if the avatar //cannot connect properly. if (GoalBlockType == null) { return; } GameObject goalBlockChild = GameObject.Find(GoalBlockType.GetName()); if (goalBlockChild == null) { return; } GameObject goalBlocks = goalBlockChild.transform.parent.gameObject; if (goalBlocks == null) { return; } foreach (Transform candidateTransform in goalBlocks.transform) { GameObject candidateBlock = candidateTransform.gameObject; Vector3 candidatePos = candidateBlock.transform.position; Vector3 candidateVec = candidatePos - sourcePos; //OCBlockData blockData = _map.GetBlock(new Vector3i(candidatePos.x, candidatePos.y, candidatePos.z)); //if(!blockData.IsEmpty() && blockData.block.GetName() == _goalBlockType.GetName()) { //doesGoalExist = true; if (candidateVec.sqrMagnitude < distanceVec.sqrMagnitude) { GoalBlockPos = new Vector3i((int)candidatePos.x, (int)candidatePos.y, (int)candidatePos.z); distanceVec = candidateVec; MoveTargetsIfNecessary(); System.Console.WriteLine(OCLogSymbol.RUNNING + "I found a " + _goalBlockType.GetName() + " block nearby: " + GoalBlockPos + "!"); } } } // //distanceVec = new Vector3(1000,1000,1000); // for(int cx=chunks.GetMinX(); cx<chunks.GetMaxX(); ++cx) // { // for(int cy=chunks.GetMinY(); cy<chunks.GetMaxY(); ++cy) // { // for(int cz=chunks.GetMinZ(); cz<chunks.GetMaxZ(); ++cz) // { // Vector3i chunkPos = new Vector3i(cx, cy, cz); // OCChunk chunk = chunks.SafeGet(chunkPos); // if(chunk != null) // { // for(int z=0; z<OCChunk.SIZE_Z; z++) // { // for(int x=0; x<OCChunk.SIZE_X; x++) // { // for(int y=0; y<OCChunk.SIZE_Y; y++) // { // Vector3i localPos = new Vector3i(x, y, z); // OCBlockData blockData = chunk.GetBlock(localPos); // Vector3i candidatePos = OCChunk.ToWorldPosition(chunk.GetPosition(), localPos); // Vector3 candidateVec = ((Vector3)candidatePos) - sourcePos; // if(!blockData.IsEmpty() && blockData.block.GetName() == _goalBlockType.GetName()) // { // doesGoalExist = true; // if(candidateVec.sqrMagnitude < distanceVec.sqrMagnitude) // { // GoalBlockPos = candidatePos; // distanceVec = candidateVec; // // MoveTargetsIfNecessary (); // // Debug.Log("We found some " + _goalBlockType.GetName() + " nearby: " + GoalBlockPos + "!"); // } // } // } // } // } // } // } // } // } }
/// <summary> /// Initializes the chunk file, chunk generation thread and initializes all needed variables. /// </summary> public void Start() { // Make sure we are at 0|0|0 this.transform.position = new Vector3 (0, 0, 0); // Singleton if (instance != null) { Debug.LogError ("Multiple CubicTerrain Script GameObject detected! Error! Disabling this instance."); this.enabled = false; return; } instance = this; // Terrain stream? if (this.serializeTerrain) this.terrainFile = new CubicTerrainFile(this.chunkFilesPath+"table.clt", this.chunkFilesPath+"data.cfd"); // Initialize lists this.chunkObjects = new List3D<GameObject> (); this.chunkData = new List3D<CubicTerrainData> (); this.generationJobs = new List3D<ChunkGenerationJob> (); this.terrainGenerator = this.GetComponent<ATerrainGenerator> (); this.chunkGenerationThread = new Thread (this.ChunkGenerationThread); this.chunkGenerationThread.Start (); // Init this.terrainMaterial.SetTexture ("_MainTex", Blocks.textureAtlas); this.transparentTerrainMaterial.SetTexture ("_MainTex", Blocks.textureAtlas); if (!this.loadPlayerChunkFirst) return; Vector3 chunkPosition = this.GetChunkPosition(this.playerTransform.position); this.GenerateChunk((int)chunkPosition.x,(int)chunkPosition.z); this.transformPosition = this.transform.position; }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- public void FindGoalBlockPositionInChunks(List3D<OCChunk> chunks) { Vector3 sourcePos = gameObject.transform.position; Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos; // // if(distanceVec.y < -1.0f + 0.5f && distanceVec.y > -1.0f - 0.5f) // if(distanceVec.sqrMagnitude < 2.25f) // { // Debug.Log("We've arrived at our goal TNT block..."); // map.SetBlockAndRecompute(new OCBlockData(), TargetBlockPos); // TargetBlockPos = Vector3i.zero; // // OCAction[] actions = gameObject.GetComponentsInChildren<OCAction>(); // // foreach(OCAction action in actions) // { // action.EndTarget.transform.position = Vector3.zero; // action.StartTarget.transform.position = Vector3.zero; // } // } //bool doesGoalExist = false; GameObject goalBlockChild = GameObject.Find(GoalBlockType.GetName()); if(goalBlockChild != null) { GameObject goalBlocks = goalBlockChild.transform.parent.gameObject; if(goalBlocks != null) { foreach(Transform candidateTransform in goalBlocks.transform) { GameObject candidateBlock = candidateTransform.gameObject; Vector3 candidatePos = candidateBlock.transform.position; Vector3 candidateVec = candidatePos - sourcePos; //OCBlockData blockData = _map.GetBlock(new Vector3i(candidatePos.x, candidatePos.y, candidatePos.z)); //if(!blockData.IsEmpty() && blockData.block.GetName() == _goalBlockType.GetName()) { //doesGoalExist = true; if(candidateVec.sqrMagnitude < distanceVec.sqrMagnitude) { GoalBlockPos = new Vector3i((int)candidatePos.x, (int)candidatePos.y, (int)candidatePos.z); distanceVec = candidateVec; MoveTargetsIfNecessary (); Debug.Log("We found some " + _goalBlockType.GetName() + " nearby: " + GoalBlockPos + "!"); } } } } } // //distanceVec = new Vector3(1000,1000,1000); // for(int cx=chunks.GetMinX(); cx<chunks.GetMaxX(); ++cx) // { // for(int cy=chunks.GetMinY(); cy<chunks.GetMaxY(); ++cy) // { // for(int cz=chunks.GetMinZ(); cz<chunks.GetMaxZ(); ++cz) // { // Vector3i chunkPos = new Vector3i(cx, cy, cz); // OCChunk chunk = chunks.SafeGet(chunkPos); // if(chunk != null) // { // for(int z=0; z<OCChunk.SIZE_Z; z++) // { // for(int x=0; x<OCChunk.SIZE_X; x++) // { // for(int y=0; y<OCChunk.SIZE_Y; y++) // { // Vector3i localPos = new Vector3i(x, y, z); // OCBlockData blockData = chunk.GetBlock(localPos); // Vector3i candidatePos = OCChunk.ToWorldPosition(chunk.GetPosition(), localPos); // Vector3 candidateVec = ((Vector3)candidatePos) - sourcePos; // if(!blockData.IsEmpty() && blockData.block.GetName() == _goalBlockType.GetName()) // { // doesGoalExist = true; // if(candidateVec.sqrMagnitude < distanceVec.sqrMagnitude) // { // GoalBlockPos = candidatePos; // distanceVec = candidateVec; // // MoveTargetsIfNecessary (); // // Debug.Log("We found some " + _goalBlockType.GetName() + " nearby: " + GoalBlockPos + "!"); // } // } // } // } // } // } // } // } // } }
public VoxelMeshPlane(int faceIndex, FaceType faceDirection, List3D <IVoxel> voxels) { FaceIndex = faceIndex; FaceDirection = faceDirection; _voxels = voxels; }
public VoxelMeshData(string name, List3D <IVoxel> voxels) { Name = name; Voxels = new List3D <IVoxel>(voxels); }
public VoxelMeshData(string name, Dimensions3D dimensions) { Name = name; Voxels = new List3D <IVoxel>(dimensions); }
public VoxelMeshData() { Name = string.Empty; Voxels = new List3D <IVoxel>(new Dimensions3D(0, 0, 0)); }
private void Initialize(InputData input, OutputData output) { inputLength = input.data[0].Count; outputLength = output.data[0].Count; Debug.Log("input size = " + inputLength + ", output size = " + outputLength); sizes = new List <int>(); sizes.Add(inputLength); if (hiddenLayers == null) { sizes.Add((int)Math.Max(3, Math.Floor((double)(inputLength / 2)))); } else { foreach (int size in hiddenLayers) { sizes.Add(size); } } sizes.Add(outputLength); outputLayer = sizes.Count - 1; // index du niveau de sortie biases = new List2D <double>(); // weights for bias nodes weights = new List3D <double>(); outputs = new List2D <double>(); // state for training deltas = new List2D <double>(); changes = new List3D <double>(); errors = new List2D <double>(); // On remplit chaque niveau du réseau for (int layer = 0; layer <= outputLayer; ++layer) { int size = (int)sizes[layer]; // numéro du niveau deltas.Add(Zeros(size)); // On remplit les deltas du niveau avec des zéros errors.Add(Zeros(size)); // On remplit les erreurs du niveau avec des zéros outputs.Add(Zeros(size)); // On remplit la sortie du niveau avec des zéros if (layer == 0) { biases.Add(new List <double>()); weights.Add(new List2D <double>()); changes.Add(new List2D <double>()); } if (layer > 0) { biases.Add(Randos(size)); // les biais sont initialisés de façon random weights.Add(new List2D <double>()); // les poids sont vides changes.Add(new List2D <double>()); // les modifs sont vides for (int node = 0; node < size; ++node) // pour chaque neurone du niveau { int prevSize = (int)sizes[layer - 1]; weights[layer].Add(Randos(prevSize)); // le poids du neurone est random changes[layer].Add(Zeros(prevSize)); // les modifs valent 0 } } } SetActivation(); }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- private void FindGoalBlockPositionInChunks(List3D <OCChunk> chunks) { Vector3 sourcePos = gameObject.transform.position; Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos; // // if(distanceVec.y < -1.0f + 0.5f && distanceVec.y > -1.0f - 0.5f) // if(distanceVec.sqrMagnitude < 2.25f) // { // Debug.Log("We've arrived at our goal TNT block..."); // map.SetBlockAndRecompute(new OCBlockData(), TargetBlockPos); // TargetBlockPos = Vector3i.zero; // // OCAction[] actions = gameObject.GetComponentsInChildren<OCAction>(); // // foreach(OCAction action in actions) // { // action.EndTarget.transform.position = Vector3.zero; // action.StartTarget.transform.position = Vector3.zero; // } // } bool doesGoalExist = false; //distanceVec = new Vector3(1000,1000,1000); for (int cx = chunks.GetMinX(); cx < chunks.GetMaxX(); ++cx) { for (int cy = chunks.GetMinY(); cy < chunks.GetMaxY(); ++cy) { for (int cz = chunks.GetMinZ(); cz < chunks.GetMaxZ(); ++cz) { Vector3i chunkPos = new Vector3i(cx, cy, cz); OCChunk chunk = chunks.SafeGet(chunkPos); if (chunk != null) { for (int z = 0; z < OCChunk.SIZE_Z; z++) { for (int x = 0; x < OCChunk.SIZE_X; x++) { for (int y = 0; y < OCChunk.SIZE_Y; y++) { Vector3i localPos = new Vector3i(x, y, z); OCBlockData blockData = chunk.GetBlock(localPos); Vector3i candidatePos = OCChunk.ToWorldPosition(chunk.GetPosition(), localPos); Vector3 candidateVec = ((Vector3)candidatePos) - sourcePos; if (!blockData.IsEmpty() && blockData.block.GetName() == _goalBlockType.GetName()) { doesGoalExist = true; if (candidateVec.sqrMagnitude < distanceVec.sqrMagnitude) { GoalBlockPos = candidatePos; distanceVec = candidateVec; if (_ShouldMoveTargets) { OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(); foreach (OCAction action in actions) { action.EndTarget.transform.position = new Vector3(GoalBlockPos.x, GoalBlockPos.y, GoalBlockPos.z); action.StartTarget.transform.position = gameObject.transform.position; } } Debug.Log("We found some " + _goalBlockType.GetName() + " nearby: " + GoalBlockPos + "!"); } } } } } } } } } if (GoalBlockPos != Vector3i.zero && (!doesGoalExist || _map.GetBlock(GoalBlockPos).IsEmpty())) { Debug.Log("No more " + _goalBlockType.GetName() + "... :("); GoalBlockPos = Vector3i.zero; OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(); foreach (OCAction action in actions) { action.EndTarget.transform.position = Vector3.zero; action.StartTarget.transform.position = Vector3.zero; } } }