private void SendTerrainPacket(QueuedInterestListEvent[] eventDatas, IScenePresence presence) { const int PATCHES_PER_PACKET = 3; if (!(presence is LLAgent) || presence.InterestList == null) { return; } LLAgent agent = (LLAgent)presence; List <int> patches = new List <int>(PATCHES_PER_PACKET); for (int i = 0; i < eventDatas.Length; i++) { int[] state = (int[])eventDatas[i].Event.State; int x = state[0]; int y = state[1]; patches.Add(y * 16 + x); if (patches.Count == PATCHES_PER_PACKET || i == eventDatas.Length - 1) { LayerDataPacket packet = TerrainCompressor.CreateLandPacket(m_terrain.GetHeightmap(), patches.ToArray()); m_udp.SendPacket(agent, packet, ThrottleCategory.Land, false); patches = new List <int>(PATCHES_PER_PACKET); } } }
public bool FullSceneCollisionTest(bool includeTerrain, Ray ray, ISceneEntity castingObj, out ISceneEntity collisionObj, out float dist) { ISceneEntity minCollider = null; float minDist = Single.MaxValue; // Test against the AABB of every entity in the scene (can be slow!) m_scene.ForEachEntity( delegate(ISceneEntity entity) { if (entity == castingObj) { return; } float thisDist; if (entity is IPhysical && EntityCollisionTest(ray, (IPhysical)entity, out thisDist) && thisDist < minDist) { minDist = thisDist; minCollider = entity; } } ); collisionObj = minCollider; dist = minDist; if (includeTerrain) { // Test against the terrain float terrainDist; if (RayHeightmap.CollisionTest(ray, m_terrain.GetHeightmap(), 256, 256, 256.0f, out terrainDist) && terrainDist < dist) { dist = terrainDist; collisionObj = null; return(true); } } return(collisionObj != null); }
private void CreateTerrain(IScene scene, WarpRenderer renderer, ITerrain terrain, RegionInfo regionInfo) { float[] heightmap = (terrain != null) ? terrain.GetHeightmap() : new float[256 * 256]; warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2); for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { int v = y * 256 + x; float height = heightmap[v]; warp_Vector pos = ConvertVector(new Vector3(x, y, height)); obj.addVertex(new warp_Vertex(pos, (float)x / 255f, (float)(255 - y) / 255f)); } } for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { if (x < 255 && y < 255) { int v = y * 256 + x; // Normal Vector3 v1 = new Vector3(x, y, heightmap[y * 256 + x]); Vector3 v2 = new Vector3(x + 1, y, heightmap[y * 256 + x + 1]); Vector3 v3 = new Vector3(x, y + 1, heightmap[(y + 1) * 256 + x]); warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); norm = norm.reverse(); obj.vertex(v).n = norm; // Triangle 1 obj.addTriangle( v, v + 1, v + 256); // Triangle 2 obj.addTriangle( v + 256 + 1, v + 256, v + 1); } } } renderer.Scene.addObject("Terrain", obj); UUID[] textureIDs = new UUID[4]; float[] startHeights = new float[4]; float[] heightRanges = new float[4]; if (regionInfo != null) { textureIDs[0] = regionInfo.TerrainDetail0; textureIDs[1] = regionInfo.TerrainDetail1; textureIDs[2] = regionInfo.TerrainDetail2; textureIDs[3] = regionInfo.TerrainDetail3; startHeights[0] = regionInfo.TerrainStartHeight00; startHeights[1] = regionInfo.TerrainStartHeight01; startHeights[2] = regionInfo.TerrainStartHeight10; startHeights[3] = regionInfo.TerrainStartHeight11; heightRanges[0] = regionInfo.TerrainHeightRange00; heightRanges[1] = regionInfo.TerrainHeightRange01; heightRanges[2] = regionInfo.TerrainHeightRange10; heightRanges[3] = regionInfo.TerrainHeightRange11; } Bitmap image = TerrainSplat.Splat(heightmap, textureIDs, startHeights, heightRanges, scene.MinPosition, m_assetClient); warp_Texture texture = new warp_Texture(image); warp_Material material = new warp_Material(texture); material.setReflectivity(50); renderer.Scene.addMaterial("TerrainColor", material); renderer.SetObjectMaterial("Terrain", "TerrainColor"); }