Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenjameslee committed Mar 31, 2018
2 parents 1eaabf0 + b937eab commit 35cd94a
Show file tree
Hide file tree
Showing 64 changed files with 1,871 additions and 2,639 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
server/static/build.js
26 changes: 10 additions & 16 deletions .eslintrc.json
@@ -1,18 +1,12 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"rules": {
"no-redeclare": "off",
"no-unused-vars": "off",
"no-undef": "off",
"no-mixed-spaces-and-tabs": "off",
"no-extra-semi": "off",
"no-empty": "off",
"no-console": "off"
}
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"rules": {
"no-unused-vars": ["error", { "args": "none" }]
}
}
63 changes: 54 additions & 9 deletions README.md
Expand Up @@ -74,11 +74,11 @@ Basic Example
<body>
<a-scene networked-scene>
<a-assets>
<script id="avatar-template" type="text/html">
<a-sphere></a-sphere>
</script>
<template id="avatar-template">
<a-sphere></a-sphere>
</template>
</a-assets>
<a-entity id="player" networked="template:#avatar-template;showLocalTemplate:false;" camera wasd-controls look-controls>
<a-entity id="player" networked="template:#avatar-template;attachTemplateToLocal:false;" camera wasd-controls look-controls>
</a-entity>
</a-scene>
</body>
Expand Down Expand Up @@ -165,16 +165,61 @@ Completely removing `a-scene` from your page will also handle cleanly disconnect
### Creating Networked Entities

```html
<a-entity networked="template=YOUR_TEMPLATE;showLocalTemplate=true"></a-entity>
<a-assets>
<template id="my-template">
<a-entity>
<a-sphere color="#f00"></a-sphere>
</a-entity>
</template>
<a-assets>

<!-- Attach local template by default -->
<a-entity networked="template: #my-template">
</a-entity>

<!-- Do not attach local template -->
<a-entity networked="template:#my-template;attachTemplateToLocal:false">
</a-entity>
```

Create an instance of a template to be synced across clients. The position and rotation will be synced by default. The [`aframe-lerp-component`](https://github.com/haydenjameslee/aframe-lerp-component) is added to allow for less network updates while keeping smooth motion.

Templates must only have one root element. When `attachTemplateToLocal` is set to true, the attributes on this element will be copied to the local entity and the children will be appended to the local entity. Remotely instantiated entities will be a copy of the root element of the template with the `networked` component added to it.

#### Example `attachTemplateToLocal=true`

```html
<a-entity wasd-controls networked="template:#my-template">
</a-entity>

<!-- Locally instantiated as: -->
<a-entity wasd-controls networked="template:#my-template">
<a-sphere color="#f00"></a-sphere>
</a-entity>

<!-- Remotely instantiated as: -->
<a-entity networked="template:#my-template;networkId:123;">
<a-sphere color="#f00"></a-sphere>
</a-entity>
```
#### Example `attachTemplateToLocal=false`

```html
<a-entity wasd-controls networked="template:#my-template;attachTemplateToLocal:false;">
</a-entity>

<!-- No changes to local entity on instantiation -->

<!-- Remotely instantiated as: -->
<a-entity networked="template:#my-template;networkId:123;">
<a-sphere color="#f00"></a-sphere>
</a-entity>
```

| Parameter | Description | Default
| -------- | ------------ | --------------
| template | A css selector to a script tag stored in `<a-assets>` - [Template documentation](https://github.com/ngokevin/kframe/tree/master/components/template) | ''
| showLocalTemplate | Set to false to hide the template for the local user. This is most useful for hiding your own avatar's head | true
| template | A css selector to a template tag stored in `<a-assets>` | ''
| attachTemplateToLocal | Does not attach the template for the local user when set to false. This is useful when there is different behavior locally and remotely. | true


### Deleting Networked Entities
Expand Down Expand Up @@ -220,8 +265,8 @@ Component data is retrieved by the A-Frame Component `data` property. During the
To sync nested templates setup your HTML nodes like so:

```HTML
<a-entity id="player" networked="template:#player-template;showLocalTemplate:false;" wasd-controls>
<a-entity camera look-controls networked="template:#head-template;showLocalTemplate:false;"></a-entity>
<a-entity id="player" networked="template:#player-template;attachTemplateToLocal:false;" wasd-controls>
<a-entity camera look-controls networked="template:#head-template;attachTemplateToLocal:false;"></a-entity>
<a-entity hand-controls="left" networked="template:#left-hand-template"></a-entity>
<a-entity hand-controls="right" networked="template:#right-hand-template"></a-entity>
</a-entity>
Expand Down

0 comments on commit 35cd94a

Please sign in to comment.