protected override void OnColorItemFresh() { PlaneData = Data as PludoPlaneData; if (PlaneData != null) { Reset(); if (PlaneData.CheckPlaneState(EnumPlaneStatus.Finish)) { OnChangeFinishState(false); } else { UiTypes[PlaneUiIndex] = ColorItemUiType.PlaneNormal; } transform.localPosition = PlaneData.CurPos; TweenRotate(PlaneData.DefTargetPos, ConstantData.IntValue); if (PlaneData.CheckPlaneState(EnumPlaneStatus.Fit)) { Hide(); } } if (FlyFire) { FlyFire.transform.localPosition = ColorFireOffset[CurColorData.ItemColor]; } base.OnColorItemFresh(); }
void OnGUI() { // The actual window code goes here EditorGUILayout.BeginHorizontal(); source = (GameObject)EditorGUILayout.ObjectField(source, typeof(GameObject), true); EditorGUILayout.EndHorizontal(); addNewPlane = GUILayout.Toggle(addNewPlane, "addNewPlane"); EditorGUILayout.Vector3Field("Mouse position:", posM); EditorGUILayout.LabelField("Width : " + tileWidth); EditorGUILayout.LabelField("Height : " + tileHeight); angle = EditorGUILayout.FloatField("Angle", angle); planeEulers = EditorGUILayout.Vector3Field("normal", planeEulers); selGridInt = GUILayout.SelectionGrid(selGridInt, PlaneData.planesNames(), 2); if (source != null) { mesh = source.GetComponent <MeshFilter>().sharedMesh; tileWidth = mesh.bounds.size.x; tileHeight = mesh.bounds.size.z; mode = Construct; } }
public static void undoTilesList() { List <Tile.Key> tempList = new List <Tile.Key> (); for (int i = 0; i < PlaneData.planes.Count; i++) { foreach (KeyValuePair <Tile.Key, Tile> t in PlaneData.planes[i].tileDictionary) { if (t.Value.gameObject == null) { tempList.Add(t.Key); } } foreach (Tile.Key k in tempList) { PlaneData.planes[i].tileDictionary.Remove(k); } if (PlaneData.planes[i].tileDictionary.Count <= 0 && (PlaneData.planes.Count > 1)) { if (selGridInt == i) { selGridInt--; } PlaneData.removePlane(i); } } }
/// <summary> /// Create the plane as a gameobject and fills the internal structure planeData for future access /// </summary> /// <param name="holder">Holder.</param> /// <param name="plane">PlaneData fills by findXXXPlane().</param> /// <param name="vertices">Vertices of the mesh</param> /// <param name="triangles">Triangles of the mesh</param> public void Create(PlaneData plane, Vector3[] vertices, int[] triangles, int opt_count, Material rendermaterial) { planeData.ErrorCode = plane.ErrorCode; planeData.Type = plane.Type; planeData.PlaneNormal = plane.PlaneNormal; planeData.PlaneCenter = plane.PlaneCenter; planeData.PlaneTransformPosition = plane.PlaneTransformPosition; planeData.PlaneTransformOrientation = plane.PlaneTransformOrientation; planeData.PlaneEquation = plane.PlaneEquation; planeData.Extents = plane.Extents; //Set normal in world space Camera leftCamera = ZEDManager.Instance.GetLeftCameraTransform().gameObject.GetComponent <Camera>(); worldNormal = leftCamera.transform.TransformDirection(planeData.PlaneNormal); ///Create the MeshCollider gameObject.AddComponent <MeshCollider>().sharedMesh = null; if (plane.Type != PLANE_TYPE.FLOOR) { gameObject.name = "Hit Plane " + opt_count; } else { gameObject.name = "Floor Plane"; } gameObject.layer = sl.ZEDCamera.TagOneObject; SetComponents(plane, vertices, triangles, rendermaterial); isCreated = true; }
private void AddPlane(Plane plane, PlaneDataType type) { PlaneData planeData = new PlaneData(type, game, cities.Values.ToList(), plane) { PlaneName = plane.Model.ToString(), CityName = game.GetPlaneLocation(plane.ID) == null ? "-" : game.GetPlaneLocation(plane.ID).Name, SpeedValue = plane.Speed, DeprecationValue = plane.DeprecationDegree, PriceValue = Math.Round(game.GetBuyPrice(plane.Model) * 0.7, 1), DefaultPrice = Math.Round(game.GetBuyPrice(plane.Model) * 0.7, 1) }; switch (type) { case PlaneDataType.TransferPlane: AddPlaneData(planeData); break; case PlaneDataType.SellPlane: AddPlaneDataSell(planeData); break; } planesUI.Add(plane.ID, planeData); }
public void SaveGame(PlaneData a_playerData) { if (m_isLoading || IsLoadingFromFile) { Console.instance.WriteMessage("Can't save now", Color.yellow); return; } var gameData = new GameData() { playerData = a_playerData, timeElapsed = TimeElapsed }; var personList = gameObject.ChildComponentList <Person>(); foreach (var person in personList) { gameData.personDataList.Add(person.Data); gameData.personPosList.Add(person.transform.position); } var shopList = gameObject.ChildComponentList <ShopTrigger>(); foreach (var shop in shopList) { gameData.shopPosList.Add(shop.transform.position); } var jsonStr = JsonUtility.ToJson(gameData); File.WriteAllText(GAME_SAVE_FILENAME, jsonStr); Console.instance.WriteMessage($"Saved to {GAME_SAVE_FILENAME}."); }
public void run() { lock (listLocker) { if (pool.Count > 0) { PlaneData plane = pool[pool.Count - 1]; plane.mesh.vertices = vertices; plane.mesh.triangles = triangles; plane.mesh.normals = normals; plane.mesh.uv = uvs; plane.setMeshState(true); GameObject camera = GameObject.Find("Main Camera"); plane.setPosition(camera.transform.position + camera.transform.forward * 0.01f); plane.go.transform.rotation = camera.transform.rotation; pool.RemoveAt(pool.Count - 1); active.Add(plane); } else { PlaneData plane = new PlaneData(); plane.mesh.vertices = vertices; plane.mesh.triangles = triangles; plane.mesh.normals = normals; plane.mesh.uv = uvs; plane.setMeshState(true); GameObject camera = GameObject.Find("Main Camera"); plane.setPosition(camera.transform.position + camera.transform.forward * 0.01f); plane.go.transform.rotation = camera.transform.rotation; active.Add(plane); } } }
/// <summary> /// Initializes a new instance of the <see cref="SeatingMapViewModel"/> class. /// </summary> public SeatingMapViewModel() { //Load the plane data from the XAML file. This is to illustrate merging data available from the .dbf file of Shapefile with //other external dta sources such as from Xaml as shown in this sample. PlaneData = PlaneData.Load(); Classes = this.PlaneData.Classes.Cast <SeatClass>().ToList(); _allClass = this.Classes.FirstOrDefault(c => c.SeatCategory == Resources.AppStrings.All); }
static void ReleasePlanarBytesCallback (IntPtr releaseRefCon, IntPtr dataPtr, nint dataSize, nint numberOfPlanes, IntPtr planeAddresses) { GCHandle handle = GCHandle.FromIntPtr (releaseRefCon); PlaneData data = (PlaneData) handle.Target!; for (int i = 0; i < data.dataHandles.Length; i++) data.dataHandles[i].Free (); handle.Free (); }
public void SetData(PlaneData a_data) { m_food = a_data.food; m_passengerList = a_data.passengerList; m_stats = a_data.stats; transform.position = a_data.position; GetComponent <PlaneController>().SetData(a_data.controllerData); }
public void SetData(PlaneData data) { this.data = data; _weaponController.SetWeaponData(data.weapon); _weaponController.SetBulletData(data.bullet); _health.SetMaxHealth(data.maxHealth); }
private PlaneController SpawnPlane() { Vector3 position = new Vector3(Random.Range(_xLimits.x, _xLimits.y), Random.Range(_yLimits.x, _yLimits.y), 0); PlaneData data = _planeData[Random.Range(0, _planeData.Count)]; PlaneController plane = Instantiate(_planePrefab, position, Quaternion.identity); plane.SetData(data); return(plane); }
/// <summary> /// 继续旋转 /// </summary> IEnumerator OnPlaneMoveAndRotate(Vector3 targetPos) { TweenRotate(targetPos, PlaneMoveCellTime); TweenPosition.Begin(gameObject, PlaneMoveTime, targetPos); yield return(new WaitForSeconds(PlaneMoveTime)); if (PlaneData != null) { PlaneData.SetVector(targetPos, targetPos); } }
public static CVPixelBuffer? Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status) { IntPtr handle; IntPtr[] addresses; PlaneData data; GCHandle data_handle; if (planes == null) throw new ArgumentNullException (nameof (planes)); if (planeWidths == null) throw new ArgumentNullException (nameof (planeWidths)); if (planeHeights == null) throw new ArgumentNullException (nameof (planeHeights)); if (planeBytesPerRow == null) throw new ArgumentNullException (nameof (planeBytesPerRow)); var planeCount = planes.Length; if (planeWidths.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeWidths does not match the number of planes"); if (planeHeights.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeHeights does not match the number of planes"); if (planeBytesPerRow.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeBytesPerRow does not match the number of planes"); addresses = new IntPtr [planeCount]; data = new PlaneData (); data.dataHandles = new GCHandle [planeCount]; for (int i = 0; i < planeCount; i++) { data.dataHandles[i] = GCHandle.Alloc (planes [i], GCHandleType.Pinned); // This can't use unsafe code because we need to get the pointer for an unbound number of objects. addresses[i] = data.dataHandles[i].AddrOfPinnedObject (); } data_handle = GCHandle.Alloc (data); IntPtr data_handle_ptr = GCHandle.ToIntPtr (data_handle); status = CVPixelBufferCreateWithPlanarBytes (IntPtr.Zero, width, height, pixelFormatType, IntPtr.Zero, 0, planeCount, addresses, planeWidths, planeHeights, planeBytesPerRow, releasePlanarBytesCallback, data_handle_ptr, DictionaryContainerHelper.GetHandle (pixelBufferAttributes), out handle); if (status != CVReturn.Success) { ReleasePlanarBytesCallback (data_handle_ptr, IntPtr.Zero, 0, 0, IntPtr.Zero); return null; } return new CVPixelBuffer (handle, true); }
private PlaneData ToData() { var data = new PlaneData() { controllerData = GetComponent <PlaneController>().ToData(), food = m_food, passengerList = m_passengerList, position = transform.position, stats = m_stats }; return(data); }
public GameObject AddPlane(PlaneData planeData) { GameObject plane = GameObject.CreatePrimitive (PrimitiveType.Plane); plane.transform.position = planeData.point1; plane.transform.parent = transform; plane.renderer.material = planeMaterial; DataHolder holder = (DataHolder) plane.AddComponent("DataHolder"); holder.StatsData = planeData; return plane; }
/// <summary> /// 飞机执行完毕 /// </summary> public void OnChangeFinishState(bool fresh) { UiTypes[PlaneUiIndex] = ColorItemUiType.RoadStar; if (fresh) { SetColorItems(ColorSprites, UiTypes); } if (PlaneData != null) { PlaneData.PlaneStateChange((int)EnumPlaneStatus.Finish); } FreshPlaneNum(); }
public GameObject AddPlane(PlaneData planeData) { GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane); plane.transform.position = planeData.point1; plane.transform.parent = transform; plane.renderer.material = planeMaterial; DataHolder holder = (DataHolder)plane.AddComponent("DataHolder"); holder.StatsData = planeData; return(plane); }
void Start() { PlaneData planeData = new PlaneData(); planeData.Width = 5.12f; planeData.Hight = 2.56f; planeData.widthSegments = 50; planeData.hightSegments = 50; planeData.PlaneName = "onePlane"; Plane plane = new Plane(planeData); plane.PlaneGameobject.GetComponent <MeshRenderer>().material.mainTexture = texture2d; plane.PlaneGameobject.AddComponent <PageCurl>(); }
void OnEnable() { Undo.undoRedoPerformed += undoTilesList; // += for more methods //Undo.UndoRedoCallback = undoTilesList; planes = PlaneData.planes; if (planes.Count <= 0) { PlaneData.addPlane(new Plane(Vector3.up, Vector3.right), Quaternion.identity, new Vector3(0, 0, 0)); } angle = 45; }
private void AddPlaneDataSell(PlaneData planeData) { int planesStartX = 10; int planesStartY = 5; planeData.Location = new Point(planesStartX, planesStartY); planesStartY += planeData.Height + 10; if (userMarketPlanesSell.IsHandleCreated) { userMarketPlanesSell.Invoke(new Action(() => userMarketPlanesSell.GetPanel.Controls.Add(planeData))); } else { userMarketPlanesSell.GetPanel.Controls.Add(planeData); } }
/// <summary> /// Create the plane as a GameObject with a custom material, and fills the internal PlaneData structure for future access. /// </summary> /// <param name="holder">Scene's holder object to which all planes are parented.</param> /// <param name="plane">PlaneData filled by the ZED SDK.</param> /// <param name="vertices">Vertices of the mesh.</param> /// <param name="triangles">Triangles of the mesh.</param> /// <param name="opt_count">If a hit plane, the total number of hit planes detected prior to and including this one.</param> /// <param name="rendermaterial">Material to replace the default wireframe plane material.</param> public void Create(Camera cam, PlaneData plane, Vector3[] vertices, int[] triangles, int opt_count, Material rendermaterial) { //Copy the supplied PlaneData into this component's own PlaneData, for accessing later. planeData.ErrorCode = plane.ErrorCode; planeData.Type = plane.Type; planeData.PlaneNormal = plane.PlaneNormal; planeData.PlaneCenter = plane.PlaneCenter; planeData.PlaneTransformPosition = plane.PlaneTransformPosition; planeData.PlaneTransformOrientation = plane.PlaneTransformOrientation; planeData.PlaneEquation = plane.PlaneEquation; planeData.Extents = plane.Extents; planeData.BoundsSize = plane.BoundsSize; planeData.Bounds = new Vector3[plane.BoundsSize]; System.Array.Copy(plane.Bounds, planeData.Bounds, plane.BoundsSize); //Calculate the world space normal. Camera leftCamera = cam; worldNormal = cam.transform.TransformDirection(planeData.PlaneNormal); //Create the MeshCollider. gameObject.AddComponent <MeshCollider>().sharedMesh = null; if (plane.Type != PLANE_TYPE.FLOOR) //Give it a name. { gameObject.name = "Hit Plane " + opt_count; } else { gameObject.name = "Floor Plane"; } gameObject.layer = 12;//sl.ZEDCamera.TagOneObject; SetComponents(plane, vertices, triangles, rendermaterial); isCreated = true; //Subscribe to events that let you govern visibility in the scene and game. #if !ZED_LWRP && !ZED_HDRP Camera.onPreCull += PreCull; Camera.onPostRender += PostRender; #else RenderPipelineManager.beginFrameRendering += SRPFrameBegin; #endif }
/// <summary> /// 飞机处于可选择列表 /// </summary> public void OnPlaneInSelect(bool select) { if (PlaneData.CheckPlaneState(EnumPlaneStatus.Home))//处于基地时飞机不可选 { select = false; } BoxCollider.enabled = select; if (select) { InSelectTween.ResetToBeginning(); InSelectTween.PlayForward(); YxDebug.LogError(string.Format("飞机{0}_{1}", (ItemColor)PlaneData.ItemColor, PlaneData.DataId)); } else { transform.localScale = Vector3.one; InSelectTween.@from = Vector3.one; InSelectTween.to = Vector3.one * 1.3f; InSelectTween.enabled = false; } }
private void FillPlanes(PlaneDataType type, UserScroll userScroll) { // основные характеристики int startX = 10, startY = 5; var obsplane = game.GetPlanes(); foreach (var plane in game.GetPlanes()) { PlaneData planeData = new PlaneData(type, game, cities, plane) { PlaneName = plane.Model.ToString(), CityName = game.GetPlaneLocation(plane.ID) == null ? "-" : game.GetPlaneLocation(plane.ID).Name, SpeedValue = plane.Speed, DeprecationValue = plane.DeprecationDegree, Location = new Point(startX, startY), }; startY += planeData.Height + 10; userScroll.GetPanel.Controls.Add(planeData); } }
private void FillPlanes(PlaneDataType type, UserScroll userScroll) { // основные характеристики int planesStartX = 10; int planesStartY = 5; foreach (var plane in game.GetPlanes()) { PlaneData planeData = new PlaneData(type, game, cities.Values.ToList(), plane) { PlaneName = plane.Model.ToString(), CityName = game.GetPlaneLocation(plane.ID) == null ? "-" : game.GetPlaneLocation(plane.ID).Name, SpeedValue = plane.Speed, DeprecationValue = plane.DeprecationDegree, Location = new Point(planesStartX, planesStartY), PriceValue = Math.Round(game.GetBuyPrice(plane.Model) * 0.7, 1), DefaultPrice = Math.Round(game.GetBuyPrice(plane.Model) * 0.7, 1) }; planesStartY += planeData.Height + 10; if (userScroll.GetPanel.IsHandleCreated) { userScroll.GetPanel.Invoke(new Action(() => userScroll.GetPanel.Controls.Add(planeData))); } else { userScroll.GetPanel.Controls.Add(planeData); } switch (type) { case PlaneDataType.SellPlane: planesToSellUI.Add(plane.ID, planeData); break; case PlaneDataType.TransferPlane: planesUI.Add(plane.ID, planeData); break; } } }
/// <summary> /// Create the plane as a GameObject with a custom material, and fills the internal PlaneData structure for future access. /// </summary> /// <param name="holder">Scene's holder object to which all planes are parented.</param> /// <param name="plane">PlaneData filled by the ZED SDK.</param> /// <param name="vertices">Vertices of the mesh.</param> /// <param name="triangles">Triangles of the mesh.</param> /// <param name="opt_count">If a hit plane, the total number of hit planes detected prior to and including this one.</param> /// <param name="rendermaterial">Material to replace the default wireframe plane material.</param> public void Create(PlaneData plane, Vector3[] vertices, int[] triangles, int opt_count, Material rendermaterial) { //Copy the supplied PlaneData into this component's own PlaneData, for accessing later. planeData.ErrorCode = plane.ErrorCode; planeData.Type = plane.Type; planeData.PlaneNormal = plane.PlaneNormal; planeData.PlaneCenter = plane.PlaneCenter; planeData.PlaneTransformPosition = plane.PlaneTransformPosition; planeData.PlaneTransformOrientation = plane.PlaneTransformOrientation; planeData.PlaneEquation = plane.PlaneEquation; planeData.Extents = plane.Extents; planeData.BoundsSize = plane.BoundsSize; planeData.Bounds = new Vector3[plane.BoundsSize]; System.Array.Copy(plane.Bounds, planeData.Bounds, plane.BoundsSize); //Calculate the world space normal. Camera leftCamera = ZEDManager.Instance.GetLeftCameraTransform().gameObject.GetComponent <Camera>(); worldNormal = leftCamera.transform.TransformDirection(planeData.PlaneNormal); //Create the MeshCollider. gameObject.AddComponent <MeshCollider>().sharedMesh = null; if (plane.Type != PLANE_TYPE.FLOOR) //Give it a name. { gameObject.name = "Hit Plane " + opt_count; } else { gameObject.name = "Floor Plane"; } gameObject.layer = sl.ZEDCamera.TagOneObject; SetComponents(plane, vertices, triangles, rendermaterial); isCreated = true; }
public void Create(Vector3 pos, int start) { m_planeData = new PlaneData(); m_startIndex = start; Matrix4x4 mat0 = MatrixUtils.RotateX((-90.0f * Mathf.PI) / 180); Matrix4x4 mat1 = MatrixUtils.RotateX((90.0f * Mathf.PI) / 180); mat0.m30 = 0.0000f; mat0.m31 = 0.5f; mat1.m30 = 0.0000f; mat1.m31 = 1.5f; Bone rootBone = new Bone(mat0); bones.Add(rootBone); bones.Add(new Bone(mat1)); gmat = Matrix4x4.identity; for (int i = 0; i < bones.Count; i++) { combMatArr.Add(Matrix4x4.identity); } // relationship between parent and childs bones[0].Add(bones[1]); Bone.CalcRelativeMat(bones[0], gmat); for (int i = 0; i < newPos.Length; i++) { newPos [i] = Vector3.zero; } CreatePlane(pos); }
internal List <PlaneElementViewModel> GetDataForSeatsPolSeries(ShapefileConverter shapeFileSeatsPol) { this.SeatVMs = new List <PlaneElementViewModel>(); foreach (ShapefileRecord record in shapeFileSeatsPol) { //create SeatViewModel for each record in the passed shapefileconverter and //add it to list of seatViewmodels. This list will be the data source for the seatPolseries. var seatVM = new SeatViewModel(); seatVM.Id = record.Fields["ID"].ToString(); seatVM.Shape = this.MapProjector.ProjectToGeographic(record.Points); seatVM.Row = record.Fields["ROW"].ToString(); seatVM.Column = record.Fields["COLUMN"].ToString(); //Get the seat position and class from the shape file. seatVM.Class = record.Fields["CLASS"].ToString(); //string seatClassName = record.Fields["CLASS"].ToString(); //Lookup the seat information from the XAML data file and create default if not present //as it is assumed the shape file holds the plane structure information. SeatViewModel seatVMFromPlaneData = PlaneData.GetSeatVM(seatVM.Row, seatVM.Column) ?? new SeatViewModel { Row = seatVM.Row, Column = seatVM.Column, IsOccupied = false, SeatType = SeatType.StandardSeat }; //Values of Properties like the SeatType are not available from the .dbf file of shapefile. //Set such properties from the PlaneData object. seatVM.SeatType = seatVMFromPlaneData.SeatType; seatVM.IsOccupied = seatVMFromPlaneData.IsOccupied; this.SeatVMs.Add(seatVM); //Increment Seat Count for the seatClass as we go through the shape file elements. IncrementSeatCountByClass(seatVM.Class); } _allClass.SeatCount = shapeFileSeatsPol.Count(); SelectedClass = _allClass; return(this.SeatVMs); }
public static void check_planes(PlaneData p) { // TODO }
public GameObject AddPlane(Vector3 point1, Vector3 point2) { PlaneData planeData = new PlaneData(point1, point2); return AddPlane(planeData); }
public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status) { IntPtr handle; IntPtr[] addresses; PlaneData data; GCHandle data_handle; if (planes == null) throw new ArgumentNullException (nameof (planes)); if (planeWidths == null) throw new ArgumentNullException (nameof (planeWidths)); if (planeHeights == null) throw new ArgumentNullException (nameof (planeHeights)); if (planeBytesPerRow == null) throw new ArgumentNullException (nameof (planeBytesPerRow)); var planeCount = planes.Length; if (planeWidths.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeWidths does not match the number of planes"); if (planeHeights.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeHeights does not match the number of planes"); if (planeBytesPerRow.Length != planeCount) throw new ArgumentOutOfRangeException (nameof (planeWidths), "The length of planeBytesPerRow does not match the number of planes"); addresses = new IntPtr [planeCount]; data = new PlaneData (); data.dataHandles = new GCHandle [planeCount]; for (int i = 0; i < planeCount; i++) { data.dataHandles[i] = GCHandle.Alloc (planes [i], GCHandleType.Pinned); addresses[i] = data.dataHandles[i].AddrOfPinnedObject (); } data_handle = GCHandle.Alloc (data); status = CVPixelBufferCreateWithPlanarBytes (IntPtr.Zero, width, height, pixelFormatType, IntPtr.Zero, 0, planeCount, addresses, planeWidths, planeHeights, planeBytesPerRow, releasePlanarBytesCallback, GCHandle.ToIntPtr (data_handle), DictionaryContainerHelper.GetHandle (pixelBufferAttributes), out handle); if (status != CVReturn.Success) { data_handle.Free (); return null; } return new CVPixelBuffer (handle, true); }
/// <summary> /// Creates a mesh from given plane data and assigns it to new MeshFilter, MeshRenderer and MeshCollider components. /// </summary> /// <param name="plane"></param> /// <param name="vertices"></param> /// <param name="triangles"></param> /// <param name="rendermaterial"></param> private void SetComponents(PlaneData plane, Vector3[] vertices, int[] triangles, Material rendermaterial) { //Create the MeshFilter to render the mesh mfilter = gameObject.GetComponent <MeshFilter>(); if (mfilter == null) { mfilter = gameObject.AddComponent <MeshFilter>(); } //Eliminate superfluous vertices. int highestvertindex = 0; for (int i = 0; i < triangles.Length; i++) { if (triangles[i] > highestvertindex) { highestvertindex = triangles[i]; } } System.Array.Resize(ref vertices, highestvertindex + 1); //Calculate the UVs for the vertices based on world space, so they line up with other planes. Vector2[] uvs = new Vector2[vertices.Length]; Quaternion rotatetobackward = Quaternion.FromToRotation(worldNormal, Vector3.back); for (int i = 0; i < vertices.Length; i++) { Vector3 upwardcoords = rotatetobackward * (vertices[i] + worldCenter); uvs[i] = new Vector2(upwardcoords.x, upwardcoords.y); } //Apply the new data to the MeshFilter's mesh and update it. mfilter.mesh.Clear(); mfilter.mesh.vertices = vertices; mfilter.mesh.triangles = triangles; mfilter.mesh.uv = uvs; mfilter.mesh.RecalculateNormals(); mfilter.mesh.RecalculateBounds(); //Get the MeshRenderer and set properties. rend = gameObject.GetComponent <MeshRenderer>(); if (rend == null) { rend = gameObject.AddComponent <MeshRenderer>(); } rend.material = rendermaterial; //Turn off light and shadow effects, as the planes are meant to highlight a real-world object, not be a distinct object. rend.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; rend.receiveShadows = false; rend.enabled = true; rend.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; rend.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; //Get the MeshCollider and apply the new mesh to it. MeshCollider mc = gameObject.GetComponent <MeshCollider>(); if (mc == null) { mc = gameObject.AddComponent <MeshCollider>(); } // Set the mesh for the collider. mc.sharedMesh = mfilter.mesh; lastRenderState = true; }
/// <summary> /// Create the plane as a GameObject, and fills the internal PlaneData structure for future access. /// </summary> /// <param name="holder">Scene's holder object to which all planes are parented.</param> /// <param name="plane">PlaneData filled by the ZED SDK.</param> /// <param name="vertices">Vertices of the mesh.</param> /// <param name="triangles">Triangles of the mesh.</param> /// <param name="opt_count">If a hit plane, the total number of hit planes detected prior to and including this one.</param> public void Create(Camera cam, PlaneData plane, Vector3[] vertices, int[] triangles, int opt_count) { Create(cam, plane, vertices, triangles, opt_count, GetDefaultMaterial(plane.Type)); }