Skip to content

Conversation

@deltamolfar
Copy link
Contributor

@deltamolfar deltamolfar commented Oct 10, 2025

Adds gmod_wire_customprop entity into the wiremod, an entity with custom physics mesh, which isn't spawnable by itself but by the E2/duplicator, and maybe in future, by something else.

It's essentially starfall's custom mesh prop with a few tweaks:

  • 16-bit precision vertices positions instead of sf's 32.
  • Lower default amount of vertices per convex. As the performance bottleneck of the custom prop is client's ENT:BuildPhysics function, and self:PhysicsInitMultiConvex function in particular which seemingly takes more resources exponentially with the rise of verticies amount, I've decided (and tested by stressing/abusing different limits) to lower the verticies limit and raise convexes limit instead.
  • Added convar-controller limit to these props (default is 10), as without it - it's possible to abuse client's performance horribly
  • Expression2 functions to spawn said props (+ dynamic cost of creation)

Example of usage: (again, taken mostly from SF's example, not trying to credit myself for other's stuff)

propSpawnUndo(0)

const Fidelity = 15
const X = 150
const Y = 100
const Z = 50

const Convexes = table(
    # cube
    array(
        vec(0, 0, 0), vec(X, 0, 0), vec(X, Y, 0), vec(0, Y, 0),
        vec(0, 0, Z), vec(X, 0, Z), vec(X, Y, Z), vec(0, Y, Z)
    ),
    # cylinder
    array(
        # cone
        vec(X/2, Y/2, Z*3)
    )
)

# cylinder base
for(I = 1, Fidelity) {
    local T = _PI*2 / Fidelity * I
    local Cos = X/2 + cosr(T) * X/4
    local Sin = Y/2 + sinr(T) * Y/4
    
    Convexes[2,array]:pushVector(vec(Cos, Sin, Z))
    Convexes[2,array]:pushVector(vec(Cos, Sin, Z*2))
}

customPropSpawn(Convexes)

for _, vertex in ipairs(convex) do
buffer[#buffer+1] = shared.writeQuantizedFloat16(vertex.x, quantMinX, quantMaxX)
buffer[#buffer+1] = shared.writeQuantizedFloat16(vertex.y, quantMinY, quantMaxY)
buffer[#buffer+1] = shared.writeQuantizedFloat16(vertex.z, quantMinZ, quantMaxZ)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use table.insert or at least cache length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants