Skip to content

Instantly share code, notes, and snippets.

@drcmda
Last active March 21, 2016 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drcmda/0abaeab81be4deee29c6 to your computer and use it in GitHub Desktop.
Save drcmda/0abaeab81be4deee29c6 to your computer and use it in GitHub Desktop.
client assembly via custom factory first draft
// Application ------------------------------------------------------------------------
import AssemblyFactory from 'factory/assembly'
// Create factory, link it to the scene, or whereever models are stored in the application
let factory = new AssemblyFactory(scene);
// Request a table
server.request('_O.CreateTable()', factory);
// Request a clone
server.request('_O.Clone(0)', factory);
// Module -----------------------------------------------------------------------------
// To be shippped as module under factory/assembly.js in the official library's repo
export default AssemblyFactory class {
constructor(pool) {
this.pool = pool;
return attribs => {
switch (attribs.type) {
case Parser.Factory.Link:
let { ref, matrix } = attribs.data;
let item = this.pool.find(obj => obj.userData.id === ref);
if (item) {
// Add reference to the current model, transform it
attribs.model.add(item.clone().applyMatrix(matrix));
}
case Parser.Factory.Finished:
// Add finished assembly to the application pool
this.pool.add(attribs.model)
break;
}
}
}
}
// Responses --------------------------------------------------------------------------
// Response for: _O.CreateTable():
{
command: 'Assembly',
id: 0,
parts: [
{ command: 'Blob', data: '...tischplatte (id1), mesh...' },
{ command: 'Blob', data: '...tischbein (id2), mesh...' },
{ command: 'Link', id: 3, ref: 2, matrix: [1,0,0,0,1,0,0,0,1,0,0,0,1] },
{ command: 'Link', id: 4, ref: 2, matrix: [1,0,0,0,1,0,0,0,1,10,10,20,1] },
{ command: 'Link', id: 5, ref: 2, matrix: [1,0,0,0,1,0,0,0,1,30,20,40,1] },
{ command: 'constraint', type: 'distance', ids: [2, 3], value: 40 }
]
}
// Response for: _O.Clone(0):
{
command: 'Assembly',
id: 6,
parts: [
{ command: 'Link', id: 7, ref: 0, matrix: [1,0,0,0,1,0,0,0,1,50,30,30,1] }
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment