How to create a Hanging lamp?

  Example objects for this post
This post introduces a simple hanging lamp example with a built-in omni light source. The light source is provided by the “lightMacro_m” macro, which can be found in the ARCHICAD Library. For general information about creating a light object check out the How to make a Light object? post.

Sizes and positioning

The two example objects for this post only differ in their placement method: Hanging Lamp Example 1 is placed by the top of the 3D model and is drawn downwards, Hanging Lamp Example 2 is placed by the top of the 3D model and is drawn upwards.

In both cases the height of the lamp model (the ZZYZX parameter) can be adjusted to the actual story height by a GDL editing hotspot. The _hTopCasing, _hBotCasing variables are fix sizes defined in the Master script, the _hShade and _chainHeight variables are calculated from GDL parameters and the fix size variables.

In the ARCHICAD Library the placement method of Hanging Lamp Example 2 is used for standing lamps, as in this case the model is drawn upwards from the placement point. However it can be useful for a hanging lamp, when the bottom of the model should be defined at the placement.

Note that for a proper editing bounding box and floor plan display the ac_bottomlevel and ac_toplevel parameters should be set. Because of this, we do not recommend the Lamp model to be story sensitive: the ZZYZX height should not be calculated from GLOB_ELEVATION and GLOB_HSTORY_HEIGHT global variables, as these global variables are not working in parameterscript. In this case the ZZYZX, ac_toplevel and ac_bottomlevel parameters cannot be set, the editing bounding box and floor plan display will not be correct.

Lamp model scripts

In the 3D scripts of the example objects the parts of the lamps are modeled from the bottom to the top. Therefore at the Hanging Lamp Example 1 object the 3D script starts with the coordinate system re-position from the top to the bottom:

! =============================================================
! Create Lamp model from bottom to top
! =============================================================
addz -ZZYZX

Otherwise the introduced 3D scripts of Hanging Lamp Example 1 and Hanging Lamp Example 2 are identical.

Note that in the example objects there are 3D editing hotspots for ZZYZX and heightLamp parameters. These hotspot editings are scripted in different directions in Hanging Lamp Example 1 and Hanging Lamp Example 2.

Size definitions

As some sizes are used in the 2D and 3D scripts as well, the fix and calculated sizes are defined in the masterscript:

! =============================================================
! Main Size Definition
! =============================================================
_hBotCasing		= 0.03
_hTopCasing		= 0.08
_rShadeTop		= 0.047
_hBulb			= 0.08
_rChain			= 0.004
_hChain		 	= ZZYZX - heightLamp - _hTopCasing
_hShade			= heightLamp - _hBotCasing

Lamp Shade model

The lamp shade is a parallelogram revolved around the Z axis of the lamp. The inner side of the lamp shade emits light based on the light intensity set by the User.

To create the surface with light emission the DEFINE MATERIAL BASED_ON command is used. For this command the name of the shade surface can be requested by the “Name_of_material” request option. The emission color RGB are set by the light source color RGB, the emission attenuation is set based on the light intensity.

! -------------------------------------------------------------
! Lamp Shade
! -------------------------------------------------------------
rotz -90
roty -90

material shadeSurface

if gs_light_switch and gs_light_intensity > 0 then    
    revolve 3, 360, 0,
            _hShade,    _rShadeTop,     0,
            0,          A/2,            0,
            0,          A/2 - 0.01,     0

    ! lightsource is lit: inner side is bright
    r = request ("Name_of_material", shadeSurface, _matName)
    if r then
        define material "shadeMatInner" based_on _matName parameters gs_mat_transparent = 0,
            gs_mat_emission_r = gs_color_red,
            gs_mat_emission_g = gs_color_green,
            gs_mat_emission_b = gs_color_blue,
            gs_mat_emission_att = gs_light_switch * 2 * gs_light_intensity / 100
        material "shadeMatInner"
    else
        material shadeSurface
    endif
    revolve 2, 360, 0,
            0,           A/2 - 0.01,         0,
            _hShade,     _rShadeTop - 0.01,  0
else
    revolve 5, 360, 0,
            _hShade,     _rShadeTop,         0,
            0,           A/2,                0,
            0,           A/2 - 0.01,         0,
            _hShade,     _rShadeTop - 0.01,  0,
            _hShade,     _rShadeTop,         -1
endif

body -1
del 2

Other Lamp model parts

A top and a bottom casing is modeled for the hanging lamp, which are connected by a lamp chain. The casings have fix sizes, the chain height is calculated from the ZZYZX and heightLamp parameters and the _hTopCasing fix size variable.

! -------------------------------------------------------------
! Bottom Casing
! -------------------------------------------------------------
material stringSurface
addz _hShade
cone _hBotCasing, 0.05, 0.04, 90, 90
del 1

! -------------------------------------------------------------
! Chain
! -------------------------------------------------------------
addz heightLamp 	
cylind _hChain, _rChain
del 1

! -------------------------------------------------------------
! Top Casing
! -------------------------------------------------------------
addz heightLamp + _hChain
cone _hTopCasing, 0.035, 0.04, 90, 90
del 1

Inside the lamp shade a light bulb model is created with different surface and fix sizes.

! -------------------------------------------------------------
! Light Bulb
! -------------------------------------------------------------
material bulbSurface
rotz -90
roty -90
addx _hShade - _hBulb

revolve 5, 360, 1+2,
        0,		0,		1,
        0,		1,		800,
        _hBulb*2/3,	0.25*_hBulb,	1001,
        _hBulb,		0.15*_hBulb,	1001,
        _hBulb,		0.15*_hBulb,	0
del 3

Light source

For the light source of the hanging lamp call the “lightMacro_m” with omni light settings – for more details see the How to make a Light object? post.

if gs_light_switch then

    lightUnID = 1000

    ! =============================================================
    ! Non Visible Omni Light
    ! =============================================================
    call "lightMacro_m" parameters gs_light_switch         = gs_light_switch,
                                   gs_color_red            = gs_color_red,
                                   gs_color_green          = gs_color_green,
                                   gs_color_blue           = gs_color_blue,
                                   gs_light_intensity      = gs_light_intensity,
                                   iColorPreset            = iColorPreset,
                                   iLightGroupType         = 2,    ! LIGHTGROUP_BUILTIN_OMNI
                                   iC4dDetAreaShape        = 3,    ! AREASHAPE_SPHERE
                                   c4dDetAreaX             = 0.03,
                                   c4dDetAreaY             = 0.03,
                                   c4dDetAreaZ             = 0.03,
                                   bGenShadow              = bGenShadow,
                                   iShadowQuality          = iShadowQuality,
                                   iShadowQualityGroupType = 2,
                                   iC4dGenVisibility       = 1,
                                   bDetShowFalloff         = 1,
                                   iFalloffType            = 1,     ! FALLOFFTYPE_OMNI
                                   c4dDetRadius            = c4dDetRadius,
                                   c4dPhoPhotometric       = c4dPhoPhotometric,
                                   iC4dPhoUnit             = iC4dPhoUnit,
                                   photoIntensityLumen     = photoIntensityLumen,
                                   photoIntensityCandela   = photoIntensityCandela,
                                   bShowIllumination3D     = bShowIllumination3D,
                                   gs_cont_pen             = gs_cont_pen,
                                   penIllumination         = penIllumination,
                                   lightUnID               = lightUnID

endif

Parameter settings

The parameter ranges of the lamp are handled in the parameter script. The “B” size is not used, so it is hidden.

hideparameter "B"

values "ZZYZX" 		range (heightLamp + _hTopCasing, )
values "heightLamp"	range (_hBotCasing, ZZYZX -  _hTopCasing)

Parameters ac_bottomlevel and ac_toplevel should be set for a proper bounding box editing and for correctly displaying the object at the all relevant stories display option.

At Hanging Lamp Example 1 the lamp is drawn from the top of the model, so the ac_bottomlevel is set -ZZYZX, the ac_toplevel is set to 0:

parameters ac_bottomlevel = -ZZYZX
parameters ac_toplevel = 0

At Hanging Lamp Example 2 the lamp is drawn from the bottom of the model, so the ac_bottomlevel is set 0, the ac_toplevel is set to ZZYZX:

parameters ac_bottomlevel = 0
parameters ac_toplevel = ZZYZX

For the proper parameter handling (locking, hiding, value range definitions, etc.) the “lightMacro_m” macro should be called from the parameterscript as well:

call "lightMacro_m" parameters all	iLightGroupType	    = 2, ! LIGHTGROUP_BUILTIN_OMNI
					bShow3D		    = 1,
					bEnable3DModelTypes = 0,
					bEnableSymbolic2D   = 0

The result of this example object can be seen in the rendered picture below.