#Render 3d Box

103 messages · Page 1 of 1 (latest)

nimble kiln
#

How do I render a 3d box at x, y, z with width, height and colored r, g, b, a?

ruby steppe
#

same question here :D

forest cypress
#

This question has surely been answered previously. One option is to use WoldRenderer.drawBox

nimble kiln
nimble kiln
forest cypress
#

cyl?

flat turret
#

cylinder most likely

forest cypress
#

Impossible, in minecraft?!?!

flat turret
#

with gl its not

forest cypress
#

That was a joke :8

flat turret
nimble kiln
nimble kiln
flat turret
forest cypress
nimble kiln
#

wait what

#

i thought tesselator was for

#

like

#

hud elements

#

?

#

can i have an example

#

of like a box or something

forest cypress
#

Doesnt WorlderRenderer.drawbox use Tesselator

nimble kiln
#

not sure

forest cypress
#
public static void drawBox(Vector3d cam, VertexConsumer vertexConsumer, Box box, float red, float green, float blue, float alpha) {
        float minX = (float) (box.minX - cam.x);
        float minY = (float) (box.minY - cam.y);
        float minZ = (float) (box.minZ - cam.z);
        float maxX = (float) (box.maxX - cam.x);
        float maxY = (float) (box.maxY - cam.y);
        float maxZ = (float) (box.maxZ - cam.z);
        ...
    }
#
        vertexConsumer.vertex(minX, minY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, minY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, minY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, maxY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, minY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, minY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, minY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, maxY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, maxY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, maxY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, maxY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, maxY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, maxY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, minY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, minY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, minY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, minY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, minY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(minX, maxY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, maxY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, minY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, maxY, maxZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, maxY, minZ).color(red, green, blue, alpha);
        vertexConsumer.vertex(maxX, maxY, maxZ).color(red, green, blue, alpha);
#

Didn't fit in one message

nimble kiln
#

what's that from

#

drawBox?

forest cypress
#

Yea more or less

nimble kiln
#

what's cam

#

how do I access it

forest cypress
#

You can call that function like so:

BufferBuilder vertices = Tessellator.getInstance().begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
        RenderSystem.setShader(GameRenderer::getPositionColorProgram);

drawBox(cam, vertices, box, 0.6f, 1f, 0.5f, 1f);
        BufferRenderer.drawWithGlobalProgram(vertices.end());
nimble kiln
#

i see

#

okay

#

how do I access cam though?

forest cypress
#

It seems that 1.21.3 doesnt have WorldRenderer#drawBox anymore

nimble kiln
#

so it's fine

#

how do I get

#

cam

#

is that just player eyes or something

forest cypress
#

Yeah its the camera position

#

MinecraftClient.getInstance().getCameraEntity().getCameraPosVec(tickDelta)

nimble kiln
#

ok

forest cypress
#

But you get it passed as a parameter in most rendering functions

nimble kiln
#

couldnt I put vertex consumer and camera in the rendering file

forest cypress
#

Not sure what you mean by that

nimble kiln
#

like

#

instead of passing it into the function

#

why dont I just

#

not pass it in

#

and have it in the function

forest cypress
#

Yes you can do that

nimble kiln
#

okay

forest cypress
#

But if you want to draw a lot of boxes this method isn't very efficent

nimble kiln
#

how do I get tick delta

#

what should I put

#

since I dont have tick delta

#

in my render function

forest cypress
#

Well you should

#

tickDelta is a bad name btw. Think of it as "tickProgress"

nimble kiln
#

well I know what it is but I dont have it anywhere

#

how do I get it

forest cypress
#

Somewhere from GameRenderer probably

#

You can use 0 if its just for debugging

nimble kiln
#

ok

nimble kiln
forest cypress
#

Just change the parameters?

nimble kiln
#

yeah, but for things like box.maxX or whatever it wouldn't work

forest cypress
#

maxX is just x + width

nimble kiln
#

oh

#

okay

forest cypress
#

Well unless you want x,y,z to specify the center

#

Then minX is x - width/2 and maxX is x + width/2

nimble kiln
#

ThreeDimRenderer.drawBox(5, 5, 5, 2, 2, 2, 255, 255, 255, 255);

#

doesn't seem to draw anything

forest cypress
#

You're calling it every frame?

nimble kiln
#

yes

forest cypress
#

Make a void world and go to 0,0,0, see if you see anything

nimble kiln
#

okay nevermind I had to make it bigger

#

but uh

#

its not really..

#

boxing

#

it's just a two dim square on my screen and sometimes moves when i turn my camera

forest cypress
#

You're probably drawing at a time which isn't suited for 3d rendering

#

The RenderSystem state must be set up correctly

#

Such as the view and projection matrix

#

It's simplest to just move your draw call elsewhere

#

For example one of the fapi render callbacks

nimble kiln
#

uhhh

#

that's where I activate it

nimble kiln
#

OH

#

wait

#

onFrame is called

#

in inGameHud

#

.render