S&box Wiki

Revision Difference

custom_modeldoc_nodes#546444

<title>Custom ModelDoc nodes</title> <cat>Dev.Model</cat><title>Custom ModelDoc nodes</title> You can make a custom ModelDoc node. This is useful for any gamemode-specific data you want to attach to specific models. These nodes are defined in C# code, and the FGD for these is automatically generated for you. # How to do it 1. Define a struct or class. Add the `ModelDoc.GameData` attribute. ``` /// <summary> /// Spawn a particle when the model is used on an entity. Support for this depends on the entity. /// </summary> [ModelDoc.GameData( "particle", AllowMultiple = true )] public class ModelParticle { [DisplayName( "Particle" ), ResourceType( "vpcf") ] public string Name { get; set; } [JsonPropertyName( "attachment_point" ), FGDType( "model_attachment" )] public string AttachmentPoint { get; set; } [JsonPropertyName( "attachment_type" )] public ParticleAttachment AttachmentType { get; set; } = ParticleAttachment.AttachmentFollow; [JsonPropertyName( "attachment_offset" )] public Vector3 AttachmentOffset { get; set; } } ``` 2. Run your gamemode. The FGD for this node then gets auto-generated. 3. Assign the node in ModelDoc. If you don't know how to do that, you should probably read a ModelDoc guide like [this one](https://wiki.facepunch.com/sbox/Importing_a_new_model#thingsyouregoingtoneed). 4. Now you can use this data in code. ``` ModelParticle[] modelParticles = Model.GetData<ModelParticle[]>(); ``` # Other things you can do with this There's multiple attributes that you can use in order to make your own custom designers: - `ModelDoc.Axis` - `ModelDoc.Box` - `ModelDoc.Sphere` - `ModelDoc.Capsule` - `ModelDoc.Cylinder` - `ModelDoc.Line` - `ModelDoc.HandPose` - `ModelDoc.EditorWidget`