@@ -1591,20 +1591,66 @@ THREE.GLTFExporter.prototype = {
15911591
15921592 }
15931593
1594+ function processLight ( light ) {
1595+
1596+ var lightDef = { } ;
1597+
1598+ if ( light . name ) lightDef . name = light . name ;
1599+
1600+ lightDef . color = light . color . toArray ( ) ;
1601+
1602+ lightDef . intensity = light . intensity ;
1603+
1604+ if ( light . isDirectionalLight ) {
1605+
1606+ lightDef . type = 'directional' ;
1607+
1608+ } else if ( light . isPointLight ) {
1609+
1610+ lightDef . type = 'point' ;
1611+ lightDef . range = light . distance ;
1612+
1613+ } else if ( light . isSpotLight ) {
1614+
1615+ lightDef . type = 'spot' ;
1616+ lightDef . range = light . distance ;
1617+ lightDef . spot = { } ;
1618+ lightDef . spot . innerConeAngle = ( light . penumbra - 1.0 ) * light . angle * - 1.0 ;
1619+ lightDef . spot . outerConeAngle = light . angle ;
1620+
1621+ }
1622+
1623+ if ( light . decay !== undefined && light . decay !== 2 ) {
1624+
1625+ console . warn ( 'THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, '
1626+ + 'and expects light.decay=2.' ) ;
1627+
1628+ }
1629+
1630+ if ( light . target
1631+ && ( light . target . parent !== light
1632+ || light . target . position . x !== 0
1633+ || light . target . position . y !== 0
1634+ || light . target . position . z !== - 1 ) ) {
1635+
1636+ console . warn ( 'THREE.GLTFExporter: Light direction may be lost. For best results, '
1637+ + 'make light.target a child of the light with position 0,0,-1.' ) ;
1638+
1639+ }
1640+
1641+ var lights = outputJSON . extensions [ 'KHR_lights_punctual' ] . lights ;
1642+ lights . push ( lightDef ) ;
1643+ return lights . length - 1 ;
1644+
1645+ }
1646+
15941647 /**
15951648 * Process Object3D node
15961649 * @param {THREE.Object3D } node Object3D to processNode
15971650 * @return {Integer } Index of the node in the nodes list
15981651 */
15991652 function processNode ( object ) {
16001653
1601- if ( object . isLight ) {
1602-
1603- console . warn ( 'GLTFExporter: Unsupported node type:' , object . constructor . name ) ;
1604- return null ;
1605-
1606- }
1607-
16081654 if ( ! outputJSON . nodes ) {
16091655
16101656 outputJSON . nodes = [ ] ;
@@ -1675,6 +1721,24 @@ THREE.GLTFExporter.prototype = {
16751721
16761722 gltfNode . camera = processCamera ( object ) ;
16771723
1724+ } else if ( object . isDirectionalLight || object . isPointLight || object . isSpotLight ) {
1725+
1726+ if ( ! extensionsUsed [ 'KHR_lights_punctual' ] ) {
1727+
1728+ outputJSON . extensions = outputJSON . extensions || { } ;
1729+ outputJSON . extensions [ 'KHR_lights_punctual' ] = { lights : [ ] } ;
1730+ extensionsUsed [ 'KHR_lights_punctual' ] = true ;
1731+
1732+ }
1733+
1734+ gltfNode . extensions = gltfNode . extensions || { } ;
1735+ gltfNode . extensions [ 'KHR_lights_punctual' ] = { light : processLight ( object ) } ;
1736+
1737+ } else if ( object . isLight ) {
1738+
1739+ console . warn ( 'THREE.GLTFExporter: Only directional, point, and spot lights are supported.' ) ;
1740+ return null ;
1741+
16781742 }
16791743
16801744 if ( object . isSkinnedMesh ) {
0 commit comments