Jump to content

gord0

Members
  • Content count

    36
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by gord0

  1. gord0

    Runtime assistance

    So, how does one go about scaling a pb_Face via code?
  2. gord0

    Runtime assistance

    Figured it out, it needs 6 vertices and I was giving it 4. It's creating the plane now, but I need to sort out placement. It's not appearing where it should be. I figure it's a local vs world thing.
  3. gord0

    Runtime assistance

    I've tracked down your git repo, but even in that the code I need to look at is inside a .dll . : (
  4. gord0

    Runtime assistance

    Alright, I've hit a wall that I can't see the other side of. The following is the code I'm using to allow the user to draw a plane on a pbObject. It gets called every frame if the user is pressing the right inputs. protected void DrawCustomPlane() { if (Input.GetMouseButtonUp(0)) //they let go of the button, lets get outta here { _customExtruding = false; 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[4] //we'll start our 4 vertices at the hit point { new Vector3(_hit.point.x, _hit.point.y, _hit.point.z), new Vector3(_hit.point.x, _hit.point.y, _hit.point.z), new Vector3(_hit.point.x, _hit.point.y, _hit.point.z), new Vector3(_hit.point.x, _hit.point.y, _hit.point.z) }; 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 _customExtruderPlane.gameObject.transform.position += _hit.normal * 0.1f; } } if (_customExtruderPlane==null) { return; } //i guess we missed else //lets move our vertices according to mouse movement { /*i'm assuming the following is what each vertice is, i could very well be wrong, we'll find out soon enough verts[0] -- upper left corner verts[1] -- upper right corner verts[2] -- lower right corner verts[3] -- lower left corner */ Vector3[] verts = _customExtruderPlane.vertices; verts[1].x += Input.GetAxis("Mouse X") * CustomExtrudeDragSpeed * Time.deltaTime; verts[2].x = verts[1].x; verts[2].y += Input.GetAxis("Mouse Y") * CustomExtrudeDragSpeed * Time.deltaTime; verts[3].y = verts[2].y; _customExtruderPlane.SetVertices(verts); _customExtruderPlane.ToMesh(); _customExtruderPlane.Refresh(); } } I get an index out of range error at this line: _customExtruderPlane = pb_Object.CreateInstanceWithVerticesFaces(verts, new pb_Face[] { new pb_Face(indices) }); I can't dig into the PB scripts to see why. Would you be able to shine some light? Cheers
  5. gord0

    Runtime assistance

    Ahhh. Nice. So what I'm going to do now is work on a way for the user to just draw the preview plane on a face (perhaps by holding a kb key and dragging the mouse). Then I can do as you've explained above. Instead of sizing the preview plane to match the face, I'll scale/position the face to match the preview plane. : ]
  6. gord0

    Runtime assistance

    So which overload of Extrude() would work? Would we not need to add vertices to the face to create the smaller face within the original face? I made another diagram using regular cubes to illustrate what I'm trying to do. Where the red plane is sized and placed by the user.
  7. gord0

    Runtime assistance

    In the picture below. Let the blue represent a face. Let the red represent the preview plane. Instead of having it sized to match the face, have it sized by the user in some way so they can just extrude whatever size of rectangle from wherever they place the preview plane. Programmatically we would be adding the necessary geometry for it to work. Is that doable with probuilder?
  8. gord0

    Runtime assistance

    W0000! Before you had replied I had sorted out the bool thing so that it only does it once per drag, but I didn't know that ToMesh() was needed. I take it that method is like a "commit changes" sort of thing? I went a little nuts testing but it works : ] Just one more thing though. Is there a way I can do this with my own rectangle (just like the preview plane) that isn't sized from the values of the face. I just size it myself and then use it like a cookie cutter to extrude with? As it is now, you kind of have to play a bit to get a face to be the right size to make a "corridor". Also the end user isn't going to have any comprehension of what's under the hood.
  9. gord0

    Runtime assistance

    That sorted out the syntax error, but I think I need to change when things are happening because I'm creating waaaay too much geometry. Also I think there's a texturing issue. In game view it appears as though I'm just pulling the face right off the cube but scene view shows that I am indeed doing what I wanted to, but way too many times. Here's the bit of code where it's happening: if (_preview!=null && Input.GetMouseButton(0)) { UpdateNodeRestrictions(); //check if behind face, if so use a nagative multiplier below Vector3 facePos = FaceCenter(_currentSelection.Face, _currentSelection.PB); Vector3 toWidget = (_widget.localPosition - facePos).normalized; bool behind = Mathf.Approximately(Vector3.Dot(toWidget, _localNormal), -1.0f); _currentSelection.PB.Extrude( new pb_Face[] { _currentSelection.Face }, ExtrudeMethod.IndividualFaces, Mathf.Epsilon); _currentSelection.PB.TranslateVertices( _currentSelection.Face.distinctIndices, _localNormal.normalized * (Vector3.Distance(_widget.localPosition, facePos)) * (behind ? -1.0f : 1.0f) ); // Refresh will update the Collision mesh volume, face UVs as applicatble, and normal information. _currentSelection.PB.Refresh(); // this create the selected face preview RefreshSelectedFacePreview(); }
  10. gord0

    Runtime assistance

    There's no .Extrude method for pb_Object. At least not a public one.
  11. gord0

    Runtime assistance

    Cheers. It's a snow day for me so I won't be able to try this until tomorrow...unless that's a snow day too. I'll let you know how it works out. : ]
×