Skip to content

Commit 6a217ce

Browse files
author
Jarrod Smith
committed
Stingray plugin documentation generation with adoc.
1 parent 44cf21d commit 6a217ce

7 files changed

Lines changed: 152 additions & 0 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ See [the wiki](https://github.com/AutodeskGames/stingray-plugin/wiki/How-to-crea
9191
- `stingray_sdk`: Autodesk Interactive editor and engine C/C++ header based plugin SDK downloaded by `spm`.
9292
- `tools`: Various build tools downloaded by `spm`.
9393
- `make.rb`: Build interface script. Execute `make.rb --help` to see all the options.
94+
- `docs`: Ruby script and template to automatically generate documentation for your plugin using Adoc.
9495

9596
Once you've successfully built the Autodesk Interactive plugin, you can zip the `plugin` folder and **distribute** your plugin. For help getting started with with the Autodesk Interactive SDK, see the tutorial videos and topics in the [main Autodesk Interactive SDK Help](http://help.autodesk.com/view/Stingray/ENU/?guid=__sdk_help_introduction_html).
9697

@@ -99,6 +100,19 @@ Once you've successfully built the Autodesk Interactive plugin, you can zip the
99100
- `stingray-example.plugin`: Initial plugin descriptor. It is strongly recommended to rename the file name of this file.
100101
- `sample_project/`: Example project that demonstrate how your plugin works.
101102

103+
## Documentation
104+
105+
*Note: This currently requires Stingray source access due to the dependency on [Adoc](https://git.autodesk.com/gameware/stingray/tree/develop/docs/build/tools/adoc).*
106+
107+
In the [`./docs`](./docs) directory there's a ruby script that will generate documentation for your plugin using Adoc. Refer to the comments in the script and the other documentation example files in the `./docs` dir, as well as the [Stingray repository /docs readme](https://git.autodesk.com/gameware/stingray/tree/develop/docs) to learn how to annotate your code comments for Adoc parsing.
108+
109+
You do not need to install the `ixg-doc-tools` to generate your plugin docs. Just define the `%SR_SOURCE_DIR%` environment variable (e.g. `c:\dev\stingray`) or modify the line in [`make_plugin_docs.rb`](./docs/make_plugin_docs.rb). Then run the script and refer to the output directory in the console to view the generated documentation.
110+
111+
Usage:
112+
```
113+
ruby docs/make_plugin_docs.rb
114+
```
115+
102116
## More help
103117

104118
Please see the [Autodesk Interactive SDK Help](http://help-staging.autodesk.com/view/Stingray/ENU/?contextId=SDK_HOME) for more details on working with plug-ins, API reference documentation, and more.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
{
3+
"output_path": "$(SR_DOC_OUTPUT_DIR)/lua_HTML",
4+
"index_title": "My Plugin Documentation",
5+
"index_file": "./source/lua_reference/index.txt",
6+
"images_path": "./source/lua_reference/images",
7+
"version_history": "./source/lua_reference/versions",
8+
"save_version_as": "",
9+
"ref_id": "lua_ref"
10+
}

docs/make_plugin_docs.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#******************************************************************************
2+
#
3+
# make_plugin_docs.rb - Builds Adoc documentation for your plugin project.
4+
#
5+
# Details of marking up your source for Adoc processing can be found here:
6+
# https://git.autodesk.com/gameware/stingray/tree/develop/docs
7+
#
8+
# Usage:
9+
# 1) Modify the configuration variables below if needed.
10+
# 2) ruby make_plugin_docs.rb
11+
#******************************************************************************
12+
13+
require 'optparse'
14+
require 'fileutils'
15+
16+
# Utility functions
17+
class String
18+
def colorize(color_code); $stdout.isatty() ? "\e[#{color_code}m#{self}\e[0m" : self; end
19+
def black; colorize(30) end
20+
def red; colorize(31) end
21+
def green; colorize(32) end
22+
def yellow; colorize(33) end
23+
def blue; colorize(34) end
24+
def magenta; colorize(35) end
25+
def cyan; colorize(36) end
26+
def gray; colorize(37) end
27+
def default; colorize(39) end
28+
def bold; $stdout.isatty() ? "\e[1m#{self}\e[22m" : self; end
29+
end
30+
31+
$script_dir = File.expand_path(File.dirname(__FILE__))
32+
$docs_dir = $script_dir
33+
$plugin_dir = "#{$script_dir}/.."
34+
35+
#**************************************************************************
36+
# Change these depending upon your plugin's needs.
37+
$explicit_engine_dir = nil # Path to Stingray source directory e.g. "c:\dev\stingray", alternatively set the %SR_SOURCE_DIR% environment variable.
38+
$input_dirs = [
39+
"#{$plugin_dir}/engine", # For Lua API documentation.
40+
"#{$docs_dir}/source/samples",
41+
"#{$docs_dir}/source/lua_reference",
42+
"#{$plugin_dir}/plugin/sample_project"
43+
# Add any additional paths for adoc to process as needed.
44+
]
45+
$output_dir = "#{$docs_dir}/output"
46+
$config_path = "#{$docs_dir}/config_adoc_lua_reference.json"
47+
#**************************************************************************
48+
49+
$engine_dir = $explicit_engine_dir || ENV["SR_SOURCE_DIR"]
50+
if $engine_dir == nil or $engine_dir.empty?
51+
STDERR.puts "\nPlease define the %SR_SOURCE_DIR% environment variable or modify this script's $explicit_engine_dir to point to your Stingray source directory.".bold.red
52+
exit 1
53+
end
54+
55+
$make_docs = "#{$engine_dir}/docs/build/make_docs.rb"
56+
puts "Calling #{$make_docs}..."
57+
STDOUT.flush
58+
# This only builds the Lua API documentation. You can modify this to build other documentation types as needed.
59+
$command = ["ruby #{$make_docs} --lua-ref", "--input", "\"#{$input_dirs.join("\",\"")}\"",
60+
"--output", "\"#{$output_dir}\"",
61+
"--config", "\"#{$config_path}\"",
62+
*ARGV].join(" ") # Pass any command line args through.
63+
system($command)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@adoc lua
2+
3+
@ns stingray : nil
4+
@des The main namespace for the Lua API elements provided by the Stingray3D engine.
5+
6+
@cat my_category My Category
7+
@des A collection of related documentation items.
8+
9+
@obj MyObject : lightuserdata
10+
@des My test object.
11+
@grp my_category
51.3 KB
Loading
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Welcome to My Plugin!
2+
3+
More details can be found here:
4+
5+
* [A PDF](../relative/path/to/some.pdf)
6+
* [An external link](https://www.autodesk.com/products/stingray)
7+
8+
The best place to begin is by going through the [categories](categories.html), which cover the entire API grouped by topic. The category descriptions provide an overview. Alternatively, you can take a look at the [list of all objects](objects.html), or start exploring the elements exposed in the main [`stingray` namespace](ns_stingray.html).
9+
10+
Be sure to enable the plugin in the Stingray Editor:
11+
12+
![Example of including an image](add_plugin.png)

docs/source/samples/my_sample.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-- @adoc lua
2+
-- @exa my_sample Sample Title
3+
-- @des My sample description.
4+
5+
function pick_unit(world, camera)
6+
if SimpleProject then
7+
world = world or SimpleProject.world
8+
camera = camera or stingray.Unit.camera(SimpleProject.camera_unit, 1)
9+
end
10+
-- get the X and Y screen coordinates to pick from.
11+
local width, height = stingray.Application.back_buffer_size()
12+
local pick_x_pos = math.floor(width / 2)
13+
local pick_y_pos = math.floor(height / 2)
14+
if stingray.Window and stingray.Window.show_cursor() then
15+
pick_x_pos = stingray.Mouse.axis(stingray.Mouse.axis_id("cursor"), stingray.Mouse.RAW, 3).x
16+
pick_y_pos = stingray.Mouse.axis(stingray.Mouse.axis_id("cursor"), stingray.Mouse.RAW, 3).y
17+
end
18+
local depth = 0.5
19+
20+
-- translate the screen coordinates to a position in 3D world space.
21+
local screen_pos_in_scene = stingray.Camera.screen_to_world(camera, stingray.Vector3(pick_x_pos, pick_y_pos, 0), depth)
22+
local camera_position = stingray.Camera.world_position(camera)
23+
24+
-- get the direction from the camera position to the 3D starting coordinates.
25+
local camera_to_mouse_direction = stingray.Vector3.normalize(screen_pos_in_scene - camera_position);
26+
27+
-- cast a physics ray into the scene, starting from the camera position, in the
28+
-- direction toward the picked screen position.
29+
local physics_world = stingray.World.physics_world(world)
30+
local foundCollision, collisionPos, distance, normal, actor =
31+
stingray.PhysicsWorld.raycast(
32+
physics_world, camera_position, camera_to_mouse_direction, "closest"
33+
)
34+
35+
local actor_obj = nil
36+
if (foundCollision) then -- we have hit a unit.
37+
actor_obj = stingray.Actor.unit(actor)
38+
end
39+
return actor_obj, collisionPos, distance, normal, actor
40+
end
41+
-- @adoc lua
42+
-- @exa my_sample Sample Title

0 commit comments

Comments
 (0)