Jump to content

Draw 3D line with "repeated" (?) texture


Przemcio

Recommended Posts

Hello, I'm trying to achieve something like this:


SMv7hZe.png


But it's an object and I need a 3D line looking similar to that. Got no clue how to draw a 3D line without stretching the texture (or if it's even possible, but I don't think it's not). My latest attempt code and result:

 

misc.chainTexture = dxCreateTexture(download.getAssetId("asset/texture/Chain.dds"), "dxt5", false, "mirror")

 

-- Lifts chains
        for i = 1, #misc.liftData
        do
            if(isElementStreamedIn(misc.liftData[i]["cranesObject"]) == true or isElementStreamedIn(misc.liftData[i]["liftObject"]) == true)
            then
                local cranesVerticalOffset = 2.9499983787537
                local liftHeight = 2.7499985694885
                local _, _, liftZ = getElementPosition(misc.liftData[i]["liftObject"])
	                local x, y, z = utils.getPositionFromElementOffset(misc.liftData[i]["cranesObject"], -1.2499998807907, -0.049999993294477, cranesVerticalOffset)
                dxDrawMaterialSectionLine3D(x, y, z, x, y, liftZ + liftHeight, 0, 0, 1, 1, misc.chainTexture, 0.1)
	                x, y, z = utils.getPositionFromElementOffset(misc.liftData[i]["cranesObject"], 1.1499999761581, -0.049999993294477, cranesVerticalOffset)
                -- second chain will go there, eventually
            end
        end

Texture:


3TWF0gW.png

Result:


bIS7T6U.png

xD

Couldn't find any script doing anything similar, don't know even where to start - if I messed up texture creation, or dxDraw function, or both (most likely the last). Tried dxDrawMaterialLine3D either - similar effect, a little better, though I'm not sure what I really did with the dxDrawMaterialSectionLine3D xD just tried to do anything from example code from documentation.

Thanks!

Edited by Przemcio
Link to comment

To achieve the desired result, you need to calculate the chain length, for example, with getDistanceBetweenPoints3D. In the dxDrawMaterialSectionLine3D function, the U Section Size needs to be the same as the texture width (16), and the V Section Size needs to be the texture height (64). However, this alone does not yield the desired results. You also need to multiply the V Section Size with the calculated chain length, divide by the texture aspect ratio (in your case, 64/16) and finally, multiply by the line thickness ("width"). I recommend to create a helper drawing function for this, with arguments: start position, end position, chain thickness.

  • Thanks 1
Link to comment

Works like a charm, thank you, problem solved! But I think it should be ultimately divided by line thickness instead of multiplied - at least that's how I got these calculations right. If anyone wondering:

 

dxDrawMaterialSectionLine3D(x, y, z, x, y, liftZ + liftHeight, 0, 0, 16, ((64 * ((z - liftZ) + liftHeight)) / (64 / 16)) / 0.1, misc.chainTexture, 0.1)

 

0fyFnkJ.jpg

Edited by Przemcio
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...