Panorama - Custom DOTAScenePanel

edited March 2017 in Tutorials

Introduction

In this tutorial we'll go through the tricks you can do with the undocumented DOTAScenePanel class in panorama.

Now, you might have seen its usage if you looked through the sources in the main menu. This panel allows us to display 3D content in panorama. You might have tried using it yourself. It's pretty easy to setup a simple panel to display a unit, with code like

<DOTAScenePanel style="width:400px;height:400px;" unit="npc_dota_hero_sven"/>

Code like this is used to display heroes in the armory. This panel is also has no custom dynamic properties, meaning that we can't change the unit after creating a panel.

Background maps

But wait, there's more! DOTAScenePanel accepts the "map" parameter, which points to a specific type of vmaps - background maps. You can find them in asset browser in background folder. Those vmaps only accept a specific set of entities and are shown in panorama using cameras. Let's follow up by creating a simple background map.

Setting up the map

Start up hammer editor and create a new map. Save it in your maps folder as 'background.vmap'. Go to Map -> Map Properties (Ctrl-Shift-P) and check the 'Compile as background map' checkbox.

http://puu.sh/o3Bdp/93d2d9fed4.png

Use the Entity Tool (Shift-E) and choose the prop_dynamic entity, then click somewhere in the world to place it.

Select that newly placed entity in the outliner and change its World Model property to models/courier/donkey_unicorn/donkey_unicorn.vmdl.

http://puu.sh/o3BmY/2d6181c281.png

Now you've got your movie star ready to be displayed. You can also change the Default Animation field to idle or any string from its model entries.

http://puu.sh/o3Bux/60e800273e.jpg

Now we've got action, but still missing lights and camera. With the Entity Tool (Shift-E), create a env_global_light entity, and point_camera entity.

Select your newly created camera, move your hammer camera in such way that you can see the donkey and click View - Align Selection to Active Camera.

http://puu.sh/o3C4E/1a8154b302.png

http://puu.sh/o3CPb/5891357ed3.png

As the last step select your camera and give it a name in the properties, like "camera1".

Save your map and build it (F9).

Setting up panorama

I won't describe how to set up a basic panorama environment, if you are having issues with displaying simple panels, refer to https://developer.valvesoftware.com/wiki/Dota_2_Workshop_Tools/Panorama Once you've ready to go, simply add <DOTAScenePanel style="width:400px;height:400px;" map="background" camera="camera1"/> to your XML, you should see your donkey movie star in its full glory. Shouldn't take you more than 10 minutes.

Now let's get to the advanced part.

The part where magic gets real

Units with cosmetics

We can easily build up a "unit" like scene, using the portrait_world_unit entity type. This entity supports all kinds of units and also cosmetic item definitions. The quirk here is that you have to enter the raw properties editing mode to set displayed entity to a hero. Item definitions property all refer to different loadout slots and accept item IDs. Item ID list can be found here.

Lina is awesome

Multiple cameras

This is pretty straightforward, DOTAScenePanel also accepts the camera parameter in the definition, which will try to find the camera with the provided name.

http://puu.sh/o3Gv7/783de89488.jpg

Important to note, compiling the map again does change the look of the panorama panel without restarting the map, but you can't change it at runtime. You'll understand how to achieve the same result in the following parts.

Dynamic layout loading

Since the only thing DOTAScenePanel respects is its own layout definition, we will have to provide it from the start. Fortunately we can load layout from string, while altering the definition.

var camera = "camera1";
var style = "width:400px;height:400px;";
if (someCondition) {
    camera = "camera2";
}

var sceneContainer = $("#SomeContainer");
sceneContainer.BCreateChildren("<DOTAScenePanel style='" + style + "' map='background' camera='" + camera + "'"/>");

As you might have noticed, you have to wrap the whole thing in '', while also providing the initial container for the layout. Pretty terrible, but for now it seems like the only way.

Firing IO events

Animation

Now the REAL fun starts. Dashboard source code uses the DOTAGlobalSceneFireEntityInput event which starts the particles on the home button, for example. This event is basically a DoEntFire specifically for DOTAScenePanel.

For example usage, set up a simple <DOTAScenePanel id="scene" style="width:400px;height:400px;" map="background"/> (notice the id, it's very important!) once again. But this time, alter the map and change the donkey Name property to donkey, don't forget to rebuild the map.

Now make a basic panorama button, and give it onactivate="DOTAGlobalSceneFireEntityInput(scene, donkey, SetAnimation, death)".

Now if you've done everything correctly, your donkey should play his death animation every time you press the button. How? Magic. But really though, refer to the Inputs part of this page. Notice the SetAnimation input.

Also notice how we've used DOTAGlobalSceneFireEntityInput in onactivate as if it were a real function, which it isn't. That's because panel events are special cornflakes. In panorama javascript you have to use $.DispatchEvent("DOTAGlobalSceneFireEntityInput", arguments) to achieve the same result.

Example

$.DispatchEvent("DOTAGlobalSceneFireEntityInput", "LightBuilder", "donkey", "SetAnimation", "spawn");

Scripts? Scripts!

If you were a good boy, you might have noticed the RunScriptFile and RunScriptCode inputs.

Now make a donkey.lua file in your vscripts folder and put a simple print("Onions have layers, donkey") in it.

Now set your button onactivate to DOTAGlobalSceneFireEntityInput(scene, donkey, RunScriptFile, donkey).

Notice the lack of file extension. Press the button again. You should see the message in the console. Congratulations!

But don't get too excited. Yes, you can execute lua from panorama. But it's clientside-lua and it's very limited. You can't even move things there. The only good thing I could think to do is particles. A recent patch added ParticleManager support to clientside lua. So theoretically you can create, destroy and move different particles there, and particles are very powerful.

Entity parenting

The way cosmetics in dota works is that every cosmetic item is a separate entity which is parented to a hero, attached to a specific attach point with specific offsets and offset angles. And we can do that too! (Well, partly, at least)

The way that works is you select a prop_dynamic, in object properties put up a parent entity name, put in the Parent Model Bone/Attachment Name (you can look up attachment names in the model editor), check the Use Model Attachment Offset checkbox and then realize that changing attachment offset doesn't work. At least for now. Changing angles works though so there is hope that offset will be fixed someday.

That's it for today!

Comments

  • Posts: 1,670

    New keys found on the Battle Pass tree minigame

    • renderdeferred="false"
    • light="global_light"
    • antialias="true"

    The concept of Modding Community doesn't go well together with Competitive Business
    My Project Page || My GitHub Profile ||

  • DOTAGlobalSceneSetCameraEntity and $.DispatchEvent( 'DOTAGlobalSceneSetCameraEntity', 'RadiantAmbient', 'camera_end_top', 2.0 ); seems to enable dynamic camera change!

  • edited March 2017 Posts: 412

    Just some additional info:

    drawbackground="0" removes the pedestal under unit=x panels

    rotateonhover="true" yawmin="-10" yawmax="10" pitchmin="-10" pitchmax="10" allows panel rotation on hover

    particleonly="false" is required for all non-particle panels or else stuff is probably gonna look like ass

    renderwaterreflections="true

    activity-modifier="PostGameIdle"

  • DOTAGlobalSceneSetRootEntity event spotted

  • Posts: 412

    Very important things:

    <DOTAScenePanel id="DialogPortrait" unit="npc_dota_hero_pudge" environment="default"/>

    environment="default" makes it a portrait. The default itself is seemingly a camera key from portraits.txt

    DOTAScenePanel.SetUnit(unitName, string) is now a thing, you don't need to replace the panel to change a unit now. Second parameter purpose is currently unknown

    DOTAScenePanel.PlayEntitySoundEvent(string1, string2) might be something to make portraits talk. If someone knows a way to make it work: please respond to this thread or PM me.

  • Hi OP, I noticed that in your mod "crumbling island arena", even I got to change my hero cosmetics (yes, I bought a pass for it), the hero portrait stay the same. I guess it's the .webm used in normal selection UI. My question is, isn't there a way to update hero portrait after changing the hero's cosmetic with lua functions like FollowEntity?

  • edited August 2017 Posts: 412

    As far as I know there isn't right now, sadly In fact if you strip heroes from wearables as I do right now you'll get naked heroes on portraits as well, which is why I use webms

  • Thank you for your answer. I decide to put a picture on top of portrait to hide the naked hero :(