ソースを参照

Merge pull request #389 from VaclavElias/update-29-manual-model-node-example

feat: Example snippet added - Link entity to a bone, various content and styling updates
Vaclav Elias 9 ヶ月 前
コミット
813aaf7a64

+ 1 - 1
en/manual/animation/additive-animation.md

@@ -137,4 +137,4 @@ You can use additive animations with animations that use the same skeleton and s
 * [Animation scripts](animation-scripts.md)
 * [Procedural animation](procedural-animation.md)
 * [Custom blend trees](custom-blend-trees.md)
-* [custom attributes](custom-attributes.md)
+* [Custom attributes](custom-attributes.md)

+ 1 - 1
en/manual/animation/animation-scripts.md

@@ -110,4 +110,4 @@ You can also override the animation blend tree and do all animation blending in
 * [Procedural animation](procedural-animation.md)
 * [Custom blend trees](custom-blend-trees.md)
 * [Model node links](model-node-links.md)
-* [custom attributes](custom-attributes.md)
+* [Custom attributes](custom-attributes.md)

+ 1 - 1
en/manual/animation/custom-blend-trees.md

@@ -108,4 +108,4 @@ public class AnimationBlendTree : SyncScript, IBlendTreeBuilder
 * [Additive animation](additive-animation.md)
 * [Procedural animation](procedural-animation.md)
 * [Model node links](model-node-links.md)
-* [custom attributes](custom-attributes.md)
+* [Custom attributes](custom-attributes.md)

+ 1 - 1
en/manual/animation/import-animations.md

@@ -63,4 +63,4 @@ To use an animation asset, add an [AnimationComponent](xref:Stride.Engine.Animat
 * [Procedural animation](procedural-animation.md)
 * [Custom blend trees](custom-blend-trees.md)
 * [Model node links](model-node-links.md)
-* [custom attributes](custom-attributes.md)
+* [Custom attributes](custom-attributes.md)

+ 1 - 1
en/manual/animation/index.md

@@ -53,4 +53,4 @@ The templates **First-person shooter**, **Third-person platformer** and **Top-do
 * [Procedural animation](procedural-animation.md)
 * [Custom blend trees](custom-blend-trees.md)
 * [Model node links](model-node-links.md)
-* [custom attributes](custom-attributes.md)
+* [Custom attributes](custom-attributes.md)

+ 44 - 10
en/manual/animation/model-node-links.md

@@ -10,16 +10,15 @@ The **model node link** component attaches an entity to a node of a skeleton on
 
 For example, imagine you have two models: a knight, and a sword. The character has a sword swinging animation. You can use a model link node to place the sword in the knight's hand and attach it to the correct node in the knight skeleton, so the sword swings with the knight animation.
 
-<p>
+<div class="ratio ratio-16x9 mb-3">
 <video autoplay loop class="responsive-video" poster="../particles/tutorials/media/sword-slash-1.jpg">
    <source src="../particles/tutorials/media/sword-slash-1.mp4" type="video/mp4">
 </video>
-</p>
+</div>
 
 ## Set up a model node link component
 
 1. In the **Scene Editor**, select the entity you want to link to a node in another entity.
-
 2. In the **Property Grid**, click **Add component** and select **Model node link**.
 
     ![Add component](../particles/tutorials/media/add-model-node-link.png)
@@ -38,11 +37,11 @@ For example, imagine you have two models: a knight, and a sword. The character h
 
 4. Select the model you want to link the entity to and click **OK**.
 
-    >[!Note]
-    >The entity you link to must have a model with a skeleton, even if the model isn't visible at runtime.
+    > [!Note]
+    > The entity you link to must have a model with a skeleton, even if the model isn't visible at runtime.
 
-    >[!Tip]
-    >If you don't specify a model, Stride links the entity to the model on the parent entity.
+    > [!Tip]
+    > If you don't specify a model, Stride links the entity to the model on the parent entity.
 
 5. In **Node name**, select the node in the model you want to attach this entity to.
 
@@ -58,8 +57,43 @@ To add an offset to the linked entity, use the entity's [TransformComponent](xre
 
 ![Transform](media/transform-component.png)
 
->[!Note]
->If you don't want to add an offset, make sure the values are all set to `0,0,0`.
+> [!Note]
+> If you don't want to add an offset, make sure the values are all set to `0,0,0`.
+
+## Example script
+
+This script demonstrates how to link one entity (such as a `SwordModel`) to a specific bone (`weapon_bone_R`) in another entity's skeleton hierarchy (in this case, the `mannequinModel`) using Stride's `ModelNodeLinkComponent`.
+
+```csharp
+public class BoneLink : StartupScript
+{
+    // This example assumes you've created a project with the default Stride models
+    // "mannequinModel" and "SwordModel." Add them from the "Assets/Models" folder to your scene,
+    // and then attach this script to the "SwordModel" entity
+
+    ModelNodeLinkComponent boneLink;
+
+    public override void Start()
+    {
+        // Initialize the script
+        // Here we locate the entity named "mannequinModel" by searching the root scene's entities
+        Entity owner = SceneSystem.SceneInstance.RootScene.Entities.Where(e => e.Name == "mannequinModel").Single();
+
+        boneLink = new ModelNodeLinkComponent
+        {
+             // This is the ModelComponent on the target entity (mannequinModel)
+            Target = owner.Get<ModelComponent>(),
+
+            // We set a "hard link" to Nodes[70], which corresponds to "weapon_bone_R"
+            // in the target's skeleton hierarchy
+            NodeName = owner.Get<ModelComponent>().Model.Skeleton.Nodes[70].Name
+        };
+
+        // Finally, add this link component to our current (SwordModel) entity
+        base.Entity.Components.Add(boneLink);
+    }
+}
+```
 
 ## See also
 
@@ -71,7 +105,7 @@ To add an offset to the linked entity, use the entity's [TransformComponent](xre
 * [Additive animation](additive-animation.md)
 * [Procedural animation](procedural-animation.md)
 * [Custom blend trees](custom-blend-trees.md)
-* [custom attributes](custom-attributes.md)
+* [Custom attributes](custom-attributes.md)
 
 For examples of how model node links are used, see:
 

+ 1 - 1
en/manual/animation/preview-animations.md

@@ -48,4 +48,4 @@ The animation preview uses the model selected in the **preview model** in the **
 * [Procedural animation](procedural-animation.md)
 * [Custom blend trees](custom-blend-trees.md)
 * [Model node links](model-node-links.md)
-* [custom attributes](custom-attributes.md)
+* [Custom attributes](custom-attributes.md)

+ 1 - 1
en/manual/animation/procedural-animation.md

@@ -139,4 +139,4 @@ public class AnimationLight : StartupScript
 * [Additive animation](additive-animation.md)
 * [Custom blend trees](custom-blend-trees.md)
 * [Model node links](model-node-links.md)
-* [custom attributes](custom-attributes.md)
+* [Custom attributes](custom-attributes.md)

+ 6 - 6
en/manual/animation/set-up-animations.md

@@ -55,13 +55,13 @@ After you add animations to an entity, you need to play them with a [script](../
 ### Example script
 
 ```cs
-    public class SimpleAnimationScript : StartupScript
+public class SimpleAnimationScript : StartupScript
+{
+    public override void Start()
     {
-        public override void Start()
-        {
-            Entity.Get<AnimationComponent>().Play("Walk");
-        }
+        Entity.Get<AnimationComponent>().Play("Walk");
     }
+}
 ```
 
 This script looks for an animation with the name *Walk* under the animation component on the entity.
@@ -93,4 +93,4 @@ Game Studio adds the script as a component. You can adjust [public variables you
 * [Procedural animation](procedural-animation.md)
 * [Custom blend trees](custom-blend-trees.md)
 * [Model node links](model-node-links.md)
-* [custom attributes](custom-attributes.md)
+* [Custom attributes](custom-attributes.md)

+ 10 - 17
en/manual/files-and-folders/distribute-a-game.md

@@ -54,7 +54,7 @@ When you're ready to publish your game, create a release build from Visual Studi
 ### To build using terminal instead of Visual Studio
 
  1. Ensure the relevant .NET SDK is installed (Stride 4.2 is on .NET 8)
- 2. open the folder of your project where the *.Windows.csproj file sits.
+ 2. Open the folder of your project where the `*.Windows.csproj` file sits.
 
     ![Project Folder](media/project-folder.png)
 
@@ -62,32 +62,28 @@ When you're ready to publish your game, create a release build from Visual Studi
     
     ![Open terminal](media/open-terminal.png)
 
- 4. finally publish with the command 
+ 4. Finally publish with the command 
  
- ```
- dotnet publish
- ```
+    ```
+    dotnet publish
+    ```
 
- or the below to include the .NET runtime with your game
+    or the below to include the .NET runtime with your game
 
- ```
- dotnet publish -r win-x64 --self-contained true --framework net8.0-windows
- ```
+    ```
+    dotnet publish -r win-x64 --self-contained  true --  framework net8.0-windows
+    ```
  
- You can also append `--output <YOUR_EXPORT_FOLDER>` to specify where to export to.
+    You can also append `--output <YOUR_EXPORT_FOLDER>` to specify where to export to.
 
 ## 2. Delete unnecessary files
 
 In the release folder in your project bin folder (eg *MyGame/Bin/MyPlatform/Release*), you can delete the following unnecessary files:
 
 * `.pdb` files (debug information)
-
 * `.xml` files (API documentation)
-
 * files that contain `vshost` in their filenames (eg `MyGame5.vshost.exe` and `MyGame5.vshost.exe.manifest`) 
-
 * folders other than the `x64`, `x86`, or `data` folders
-
 * other unnecessary files, such as custom configuration files (ie files not created with Stride)
 
 ## 3. Distribute your game
@@ -97,9 +93,7 @@ After you create a release build, how you distribute it is up to you.
 To run games made with Stride on Windows, users need:
 
 * .NET 8 Runtime (Unless you published with **self-contained**)
-
 * DirectX11 (included with Windows 10 and later), OpenGL, or Vulkan
-
 * Visual C++ 2015 runtimes (x86 and/or x64, depending on what you set in your project properties in Visual Studio)
 
 ## See also
@@ -107,5 +101,4 @@ To run games made with Stride on Windows, users need:
 * [Add or remove a platform](../platforms/add-or-remove-a-platform.md)
 * [Version control](version-control.md)
 * [Project structure](project-structure.md)
-
 * [Microsoft documentation](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish)

+ 2 - 2
en/manual/game-studio/prefabs/nested-prefabs.md

@@ -11,11 +11,11 @@ If you modify a nested prefab, all the dependent prefabs inherit the change auto
 
 This video demonstrates an example of nested prefabs:
 
-<p>
+<div class="ratio ratio-16x9 mb-3">
 <video autoplay loop class="responsive-video" poster="media/create-nested-prefab.jpg">
    <source src="media/create-nested-prefab.mp4" type="video/mp4">
 </video>
-</p>
+</div>
 
 In the center pane, we already have a prefab named **Lamp**. In the right pane, we create a new prefab named **Boxes**, comprising several box entities positioned together. We add the Boxes prefab to the Lamp prefab. Changes made to the Boxes prefab are reflected in the Lamp prefab. These are in turn reflected in the instances of the Lamp prefab in the scene (left pane).
 

+ 2 - 2
en/manual/game-studio/prefabs/override-prefab-properties.md

@@ -12,11 +12,11 @@ In the following video, the **Lamp** prefab contains several box entities that b
 
 If we add another box to the **Boxes** parent in the prefab, it doesn't appear in the overridden instance. That's because we deleted the **Boxes** parent from that instance.
 
-<p>
+<div class="ratio ratio-16x9 mb-3">
 <video autoplay loop class="responsive-video" poster="media/delete-boxes-from-prefab-instance.jpg">
    <source src="media/delete-boxes-from-prefab-instance.mp4" type="video/mp4">
 </video>
-</p>
+</div>
 
 ## View overridden properties
 

+ 0 - 3
en/manual/navigation/index.md

@@ -9,11 +9,8 @@ You can use the **navigation** system to control how characters and other object
 ## Set up navigation
 
 1. [Create a navigation group](navigation-groups.md)
-
 2. [Add a navigation mesh](navigation-meshes.md)
-
 3. [Add a navigation bounding box](navigation-bounding-boxes.md)
-
 4. [Add a navigation component](navigation-components.md)
 
 ## Sample project

+ 2 - 2
en/manual/particles/ribbons-and-trails.md

@@ -32,11 +32,11 @@ To create ribbons and trails, you usually need to sort the particles into an ord
 
 Here's an example of how unsorted particles look at runtime:
 
-<p>
+<div class="ratio ratio-16x9 mb-3">
 <video autoplay loop class="responsive-video" poster="tutorials/media/sword-slash-2.jpg">
    <source src="tutorials/media/sword-slash-2.mp4" type="video/mp4">
 </video>
-</p>
+</div>
 
 Rather than the particles connecting in order, the strip erratically jumps between particles. (This is the same problem alpha-blended quads have when they're not properly sorted.)
 

+ 4 - 4
en/manual/physics/create-a-bouncing-ball.md

@@ -73,11 +73,11 @@ Now we'll move the camera to give us a good view of the scene.
 
 Let's see what the scene looks like so far. To run the project, press **F5**.
 
-<p>
+<div class="ratio ratio-16x9 mb-3">
 <video autoplay loop class="responsive-video">
    <source src="media/physics-tutorials-create-a-bouncing-ball-falling-ball.mp4" type="video/mp4">
 </video>
-</p>
+</div>
 
 The Sphere (body) responds to gravity and falls. The Ground (static collider) breaks its fall. But there's no bounce effect yet.
 
@@ -96,11 +96,11 @@ Let's set the `Spring Frequency` and `Spring Damping Ratio` of the Sphere.
 
 To see how this changes the physics, run the project again (**F5**). This time, the ball bounces on the ground before coming to a stop:
 
-<p>
+<div class="ratio ratio-16x9 mb-3">
 <video autoplay loop class="responsive-video">
    <source src="media/physics-tutorials-create-a-bouncing-ball-falling-and-bouncing-ball.mp4" type="video/mp4">
 </video>
-</p>
+</div>
 
 Now that we've created a bouncing ball, we can use it to learn to [Script a trigger](script-a-trigger.md).
 

+ 4 - 4
en/manual/physics/script-a-trigger.md

@@ -98,11 +98,11 @@ Now the trigger entity is between the ground and the sphere.
 
 If we run the project now (**F5**), the ball bounces off the trigger, but nothing happens.
 
-<p>
+<div class="ratio ratio-16x9 mb-3">
 <video autoplay loop class="responsive-video">
    <source src="media/bouncing-ball-with-trigger-no-effect.mp4" type="video/mp4">
 </video>
-</p>
+</div>
 
 Let's write a script to change the size of the ball when it enters the trigger.
 
@@ -194,11 +194,11 @@ Run the project (**F5**) to see the trigger in action.
 
 The ball falls through the trigger, doubles in size, exits the trigger, and returns to its normal size.
 
-<p>
+<div class="ratio ratio-16x9 mb-3">
 <video autoplay loop class="responsive-video">
    <source src="media/bouncing-ball-with-trigger-scaled.mp4" type="video/mp4">
 </video>
-</p>
+</div>
 
 ## See also
 

+ 24 - 25
en/manual/scripts/create-a-model-from-code.md

@@ -6,9 +6,7 @@
 You can create models in scripts at runtime. You can do this in several different ways, including:
 
 * creating a model from an asset
-
 * creating a procedural model using built-in geometric primitives (eg a sphere or cube)
-
 * instantiating a prefab that contains a model (see [Use prefabs](../game-studio/prefabs/use-prefabs.md))
 
 ## Create a model from an asset
@@ -21,17 +19,18 @@ You can create models in scripts at runtime. You can do this in several differen
 
     ```cs
     // Create a new entity and add it to the scene.
-	var entity = new Entity();
-	SceneSystem.SceneInstance.RootScene.Entities.Add(entity);
-
+    var entity = new Entity();
+    SceneSystem.SceneInstance.RootScene.Entities.Add(entity);
+  
     // Add a model included in the game files.
-	var modelComponent = entity.GetOrCreate<ModelComponent>();
-	modelComponent.Model = Content.Load<Model>("MyFolder/MyModel");
+    var modelComponent = entity.GetOrCreate<ModelComponent>();
+    modelComponent.Model = Content.Load<Model>("MyFolder/MyModel");
     ```
-
-    >[!Tip]
-    >To find the model's asset URL, in the **Asset View**, move the mouse over the model.
-    >![(Get asset URL](media/get-asset-url.png)
+  
+    > [!Tip]
+    > To find the model's asset URL, in the **Asset View**, move the mouse over the model.
+    >
+    > ![(Get asset URL](media/get-asset-url.png)
 
 3. Add the script as a **script component** to any entity in the scene. It doesn't matter which entity you use. For instructions, see [Use a script](use-a-script.md).
 
@@ -105,7 +104,7 @@ You can create models in scripts at runtime. You can do this in several differen
         { 
             /* Vertex buffer and index buffer setup */ 
             PrimitiveType = Stride.Graphics.PrimitiveType.TriangleList,
-            DrawCount = indicies.Length,
+            DrawCount = indices.Length,
             IndexBuffer = new IndexBufferBinding(indexBuffer, true, indices.Length),
             VertexBuffers = new[] { new VertexBufferBinding(vertexBuffer, 
                                       VertexPositionTexture.Layout, vertexBuffer.ElementCount) },
@@ -116,8 +115,8 @@ You can create models in scripts at runtime. You can do this in several differen
     ```
 
 
->[!Note]
->For more information about how to set up vertex and index buffers, see [Drawing vertices](../graphics/low-level-api/draw-vertices.md).
+> [!Note]
+> For more information about how to set up vertex and index buffers, see [Drawing vertices](../graphics/low-level-api/draw-vertices.md).
 
 Finally, you need to give the model one or more materials. There are two ways to do this.
 
@@ -145,18 +144,18 @@ Finally, you need to give the model one or more materials. There are two ways to
 For example:
 
 ```cs
-    // Create a material (eg with red diffuse color).
-    var materialDescription = new MaterialDescriptor
+// Create a material (eg with red diffuse color).
+var materialDescription = new MaterialDescriptor
+{
+    Attributes =
     {
-        Attributes =
-	    {
-	        DiffuseModel = new MaterialDiffuseLambertModelFeature(),
-	        Diffuse = new MaterialDiffuseMapFeature(new ComputeColor { Key = MaterialKeys.DiffuseValue })
-	    }
-    };
-    var material = Material.New(GraphicsDevice, materialDescription);
-    material.Parameters[0].Set(MaterialKeys.DiffuseValue, Color.Red);
-    model.Materials.Add(0, material);
+        DiffuseModel = new MaterialDiffuseLambertModelFeature(),
+        Diffuse = new MaterialDiffuseMapFeature(new ComputeColor { Key = MaterialKeys.DiffuseValue })
+    }
+};
+var material = Material.New(GraphicsDevice, materialDescription);
+material.Parameters[0].Set(MaterialKeys.DiffuseValue, Color.Red);
+model.Materials.Add(0, material);
 ```
 
 ## See also

+ 2 - 2
en/manual/sprites/use-sprites.md

@@ -20,11 +20,11 @@ To add a sprite to a scene, add a **sprite component** to an entity. Afterwards,
 
 3. From the **Asset View**, drag the sprite sheet to the **Source** field in the Sprite component:
 
-    <p>
+    <div class="ratio ratio-16x9 mb-3">
         <video autoplay loop class="responsive-video" poster="media\drag-sprite-sheet-to-asset-picker.png">
         <source src="media\drag-sprite-sheet-to-asset-picker.mp4" type="video/mp4">
         </video>
-    </p>
+    </div>
 
     Alternatively, click ![Hand icon](~/manual/game-studio/media/hand-icon.png) (**Select an asset**):