This repository was archived by the owner on Oct 19, 2020. It is now read-only.
File tree 14 files changed +69
-34
lines changed
src/scene/structure/parametric-objects
14 files changed +69
-34
lines changed Original file line number Diff line number Diff line change 6
6
import generateNormals from '../../../utils/data3d/buffer/get-normals'
7
7
import generateUvs from '../../../utils/data3d/buffer/get-uvs'
8
8
import getMaterials3d from './common/get-materials'
9
+ import applyDefaultMaterials from './common/apply-default-materials'
9
10
10
11
export default function ( attributes ) {
11
- return Promise . all ( [
12
- generateMeshes3d ( attributes ) ,
13
- getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
14
- ] ) . then ( results => ( {
15
- meshes : results [ 0 ] ,
16
- materials : results [ 1 ]
17
- } ) )
18
- }
12
+ attributes . materials = applyDefaultMaterials ( attributes . materials , getDefaultMaterials ( ) ) ;
13
+ return Promise . all ( [
14
+ generateMeshes3d ( attributes ) ,
15
+ getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
16
+ ] ) . then ( results => ( {
17
+ meshes : results [ 0 ] ,
18
+ materials : results [ 1 ]
19
+ } ) )
20
+ }
19
21
20
22
export function getDefaultMaterials ( ) {
21
23
return {
Original file line number Diff line number Diff line change @@ -5,16 +5,18 @@ import generateUvs from '../../../utils/data3d/buffer/get-uvs'
5
5
import generatePolygonBuffer from '../../../utils/data3d/buffer/get-polygon'
6
6
import generateExtrusionBuffer from '../../../utils/data3d/buffer/get-extrusion'
7
7
import getMaterials3d from './common/get-materials'
8
+ import applyDefaultMaterials from './common/apply-default-materials'
8
9
9
10
export default function ( attributes ) {
10
- return Promise . all ( [
11
- generateMeshes3d ( attributes ) ,
12
- getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
13
- ] ) . then ( results => ( {
14
- meshes : results [ 0 ] ,
15
- materials : results [ 1 ]
16
- } ) )
17
- }
11
+ attributes . materials = applyDefaultMaterials ( attributes . materials , getDefaultMaterials ( ) ) ;
12
+ return Promise . all ( [
13
+ generateMeshes3d ( attributes ) ,
14
+ getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
15
+ ] ) . then ( results => ( {
16
+ meshes : results [ 0 ] ,
17
+ materials : results [ 1 ]
18
+ } ) )
19
+ }
18
20
19
21
export function getDefaultMaterials ( ) {
20
22
return {
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ import cloneDeep from 'lodash/cloneDeep'
4
+
5
+ // apply default material names to object in case material key is unset
6
+ export default function ( materials , defaults ) {
7
+
8
+ if ( ! defaults ) {
9
+ console . error ( 'No default materials set' )
10
+ defaults = { }
11
+ }
12
+
13
+ if ( ! materials ) return Promise . resolve ( cloneDeep ( defaults ) )
14
+
15
+ Object . keys ( defaults ) . forEach ( function ( d ) {
16
+ if ( ! materials [ d ] ) materials [ d ] = defaults [ d ]
17
+ } )
18
+
19
+ return materials
20
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
1
3
import cloneDeep from 'lodash/cloneDeep'
2
4
import materialLibrary from './material-lib.js'
3
5
4
- export default function getMaterial ( material ) {
6
+ export default function ( material ) {
5
7
var STORAGE_URL = 'https://storage.3d.io/'
6
8
var mat = materialLibrary [ material ]
7
9
@@ -18,4 +20,4 @@ export default function getMaterial(material) {
18
20
}
19
21
} )
20
22
return attr
21
- }
23
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
1
3
import cloneDeep from 'lodash/cloneDeep'
2
4
import materialLibrary from './material-lib.js'
3
5
4
- export default function getMaterials3d ( materials , defaults ) {
5
- if ( ! defaults ) {
6
- console . error ( 'No default materials set' )
7
- defaults = { }
8
- }
9
- if ( ! materials ) return Promise . resolve ( cloneDeep ( defaults ) )
10
- Object . keys ( defaults ) . forEach ( function ( d ) {
11
- if ( ! materials [ d ] ) materials [ d ] = defaults [ d ]
12
- } )
6
+ // resolve standard materials if necessary
7
+ export default function ( materials , defaults ) {
13
8
Object . keys ( materials ) . map ( meshName => {
14
9
if ( typeof ( materials [ meshName ] ) === "string" ) {
15
10
materials [ meshName ] = getMaterial ( materials [ meshName ] )
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
1
3
export default {
2
4
"basic-floor" : {
3
5
"meta" : {
Original file line number Diff line number Diff line change 3
3
import generateNormals from '../../../utils/data3d/buffer/get-normals'
4
4
import generateUvs from '../../../utils/data3d/buffer/get-uvs'
5
5
import getMaterials3d from './common/get-materials'
6
+ import applyDefaultMaterials from './common/apply-default-materials'
6
7
7
8
export default function ( attributes ) {
9
+ attributes . materials = applyDefaultMaterials ( attributes . materials , getDefaultMaterials ( ) ) ;
8
10
return Promise . all ( [
9
11
generateMeshes3d ( attributes ) ,
10
12
getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
Original file line number Diff line number Diff line change @@ -5,8 +5,10 @@ import generateExtrusionBuffer from '../../../utils/data3d/buffer/get-extrusion'
5
5
import generateNormals from '../../../utils/data3d/buffer/get-normals'
6
6
import generateUvs from '../../../utils/data3d/buffer/get-uvs'
7
7
import getMaterials3d from './common/get-materials'
8
+ import applyDefaultMaterials from './common/apply-default-materials'
8
9
9
10
export default function ( attributes ) {
11
+ attributes . materials = applyDefaultMaterials ( attributes . materials , getDefaultMaterials ( ) ) ;
10
12
return Promise . all ( [
11
13
generateMeshes3d ( attributes ) ,
12
14
getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
Original file line number Diff line number Diff line change @@ -5,13 +5,15 @@ import generateExtrusionBuffer from '../../../utils/data3d/buffer/get-extrusion'
5
5
import generateNormals from '../../../utils/data3d/buffer/get-normals'
6
6
import generateUvs from '../../../utils/data3d/buffer/get-uvs'
7
7
import getMaterials3d from './common/get-materials'
8
+ import applyDefaultMaterials from './common/apply-default-materials'
8
9
9
10
import loadData3d from '../../../utils/data3d/load'
10
11
11
12
export default function ( attributes ) {
13
+ attributes . materials = applyDefaultMaterials ( attributes . materials , getDefaultMaterials ( ) ) ;
12
14
return Promise . all ( [
13
15
generateMeshes3d ( attributes ) ,
14
- getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
16
+ getMaterials3d ( attributes . materials )
15
17
] ) . then ( results => ( {
16
18
meshes : results [ 0 ] ,
17
19
materials : results [ 1 ]
@@ -35,11 +37,9 @@ export function getDefaultMaterials(){
35
37
}
36
38
}
37
39
38
- function generateMeshes3d ( a ) {
39
- console . log ( 'generateMeshes3d' , a )
40
+ export function generateMeshes3d ( a ) {
40
41
41
42
// external meshes
42
-
43
43
var externalMeshes = {
44
44
singleSink : 'https://storage.3d.io/535e624259ee6b0200000484/170429-0355-60hukz/bf4e4a56-ed95-4b58-a214-4b1a0a84ae0e.gz.data3d.buffer' ,
45
45
doubleSink : 'https://storage.3d.io/535e624259ee6b0200000484/170429-2156-7ufbnv/df481313-8fb4-48da-bc28-0369b08a2c6a.gz.data3d.buffer' ,
Original file line number Diff line number Diff line change @@ -6,9 +6,10 @@ import generateExtrusionBuffer from '../../../utils/data3d/buffer/get-extrusion'
6
6
import generateNormals from '../../../utils/data3d/buffer/get-normals'
7
7
import cloneDeep from 'lodash/cloneDeep'
8
8
import getMaterials3d from './common/get-materials'
9
-
9
+ import applyDefaultMaterials from './common/apply-default-materials'
10
10
11
11
export default function ( attributes ) {
12
+ attributes . materials = applyDefaultMaterials ( attributes . materials , getDefaultMaterials ( ) ) ;
12
13
return Promise . all ( [
13
14
generateMeshes3d ( attributes ) ,
14
15
getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
Original file line number Diff line number Diff line change @@ -5,12 +5,13 @@ import generateExtrusionBuffer from '../../../utils/data3d/buffer/get-extrusion'
5
5
import generateNormals from '../../../utils/data3d/buffer/get-normals'
6
6
import generateUvs from '../../../utils/data3d/buffer/get-uvs'
7
7
import getMaterials3d from './common/get-materials'
8
-
9
8
import sortBy from 'lodash/sortBy'
10
9
import loadData3d from '../../../utils/data3d/load'
10
+ import applyDefaultMaterials from './common/apply-default-materials'
11
11
12
12
13
13
export default function ( attributes ) {
14
+ attributes . materials = applyDefaultMaterials ( attributes . materials , getDefaultMaterials ( ) ) ;
14
15
return Promise . all ( [
15
16
generateMeshes3d ( attributes ) ,
16
17
getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
Original file line number Diff line number Diff line change @@ -5,8 +5,10 @@ import generateNormals from '../../../utils/data3d/buffer/get-normals'
5
5
import generateUvs from '../../../utils/data3d/buffer/get-uvs'
6
6
import cloneDeep from 'lodash/cloneDeep'
7
7
import getMaterials3d from './common/get-materials'
8
+ import applyDefaultMaterials from './common/apply-default-materials'
8
9
9
10
export default function ( attributes ) {
11
+ attributes . materials = applyDefaultMaterials ( attributes . materials , getDefaultMaterials ( ) ) ;
10
12
return Promise . all ( [
11
13
generateMeshes3d ( attributes ) ,
12
14
getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
Original file line number Diff line number Diff line change @@ -5,11 +5,13 @@ import generateExtrusionBuffer from '../../../utils/data3d/buffer/get-extrusion'
5
5
import generateNormals from '../../../utils/data3d/buffer/get-normals'
6
6
import generateUvs from '../../../utils/data3d/buffer/get-uvs'
7
7
import getMaterials3d from './common/get-materials'
8
+ import applyDefaultMaterials from './common/apply-default-materials'
8
9
9
10
import sortBy from 'lodash/sortBy'
10
11
import loadData3d from '../../../utils/data3d/load'
11
12
12
13
export default function ( attributes ) {
14
+ attributes . materials = applyDefaultMaterials ( attributes . materials , getDefaultMaterials ( ) ) ;
13
15
return Promise . all ( [
14
16
generateMeshes3d ( attributes ) ,
15
17
getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
@@ -30,7 +32,7 @@ export function getDefaultMaterials(){
30
32
}
31
33
}
32
34
33
- function generateMeshes3d ( a ) {
35
+ export function generateMeshes3d ( a ) {
34
36
// get children
35
37
var children = a . children
36
38
children = sortBy ( children , function ( model ) {
Original file line number Diff line number Diff line change 3
3
import generatePolygonBuffer from '../../../utils/data3d/buffer/get-polygon'
4
4
import generateNormals from '../../../utils/data3d/buffer/get-normals'
5
5
import getMaterials3d from './common/get-materials'
6
+ import applyDefaultMaterials from './common/apply-default-materials'
6
7
7
8
export default function ( attributes , parentAttributes ) {
9
+ attributes . materials = applyDefaultMaterials ( attributes . materials , getDefaultMaterials ( ) ) ;
8
10
return Promise . all ( [
9
11
generateMeshes3d ( attributes , parentAttributes ) ,
10
12
getMaterials3d ( attributes . materials , getDefaultMaterials ( ) )
You can’t perform that action at this time.
0 commit comments