Skip to content

Commit 4b27e00

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
docs: update readme
1 parent ec8f498 commit 4b27e00

File tree

1 file changed

+147
-4
lines changed

1 file changed

+147
-4
lines changed

libs/angular-three/README.md

Lines changed: 147 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,150 @@
1-
# angular-three
1+
# Angular Renderer for THREE.js
22

3-
This library was generated with [Nx](https://nx.dev).
3+
[![From Vietnam with <3](https://raw.githubusercontent.com/webuild-community/badge/master/svg/love.svg)](https://webuild.community)
44

5-
## Running unit tests
5+
Leverage your [Angular](https://angular.io) to build 3D applications with [THREE.js](https://threejs.org)
66

7-
Run `nx test angular-three` to execute the unit tests.
7+
## Installation
8+
9+
### Angular CLI
10+
11+
```shell
12+
npx ng add angular-three
13+
```
14+
15+
### Nx
16+
17+
```shell
18+
npm i angular-three
19+
npx nx g angular-three:init
20+
```
21+
22+
### Manual
23+
24+
```shell
25+
npm i angular-three three
26+
```
27+
28+
```shell
29+
npm i -D @types/three
30+
```
31+
32+
- Adjust `tsconfig.json` (or `tsconfig.base.json`) to include `skipTypeCheck: false`
33+
34+
> Typically, we'd want to keep `three` and `@types/three` on the same minor version. Eg: `0.147`, `0.148` etc..
35+
36+
## Type
37+
38+
### VSCode
39+
40+
- If you use `ng add` or `nx generate` command, this is setup for you.
41+
- If you install `angular-three` manually, you can do the following steps to enable typings
42+
- Open `.vscode/settings.json`, or create one if you do not have it
43+
- Add `html.customData` property with the value of `["./node_modules/angular-three/metadata.json"]`. If `html.customData` exists, simply add `"./node_modules/angular-three/metadata.json"` to the array
44+
45+
### WebStorm/IntelliJ
46+
47+
- You **should not** need to do anything here but if things do not work, you can add `web-types` property to `package.json` with the value of `"./node_modules/angular-three/web-types.json"`
48+
49+
### NeoVim
50+
51+
Setup will vary depending on your current NeoVim configuration. However, I'd expect the **required** steps to be the same
52+
53+
- `neovim/nvim-lspconfig` needs to be configured for `html` LSP
54+
- `init_options.dataPaths` needs to include the path to `node_modules/angular-three/metadata.json`
55+
- Setup a `html/customDataContent` handler (`handlers = {["html/customDataContent"] = function() ... end}` for Lua syntax)
56+
and return the content of the `init_options.dataPaths`
57+
58+
Here's an example setup for [LazyVim](https://www.lazyvim.org/)
59+
60+
```lua
61+
return {
62+
{
63+
"neovim/nvim-lspconfig",
64+
---@class PluginLspOpts
65+
opts = {
66+
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
67+
setup = {
68+
html = function(_, opts)
69+
opts.init_options = {
70+
dataPaths = {
71+
vim.fn.getcwd() .. "/node_modules/angular-three/metadata.json",
72+
},
73+
configurationSection = { "html", "css", "javascript" },
74+
embeddedLanguages = {
75+
css = true,
76+
javascript = true,
77+
},
78+
provideFormatter = true,
79+
}
80+
81+
opts.handlers = {
82+
["html/customDataContent"] = function(err, result, ctx, config)
83+
local function exists(name)
84+
if type(name) ~= "string" then
85+
return false
86+
end
87+
return os.execute("test -e " .. name)
88+
end
89+
90+
if not vim.tbl_isempty(result) and #result == 1 then
91+
if not exists(result[1]) then
92+
return ""
93+
end
94+
local content = vim.fn.join(vim.fn.readfile(result[1]), "\n")
95+
return content
96+
end
97+
return ""
98+
end,
99+
}
100+
101+
return false
102+
end,
103+
},
104+
},
105+
},
106+
}
107+
```
108+
109+
## Documentations
110+
111+
Read more about Angular Three usages in [Documentations](https://angular-three-backupjs.netlify.app)
112+
113+
## Simple usage
114+
115+
1. Create a `Scene` component as a Standalone Component
116+
117+
```ts
118+
import { extend } from 'angular-three';
119+
import { Mesh, BoxGeometry, MeshBasicMaterial } from 'three';
120+
121+
extend({ Mesh, BoxGeometry, MeshBasicMaterial });
122+
123+
@Component({
124+
standalone: true,
125+
template: `
126+
<ngt-mesh>
127+
<ngt-box-geometry />
128+
<ngt-mesh-basic-material color="darkred" />
129+
</ngt-mesh>
130+
`,
131+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
132+
})
133+
export class Scene {}
134+
```
135+
136+
- `extend` will add the THREE entities to `angular-three` catalogue which allows the renderer to recognize the custom tags: `ngt-mesh`, `ngt-box-geometry` etc..
137+
- Custom Element tags follow this rule: `ngt-` + THREE classes in **kebab-case**. `Mesh` -> `ngt-mesh`
138+
- `schemas: [CUSTOM_ELEMENTS_SCHEMA]` allows us to use custom tags on the template. This is Angular's limitation at the moment
139+
140+
2. Render `<ngt-canvas>` component, use `Scene` component above to pass into `[sceneGraph]` input on `<ngt-canvas>`
141+
142+
```html
143+
<ngt-canvas [sceneGraph]="Scene" />
144+
```
145+
146+
- `ngt-canvas` creates the basic building blocks of THREE.js: a default `WebGLRenderer`, a default `Scene`, and a default `PerspectiveCamera`
147+
148+
## Contributions
149+
150+
Contributions are welcomed

0 commit comments

Comments
 (0)