Possible to view a SENT with DModelPanel?

Hey guys. Pretty simple question here. I may be using this totally wrong, but I’d like to use the vgui element “DModelPanel” ( or something similar ) to draw an SENT inside a dframe. Is this possible, or only with models such as props and playermodels?

edit: My code so far is this:

	local panel = vgui.Create( "DModelPanel", parent )
	panel:SetSize( 200, 200 )
	panel:SetEntity( "my_sent" )

and it errors with this:

[ERROR] lua/includes/util.lua:184: bad key to string index (number expected, got string)
  1. error - [C]:-1
   2. __index - lua/includes/extensions/string.lua:262
    3. IsValid - lua/includes/util.lua:184
     4. unknown - lua/vgui/dmodelpanel.lua:90

edit: I’ve just realized that, obviously, SetEntity requires an entity as it’s arguement. But this is a serversided SENT that I want to show. Would I need to use net messages to send the client an entity?

It’s not possible without making custom DModelPanel. What are you trying to accomplish anyway?

basically I want players to be able to see what the SENT will look like, while within a derma panel, before it’s actually created. The entity uses 3d2d which can change and effect gameplay so it’s rather important they can see what it will look like before they actually see it ingame.

edit: Yup. I tried creating the entity serverside and sending to it the player. It doesn’t error, but simply doesn’t draw anything. Damn.

You’ll have to create a custom DModelPanel.

Why not network the entity and then do :GetModel() then:

[lua]DModelPanel:SetModel( model )[/lua]


Unfortunately that draws ONLY the model, I need to draw the 3d2d vgui as well.

I guess I could just draw the 3d2d stuff as 2D on the derma panel, to give an approximation of what it’ll look like. Kind of lame tho.

@ Robotboy: If I was going to create a custom one, would you have any sgggestions? Or is it one of those things where if you don’t already know how to do it, you probably aren’t going to be able to do it.

Copy and paste the original code and edit it. You want to edit the PANEL:Paint hook with snippets from your ENT:Draw I believe.

Ohh ofcourse. Do you think I could get away with simply overriding the paint function, or would I need to do a bit more of an extensive modification? I’ll start looking into it right now. Will paste code if it works.

What I do for mine, is draw the vehicle and draw all attachments within the vehicle using custom “Helper Functions”. Helper Functions are essentially just small, useful, functions which do a task so you don’t repeat code.

Make a few for rendering the 3d2d stuff and simply add it to the code. If you add attachments to the vehicle, you may have to deal with trig and other math in order to get them to properly rotate. I’d recommend fixing the model in place so it doesn’t move, and creating code to move the camera around. I was toying with that idea a while back when I couldn’t get the math exactly perfect and then I would’ve had to map the offsets to find the center ( even using OBB ); additional offsets in order for the attachments to show just as they would in the world. Another friend of mine recommended the same so I coded it in; and it works beautifully. Move the camera, not the object, and the rest is really easy to do.

If you need help, post your work and we’ll look it over or you can add me on Steam if you want some more details. Good Luck!

Oh well I’m already doing plenty of trig and a little bit of calculus when I’m placing the objects into the world, so that shouldn’t matter. But for sure, I’ll work on it toight and add you tomorrow if I haven’t gotten it working. Thanks both Acecool and RobotBoy, the help is much appreciated.

Here’s a useful function to benchmark how long the calculations are taking… I’d recommend taking a control/base time, and see how much time is added by using trig.:

Base with it rotating, display. Then with additions displaying; then with it rotating. If the rotating code where all the additional trig would be is substantially higher then I’d recommend looking into moving the camera.
// Benchmark
function RunBenchmark( func, … )
local x = os.clock( )
local ret = func( … );
print( string.format( "elapsed time: %.2f
", os.clock( ) - x ) )
return ret;

function name, arg1, arg2, arg3… is the usage. Alternatively, you could just use a function( ) end within func, and wrap the code for rendering.

I’d also recommend using pcall while editing the DModelPanel; it’ll prevent artifacting and having to restart the map/game if you make a typo while auto-refreshing. Any time you make a typo in a render hook, it breaks other parts of the game; sometimes it’s bad enough that you have to close-down your game and relaunch it. pcall prevents that.

All of these are the same:
[lua]// 1
function test( arg1, arg2 )
local i = 0
while i < 1000 do
print( arg1, arg2 );
i = i + 1;
RunBenchmark( test, “test”, “test2” )

// 2
RunBenchmark( function( )
local i = 0
while i < 1000 do
print( “test”, “test2” );
i = i + 1;
end );

// 3
RunBenchmark( function( )
test( “test”, “test2” );
end );[/lua]

oh lordie thank you so much for that function. I’ve really been working on trying to make efficient code, so this is godsend.

I may as well mention one more thing then; at the top of the file, or above the draw function. If you are going to be using a lot of trig functions such as math.sin, etc; localize them.

[lua]local sin = math.sin[/lua]

Etc. This can save up to 30% in time according to Lua.org

Good to know. If I do something like

local math = math

does this have the same effect as if I had done what you said for each function? Effectively does it localize the whole library? Or not at all?

According to Lua.org, it needs to be each individual function.

http://www.lua.org/gems/sample.pdf Page 4

Oh, good to know. Many thanks, this has been quite the learning experience :slight_smile: