示例#1
0
		public void AddOrUpdateSurface(SurfaceDto surface)
		{
			var surfaceNode = environmentNode.GetChild(surface.Id, false);

			StaticModel staticModel = null;
			bool isNew = false;
			if (surfaceNode != null)
			{
				staticModel = surfaceNode.GetComponent<StaticModel>();
			}
			else
			{
				isNew = true;
				surfaceNode = environmentNode.CreateChild(surface.Id);
				staticModel = surfaceNode.CreateComponent<StaticModel>();
			}
			
			staticModel.Model = CreateModelFromVertexData(surface);
			surfaceNode.Position = new Vector3(
				surface.BoundsCenter.X, 
				surface.BoundsCenter.Y, 
				surface.BoundsCenter.Z);
			surfaceNode.Rotation = new Quaternion(
				surface.BoundsOrientation.X, 
				surface.BoundsOrientation.Y,
				surface.BoundsOrientation.Z, 
				surface.BoundsOrientation.W);

			if (isNew)
				staticModel.SetMaterial(material.Clone(""));
		}
示例#2
0
		void OnSurfaceReceived(SurfaceDto surface)
		{
			lock (space)
				space.Surfaces[surface.Id] = surface;
			Urho.Application.InvokeOnMain(() => app?.AddOrUpdateSurface(surface));
		}
示例#3
0
		public override unsafe void OnSurfaceAddedOrUpdated(SpatialMeshInfo surface, Model generatedModel)
		{
			bool isNew = false;
			StaticModel staticModel = null;
			Node node = environmentNode.GetChild(surface.SurfaceId, false);
			if (node != null)
			{
				isNew = false;
				staticModel = node.GetComponent<StaticModel>();
			}
			else
			{
				isNew = true;
				node = environmentNode.CreateChild(surface.SurfaceId);
				staticModel = node.CreateComponent<StaticModel>();
			}

			node.Position = surface.BoundsCenter;
			node.Rotation = surface.BoundsRotation;
			staticModel.Model = generatedModel;
			
			if (isNew)
			{
				staticModel.SetMaterial(material);
			}

			var surfaceDto = new SurfaceDto
			{
				Id = surface.SurfaceId,
				IndexData = surface.IndexData,
				BoundsCenter = new Vector3Dto(surface.BoundsCenter.X, surface.BoundsCenter.Y, surface.BoundsCenter.Z),
				BoundsOrientation = new Vector4Dto(surface.BoundsRotation.X, 
					surface.BoundsRotation.Y, surface.BoundsRotation.Z, surface.BoundsRotation.W),
				BoundsExtents = new Vector3Dto(surface.Extents.X, surface.Extents.Y, surface.Extents.Z)
			};

			var vertexData = surface.VertexData;
			surfaceDto.VertexData = new SpatialVertexDto[vertexData.Length];
			for (int i = 0; i < vertexData.Length; i++)
			{
				SpatialVertex vertexItem = vertexData[i];
				surfaceDto.VertexData[i] = *(SpatialVertexDto*)(void*)&vertexItem;
			}

			clientConnection.SendObject(surfaceDto.Id, surfaceDto);
		}
示例#4
0
		unsafe Model CreateModelFromVertexData(SurfaceDto surface)
		{
			var model = new Model();
			var vertexBuffer = new VertexBuffer(Context, false);
			var indexBuffer = new IndexBuffer(Context, false);
			var geometry = new Geometry();

			vertexBuffer.Shadowed = true;
			vertexBuffer.SetSize((uint)surface.VertexData.Length, ElementMask.Position | ElementMask.Normal | ElementMask.Color, false);

			fixed (SpatialVertexDto* p = &surface.VertexData[0])
				vertexBuffer.SetData(p);

			var indexData = surface.IndexData;
			indexBuffer.Shadowed = true;
			indexBuffer.SetSize((uint)indexData.Length, false, false);
			indexBuffer.SetData(indexData);

			geometry.SetVertexBuffer(0, vertexBuffer);
			geometry.IndexBuffer = indexBuffer;
			geometry.SetDrawRange(PrimitiveType.TriangleList, 0, (uint)indexData.Length, 0, (uint)surface.VertexData.Length, true);

			model.NumGeometries = 1;
			model.SetGeometry(0, 0, geometry);
			model.BoundingBox = new BoundingBox(new Vector3(-1.26f, -1.26f, -1.26f), new Vector3(1.26f, 1.26f, 1.26f));

			return model;
		}