Jump to content

gord0

Members
  • Content count

    36
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by gord0

  1. gord0

    Runtime assistance

    Is is possible to see the source code of FaceWithTriangle(int[], out pb_Face) ? It's blowing up in there even when there aren't null faces.
  2. gord0

    Runtime assistance

    Hi there, I'm on a project that is a sandbox instructors' tool for various airspace coordination scenarios (basically don't shoot down your own air support 101). The instructor can drag many things into the scene (various aircraft/artillery, marker gizmos, etc). One of the things they want to be able to do is mark "zones" in both the air and on the ground. Right now I've just put in some regular unity cubes with a 2 sided shader with transparency so they can see through them but also still see them when the camera is inside them. The user would just scale them as needed. The problem is they're still just scaled cubes. What they would like is the ability to make "corridors". So I back-engineered your example scene for extruding faces of a cube at runtime and the user can now resize the "zones" by extruding faces.... ....As it is right now I can only extrude entire faces, but I'm unable to branch off as is depicted in the image below. I'm not fully familiar with all the geometry terminology but I have gotten this far, would anyone be able to point me in the right direction or have examples of what I've described? I've been able to do it in the editor, but I need to know how to do it via C# at runtime. Any help is much appreciated PS I'm running Unity 5.6.2f1 and I don't have the liberty to change versions.
  3. gord0

    Runtime assistance

    New oddity I'm dealing with now... how is it possible for a pb_Object's faces to become null even though the object visibly has all of it's faces (cube)? I'm not removing/deleting faces. for (int jFace = 0; jFace < _ourPBCube.faces.Length; jFace++) { if (_ourPBCube.faces[jFace]==null) { Debug.LogWarning("EGADS!!!"); } }
  4. gord0

    Runtime assistance

    Turns out, due to unknown sorcery, that the first 6 values in msh.triangles were being removed. So then I manually replaced them and the face reappeared, but was removed again any time I changed anything in the geometry. So I just manually made a new face and appended it to the mesh and set it's vertices to be the same as the missing face. This fix stuck, so that's that I guess.
  5. gord0

    Runtime assistance

    No, it would be wonderful if there was though lol
  6. gord0

    Runtime assistance

    Will let you know on Monday.
  7. gord0

    Runtime assistance

    Well of course because people love changing things, the whole input style has changed. The want to be able to just place nodes and have the "corridors" just connect the nodes. Which is fine, but it also means a lot of how I was doing things has changed. Have you ever had a face just disappear after an extrusion? In this case, not even the face I had extruded.
  8. gord0

    Runtime assistance

    I think I'm golden now. Thanks for all your help! : ]
  9. gord0

    Runtime assistance

    One more thing. When using AppendFace() is there a way to make the face physically stay where it was before appending. It seems to always go to the origin of the pbo that I attach it to. I then have to move the vertices manually with offsets depending where I intended to attach it. Which was fine until I realized that if the pbo is rotated at all it throws everything out of whack.
  10. gord0

    Runtime assistance

    It is working! I still have to make some adjustments so that it works on all axis but 4 of the 6 are working. I'll let you know if I have any more questions/troubles. : ]
  11. gord0

    Runtime assistance

    Cheers, will try this out in the morning. : ]
  12. gord0

    Runtime assistance

    protected void DrawCustomPlane() { if (Input.GetMouseButtonUp(0)) //they let go of the button, lets get outta here { _customExtruding = false; _meoc.RelinquishNonAxisMovement = false; _specifiedFaceSelect = true; CommenceModifications(); return; } if (!Input.GetKey(KeyCode.LeftControl)) { return; } //they're not holding left control, so let's chill if (_customExtruderPlane==null) //if our plane is null { _ray = _cam.ScreenPointToRay(Input.mousePosition); //let's fire a ray to see if we can fix that if (Physics.Raycast(_ray, out _hit, Mathf.Infinity, _lm)) //if we hit something { if (_hit.collider.gameObject.GetComponent<pb_Object>()==null) { return; } //forget it, not pb object Vector3[] verts = new Vector3[6] //we'll start with all the vertices zero'd out { Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero }; int[] indices = new int[verts.Length]; //define our indices for (int iVert=0; iVert<verts.Length; iVert++) { indices[iVert] = iVert; } //.. //now we can make the plane _customExtruderPlane = pb_Object.CreateInstanceWithVerticesFaces(verts, new pb_Face[] { new pb_Face(indices) }); _customExtruderPlane.SetFaceMaterial(_customExtruderPlane.faces, PreviewMaterial); _customExtruderPlane.ToMesh(); _customExtruderPlane.Refresh(); //move it just a little in front of whatever the ray hit so we can see it proper _customExtruderPlane.gameObject.transform.position = _hit.point + (_hit.normal * 0.1f); _customExtruderPlane.gameObject.transform.forward = _hit.normal; } } if (_customExtruderPlane==null) { return; } //i guess we missed else //lets move our vertices according to mouse movement { /* verts[0] -- upper left corner verts[0] -- upper left corner verts[1,3] -- lower left corner verts[2,3] -- lower left corner verts[2,5] -- upper right corner verts[1,4] -- upper right corner verts[4] -- lower right corner verts[5] -- lower righ corner 0 --- 2,5 0 --- 1,4 | | | | | | | | | | | | 1,3 --- 4 2,3 --- 5 */ _ray = _cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(_ray, out _hit, Mathf.Infinity, _lm)) //fire ray from the mouse { if (_hit.collider.gameObject.GetComponent<pb_Object>() == null) { return; } //forget it, not pb object _customPlaneMarker.position = _hit.point; //place our marker at the hit point _customPlaneMarker.parent = _customExtruderPlane.gameObject.transform; //child it to the plane Vector3[] verts = _customExtruderPlane.vertices; //grab verts from the plane verts[4] = _customPlaneMarker.localPosition; //place lower right corner at marker verts[4].z = verts[0].z; //copy z from upper right corner to lower left (remember plane is a little in front of hit) verts[2].x = verts[4].x; //make rest of verts form the rest of the rectangle based on 0 and 4 verts[5].x = verts[4].x; //.. verts[1].y = verts[4].y; //.. verts[3].y = verts[4].y; //.. //same as above but clockwise winding order //verts[5] = _customPlaneMarker.localPosition; //verts[5].z = verts[0].z; //verts[1].x = verts[5].x; //verts[4].x = verts[5].x; //verts[2].y = verts[5].y; //verts[3].y = verts[5].y; _customExtruderPlane.SetVertices(verts); //update the plane's vertices with our changes _customExtruderPlane.ToMesh(); //apply changes _customExtruderPlane.Refresh(); //.. _customPlaneMarker.parent = null; //unchild marker from plane } } } This is the code that allows the user to draw their own plane.
  13. gord0

    Runtime assistance

    I was hopeful but...same issue. I also tried VertexNormal just see what would happen and it's also the same. All three methods seem to turn out the same in this scenario.
  14. gord0

    Runtime assistance

    Ahhhh, I didn't even think to look there since I had been using that line as is for so long. Will give it a go in the morning!
  15. gord0

    Runtime assistance

    Alright I'm getting better results using a different approach. The new problem is, what is this diagonal plain on the inside of the "corridor"? I've used a 2 sided transparent material so you can see (it seems your attachment system is broken so I'm using external links): https://pasteboard.co/HfQ4Xja.png https://pasteboard.co/HfQ5Ahq.png This is how I'm achieving it: protected void CommenceModifications() { Vector3 facePos = FaceCenter(_currentSelection.Face, _currentSelection.PB); //get the center point of selected face Vector3 toWidget = (_widget.localPosition - facePos).normalized; //get direction from face center to widget bool behind = Mathf.Approximately(Vector3.Dot(toWidget, _localNormal), -1.0f); //determine if widget is in front or behind face if (_canExtrude) //may we extrude? { //make it so _currentSelection.PB.Extrude(new pb_Face[] { _currentSelection.Face }, ExtrudeMethod.IndividualFaces, !_specifiedFaceSelect ? Mathf.Epsilon : 0.0f); //epsilon if not custom face, otherwise 0 _currentSelection.PB.ToMesh(); _currentSelection.PB.Refresh(); if (_specifiedFaceSelect) //is this a user defined face? { //move their plane back to be flush with the actual face they want to extrude from _customExtruderPlane.gameObject.transform.position -= _customExtruderPlane.gameObject.transform.forward * 0.1f; Transform t = _customExtruderPlane.gameObject.transform; if (Mathf.Approximately(t.forward.z, 1.0f) || Mathf.Approximately(t.forward.x, 1.0f) || Mathf.Approximately(t.forward.x, -1.0f) || Mathf.Approximately(t.forward.y, 1.0f) || Mathf.Approximately(t.forward.y, -1.0f)) { _customExtruderPlane.faces[0].ReverseIndices(); } t.parent = _currentSelection.PB.gameObject.transform; Vector3[] offSetVerts = _customExtruderPlane.vertices; float xDist = Vector3.Distance(offSetVerts[0], offSetVerts[2]); float yDist = Vector3.Distance(offSetVerts[0], offSetVerts[1]); for (int iVert=0; iVert<offSetVerts.Length; iVert++) { offSetVerts[iVert] += t.localPosition; if (Mathf.Approximately(t.forward.z, -1.0f)) { offSetVerts[iVert].x += xDist; } /*if (iVert==5) //touching: 0, 2, 5 { //not touching: 1, 3, 4 Transform go = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform; go.parent = _currentSelection.PB.gameObject.transform; go.localPosition = offSetVerts[iVert]; }*/ if ((iVert!=0 && iVert!=1 && iVert!=3) && (Mathf.Approximately(t.forward.x, 1.0f) || Mathf.Approximately(t.forward.x, -1.0f))) { offSetVerts[iVert].x = offSetVerts[0].x; offSetVerts[iVert].z += xDist * (Mathf.Approximately(t.forward.x, -1.0f) ? -1.0f : 1.0f); } if ((iVert!=0 && iVert!=2 && iVert!=5) && (Mathf.Approximately(t.forward.y, 1.0f) ||Mathf.Approximately(t.forward.y, -1.0f))) { offSetVerts[iVert].y = offSetVerts[0].y; offSetVerts[iVert].z += yDist * (Mathf.Approximately(t.forward.y, 1.0f) ? -1.0f : 1.0f); } } t.parent = null; pb_Face pbf=_currentSelection.PB.AppendFace(offSetVerts, new Color[1] { Color.white }, _customExtruderPlane.uv, _customExtruderPlane.faces[0]); _manualFaceSelect = true; _manualFaceSelectPBO = _currentSelection.PB; _manualFaceSelectFace = pbf; /*Debug.LogWarning("_customExtruderPlane.gameObject.transform.forward: " + _customExtruderPlane.gameObject.transform.forward);*/ if (_customExtruderPlane != null) { Destroy(_customExtruderPlane.gameObject); } } _currentSelection.PB.ToMesh(); //apply changes _currentSelection.PB.Refresh(); //.. _canExtrude = false; //no more extuding for now } if (!_specifiedFaceSelect) //if this was a not a user defined face, translate the verts based on widget pos { _currentSelection.PB.TranslateVertices( _currentSelection.Face.distinctIndices, _localNormal.normalized * (Vector3.Distance(_widget.localPosition, facePos)) * (behind ? -1.0f : 1.0f) ); _currentSelection.PB.ToMesh(); _currentSelection.PB.Refresh(); } else //otherwise { _specifiedFaceSelect = false; //we're done with the user defined face _destroyPreview = true; //destroy the preview plane _waitAFrame = true; //we should probably wait a frame before we do anything else } // Refresh will update the Collision mesh volume, face UVs as applicatble, and normal information. _currentSelection.PB.Refresh(); // this creates the selected face preview RefreshSelectedFacePreview(); Have you seen this kind of problem before?
  16. gord0

    Runtime assistance

    How are these pb_Object methods used?: AppendFace, Connect, and MergeFaces Could they be of use?
  17. gord0

    Runtime assistance

    I've added a couple more ToMesh() and Refesh()es so that each time I Extrude(), SetVertices(), ReverseIndices(), and TranslateVertices() I call those two methods immediately after. Seems to have been redundant though because my result is the same as before protected void CommenceModifications() { Vector3 facePos = FaceCenter(_currentSelection.Face, _currentSelection.PB); //get the center point of selected face Vector3 toWidget = (_widget.localPosition - facePos).normalized; //get direction from face center to widget bool behind = Mathf.Approximately(Vector3.Dot(toWidget, _localNormal), -1.0f); //determine if widget is in front or behind face if (_canExtrude) //may we extrude? { //make it so _currentSelection.PB.Extrude(new pb_Face[] { _currentSelection.Face }, ExtrudeMethod.IndividualFaces, !_specifiedFaceSelect ? Mathf.Epsilon : 0.0f); //epsilon if not custom face, otherwise 0 _currentSelection.PB.ToMesh(); _currentSelection.PB.Refresh(); if (_specifiedFaceSelect) //is this a user defined face? { //move their plane back to be flush with the actual face they want to extrude from _customExtruderPlane.gameObject.transform.position -= _customExtruderPlane.gameObject.transform.forward * 0.1f; //extrude again with 0 distance _currentSelection.PB.Extrude(new pb_Face[] { _currentSelection.Face }, ExtrudeMethod.IndividualFaces, 0.0f); _currentSelection.PB.ToMesh(); _currentSelection.PB.Refresh(); Vector3[] verts = _currentSelection.PB.vertices; //grab all our verts int[] indices = _currentSelection.Face.indices /*distinctIndices*/; //grab the indices of the current face Vector3[] toVerts = _customExtruderPlane.vertices; //grab the verts of the user defined plane //place markers to represent the postions of the user defined plane verts for (int iMarker = 0; iMarker < _faceScalerMarkers.Length; iMarker++) { //child marker to user defined plane _faceScalerMarkers[iMarker].parent = _customExtruderPlane.gameObject.transform; //place marker at user defined plane's iMarker vertice position _faceScalerMarkers[iMarker].localPosition = toVerts[iMarker]; _faceScalerMarkers[iMarker].parent = transform; //child marker to us } //set current face vertices to the position of the closest marker (to retain wind order) for (int iVert = 0; iVert < indices.Length; iVert++) { verts[indices[iVert]] = ClosestScalerMarkerPos(verts[indices[iVert]]); } _currentSelection.PB.SetVertices(verts); //apply new vertice positions _currentSelection.PB.ToMesh(); _currentSelection.PB.Refresh(); _currentSelection.Face.ReverseIndices(); //reverse the indices so we can see the face (for some reason backwards) _currentSelection.PB.ToMesh(); _currentSelection.PB.Refresh(); Destroy(_customExtruderPlane.gameObject); //destroy user defined plane for (int iMarker = 0; iMarker < _faceScalerMarkers.Length; iMarker++) //unchild markers { _faceScalerMarkers[iMarker].parent = null; } } _currentSelection.PB.ToMesh(); //apply changes _currentSelection.PB.Refresh(); //.. _canExtrude = false; //no more extuding for now } if (!_specifiedFaceSelect) //if this was a not a user defined face, translate the verts based on widget pos { _currentSelection.PB.TranslateVertices( _currentSelection.Face.distinctIndices, _localNormal.normalized * (Vector3.Distance(_widget.localPosition, facePos)) * (behind ? -1.0f : 1.0f) ); _currentSelection.PB.ToMesh(); _currentSelection.PB.Refresh(); } else //otherwise { _specifiedFaceSelect = false; //we're done with the user defined face _destroyPreview = true; //destroy the preview plane _waitAFrame = true; //we should probably wait a frame before we do anything else } // Refresh will update the Collision mesh volume, face UVs as applicatble, and normal information. _currentSelection.PB.Refresh(); // this creates the selected face preview RefreshSelectedFacePreview(); }
  18. gord0

    Runtime assistance

    Alright, so is this what's going on with the pipes? If so, is this not just an automated version of the example that comes with probuilder that I started with?
  19. gord0

    Runtime assistance

    Cheers, that sorted that out. Looking at code now.
  20. gord0

    Runtime assistance

    Sorry, I was off work longer than I knew I was going to be. Anyway, I've got that project opened up. It didn't have the probuilder stuff with it so I imported it. After that I now have " The type or namespace name `Math' does not exist in the namespace `ProBuilder2'. Are you missing an assembly reference?" coming from Pipe.cs on line 5: using ProBuilder2.Math; If I comment that out, the next problem is "The name `pb_Shape_Generator' does not exist in the current context" coming from PipeSpawner.cs at line 238: pb_Object pb = pb_Shape_Generator.CubeGenerator(Vector3.one * pipeSize); I imagine this is due to deprecation? How might I sort this out?
  21. gord0

    Runtime assistance

    Cool. I'll check that out when I'm back at work tomorrow. : ]
  22. gord0

    Runtime assistance

    I'm not at work today, but the problem is most likely in CommenceModifications(). The reason I asked about a merging functionality is that it could probably take a huge chunk of the work out of my hands. If I were to place a plane on a face of a cube, said plane is smaller dimensions than the face, and merge would that plane become a face on the cube?
  23. gord0

    Runtime assistance

    I'm super stuck. Don't know how to sort this out. Does probuilder have the ability to "merge" meshes? So I could just merge the user drawn plane (pb_Object) into the target object (pb_Object) so that I don't have to do all this manual jiggering around? Or do you know another way to achieve the desired result?
  24. gord0

    Runtime assistance

    Alright, so nothing in there really helps (that I can tell). So right now I've got it doing almost what I want but I'm experiencing geometry glitches. I've stripped out as much of my project as I could while keeping code in question functioning and placed it in a zip which I've attached to this post (CorridorTest3.7z). The code that's doing the work in question is in PBCorridor.cs . The scene is PBCorridorTest3 . You'll need to be quite careful as I've only put in super basic functionality and it's easy to break things. First you'll want to drag out a corridor: It should look like this, don't click anywhere just yet: Now move the cursor to somewhere on the face that is facing the camera. Hold left control and left click and drag the mouse to draw a rectangle on the face (might want to have left control down before the left click): When you let go, the rectangle will disappear (at least for now it does, later I'll have it auto-select). Click roughly near the center of the rectangle you drew. A single arrow should appear with your rectangle highlighted: Now you'll want to move the camera to see better (camera controls are same as scene view (right click--rotate, middle mouse down--pan/strafe, scroll wheel--zoom). Then left click on arrow and pull it: Now you're thinking, so you've got it. What's the problem? Well if you try this on any other face (including a second time on the face you already used) the geometry gets messed up causing faces to no longer be visible. Also, in the screen shot above, it actually has one tiny problem too (the face on the back side that is not in view of the camera is invisible). This is the point where I no longer know what to do. Any help would be much appreciated. : ]
  25. gord0

    Runtime assistance

    Just got back in from the weekend. I see you've added more stuff to the repo since I last visited a week or two ago. I've made some progress on my side but still stuck with some things. I'll take a look on the repo and report back later.
×