Dylancyclone / VMF2OBJ

Convert source-engine VMF files into OBJ files with materials (including brushes, displacements, entities, and models)
MIT License
109 stars 6 forks source link

Support CS:GO's prop scaling feature #9

Closed Dylancyclone closed 4 years ago

TheBlizWiz commented 4 years ago

This would be pretty simple to do. All we would need is to get the value of the static prop scaling (better check per axis), then we can either A. multiply every vertex in the model by that scaling multiplier or B. - and the one I'd recommend - auto-generating a Python script to set the scale of that model to what the value is in Hammer into Blender

TheBlizWiz commented 4 years ago

Did some digging in the Blender API, using the command bpy.ops.transform.resize(value={x, y, z)) inside the Blender console will resize the currently selected object by the specified float value on the x, y, and z axis respectively. Looks like the real question now is figuring out how to first select the object instead of the whole map and then putting that string into the console.

First part seems easy, just select those vertexes in edit mode. But as to which those vertexes are...? :/

Dylancyclone commented 4 years ago

Option A would be pretty straightforward and not too difficult to do, and since it can be done during the conversion process it means we don't have to rely on blender or force people to use blender to get an accurate conversion.

Option B could work, right now each brush is named the same as it's brush number in hammer, and each prop is named by it's model name, but there currently isn't a way to discern between two props with the same model. That could be added though.

I would go with the first option to keep things simple. I'm out of the house right now but can take a closer look when I get back

TheBlizWiz commented 4 years ago

Quick note: Make sure you're using the local origin of that prop; if you use the world origin it's going to break.

If I'm not mistaken, local origin is calculated by averaging the coordinates of each vertex and then declaring that to be 0,0,0. Then each local vertex is (x - x̄, y - ȳ, z -z̄ ). From there just multiply by the scale factor and then convert back to global coordinates by adding the average rather than subtracting it

Dylancyclone commented 4 years ago

This issue was actually a lot easier to fix than I thought! Just had to scale the object before moving it into position For reference, the way props are handled is they are loaded, rotated, and now scaled at (0,0,0), and then moved to the entity's proper location