Place text on my mesh or to the screen where my mesh is located...

Blitz3D Forums/Blitz3D Programming/Place text on my mesh or to the screen where my mesh is located...

hollifd(Posted March) [#1]
I am looking for some code that will allow me to place some text on my meshes or write the text to the screen wherever my meshes may be located. Can anyone provide any code?

I have a TYPE that contains the TEXT that I need to place on the meshes or on the screen. Here is the TYPE definition...

  Type BendData
  	Field SEQ%      ;Bend sequence number
	Field Entity    ;Mesh created using CreateCube() and scaled to the size I need
	Field Name$     ;Mesh name
	Field MyX#      ;Mesh X
	Field MyY#      ;Mesh Y
	Field MyZ#      ;Mesh Z
	Field MyPitch#  ;MeshPitch
	Field MyYaw#    ;MeshYaw
	Field MyRoll#   ;MeshRoll

  End Type


When I create or modify these meshes, I want to put the Name$ Field on the mesh or write the Name$ Field to the screen. Is this possible and can anyone provide some code for me?

Thanks,
David


grable(Posted March) [#2]
CameraProject is what your looking for, it projects a 3D point in space to a 2D point on screen. Then use Text as usual.


hollifd(Posted March) [#3]
I can get the text to display on the screen but it will not move as I move things around on the screen. Can you see what I am doing wrong?

Function DisplayBendData()

  camera2=CreateCamera()
  PositionEntity camera2, 0, 0, -200
  RotateEntity camera2, 0, 0, 0

	Color 255, 0, 0
	Count = 12
	For b.BendData = Each BendData
		;Let's print the bend seq on the bend lines...
		CameraProject(camera2, EntityX#(b\entity), EntityY#(b\entity), EntityZ#(b\entity))
		Text ProjectedX#(), ProjectedY#(), b\Name$
		
	Next
	
	FreeEntity camera2
	
End Function



grable(Posted March) [#4]
The camera has to be the render target or the points it produces makes no sense, so creating a temp one wont work.


hollifd(Posted March) [#5]
When trying to access my normal camera within the function, I was getting "entity does not exist" error. I thought creating a camera within the function would work. What do I need to do to access the normal camera from within my function?


hollifd(Posted March) [#6]
Got it figured out. I needed to add the Global = true option to the b\entity

I placed my code in the main loop. Is there a way it can be called within a function without getting the "entity does not exist" error?

...and Thanks grable for pointing me to the code to accomplish all of this.
David


Flanker(Posted March) [#7]
You almost answered yourself ^^

You must make your main camera as Global so it can be accessed from anywere in your code, so this will give something like this :

; your main camera as Global
Global camera = CreateCamera()

; type
; loop
; etc...
;
;


Function DisplayBendData()

	Color 255, 0, 0

	For b.BendData = Each BendData
		;Let's print the bend seq on the bend lines...
		CameraProject(camera, EntityX#(b\entity), EntityY#(b\entity), EntityZ#(b\entity))
		Text ProjectedX#(), ProjectedY#(), b\Name$
	Next
		
End Function



hollifd(Posted March) [#8]
OK. Great. I didn't know you could make a global camera. Sorry, I am not really a game programmer. Just trying to use Blitz in a creative way to help improve the processes in our sheet metal shop.

Thanks,
David


K(Posted April) [#9]
Any value can be a camera and any value can be Global, remember,
"Camera=CreateCamera()" just returns a reference number into the Camera 'container'.
So if we then say "A=Camera", we can then use "A" anywhere instead of saying "Camera"

These principles allows one to pass the Local value of Camera in like so:
Camera=CreateCamera()
...
...
DisplayBendData(Camera)
...
...
Function DisplayBendData(Camera)
etc.
etc.
End function





hollifd(Posted April) [#10]
Thanks guys! This feature is working great for me now.


RemiD(Posted April) [#11]
if you want to display the texts centered horizontally, you can use the command stringwidth() to calculate the width of the string, then to calculate the wanted pixel x coordinate
px% = projectedx()-stringwidth(linestr)/2


You can do a similar thing stringheight() to calculate the wanted pixel y coordinate
py% = projectedy()-stringheight(linestr)
;or
py% = projectedy()+stringheight(linestr)

then
Text(px,py,linestr,false,false,false)


note that cameraproject will use the entity origine to calculate the corresponding pixel x,y position, so if you want to display the text on a specific part of the mesh, (for example above a mesh) you can create a pivot at the position that you want related to the mesh, and set it as a child of mesh (so that it will turn/move with it), and use this pivot with cameraproject...


hollifd(Posted April) [#12]
My oddly large and growing head will barely fit thru the head opening in my tee shirts due to all of this knowledge you guys are passing along.

This project I have been working on is really coming along nicely and I have had a lot of fun doing it.

I wish someone would figure out how to solve my "bending and un-bending" sheet metal parts problem in my Simulating Sheet Metal Bending posts. Then, my project would really be impressive and 10X more useful to us.


Kryzon has been a huge help in the past. Perhaps if he is finding this post, he might have a go at solving how to simulate bending and unbending sheet metal.

Thanks!


Kryzon(Posted April) [#13]
Hi David, I don't have much time right now to write code.
Your thread on bending has some possible ways to do that, but they are meant for working with 3D meshes:
http://www.blitzbasic.com/Community/posts.php?topic=107752

It's not clear if you're working with the 2D commands (DrawLine, DrawImage etc.) or 3D commands (MoveEntity, RenderWorld, etc.).

If you're using 3D meshes, the method that Floyd suggested is probably the simplest:
http://www.blitzbasic.com/Community/posts.php?topic=107752#1336236

Parent a hidden copy of your mesh to a pivot that is already placed and oriented at the location of the bend, rotate that pivot so its child mesh rotates along, take the coordinates of the relevant vertices from the rotated hidden copy and transfer those coordinates to the original unrotated mesh. The index of vertices is the same.

If you need to specify which vertices are to be bended then you need to write some selection logic, that is, code that allows you to use the mouse to select components of your mesh (vertices, edges etc.), so you're able to select vertices and specify "I want these vertices to be bended by this pivot".
This is mostly related to problem-solving, like "checking if the mouse is on top of a vertex on the screen", "how to add or remove something from the current selection", "rectangle-selecting multiple elements at the same time", for example.


hollifd(Posted April) [#14]
Yes. I am working with 3D meshes now. I am unfolding the 3D part in our CAD system, then exporting a .STL file from our CAD system then converting it to a .3DS file and then importing into Blitz.

The older version you helped me with earlier was working with 2D DXF files. I have since rewritten the tool to work in 3D and it is much better and simpler now. I plan to keep using it to work with the completely flat part until someone comes up with a solution to bend the flat parts.

The solution you suggest is way above my head. I am a beginner at this stuff and am amazed at what I have created so far but I doubt I would ever be able to implement what you are suggesting.

My tool is helping us as-is. I can wait to see if anyone wants to tackle the problem. If not, then that is OK too.

I do appreciate everyone's help with this project.

David


RemiD(Posted April) [#15]

I am a beginner at this stuff and am amazed at what I have created so far but I doubt I would ever be able to implement what you are suggesting.


hence the usefulness to hire somebody to help you achieve what you won't manage to do alone... (you can't be good at everything, this is normal)