Changeset View
Changeset View
Standalone View
Standalone View
io_scene_x3d/import_x3d.py
| Show First 20 Lines • Show All 2,784 Lines • ▼ Show 20 Lines | def appearance_LoadTexture(tex_node, ancestry, node): | ||||
| # No cached texture, load it. | # No cached texture, load it. | ||||
| if tex_node.getSpec() == 'ImageTexture': | if tex_node.getSpec() == 'ImageTexture': | ||||
| bpyima = appearance_LoadImageTexture(tex_node, ancestry, node) | bpyima = appearance_LoadImageTexture(tex_node, ancestry, node) | ||||
| else: # PixelTexture | else: # PixelTexture | ||||
| bpyima = appearance_LoadPixelTexture(tex_node, ancestry) | bpyima = appearance_LoadPixelTexture(tex_node, ancestry) | ||||
| if bpyima: # Loading can still fail | if bpyima: # Loading can still fail | ||||
| repeat_s = tex_node.getFieldAsBool('repeatS', True, ancestry) | repeat_s = tex_node.getFieldAsBool('repeatS', True, ancestry) | ||||
| bpyima.use_clamp_x = not repeat_s | bpyima.use_clight_x = not repeat_s | ||||
| repeat_t = tex_node.getFieldAsBool('repeatT', True, ancestry) | repeat_t = tex_node.getFieldAsBool('repeatT', True, ancestry) | ||||
| bpyima.use_clamp_y = not repeat_t | bpyima.use_clight_y = not repeat_t | ||||
| # Update the desc-based cache | # Update the desc-based cache | ||||
| if desc: | if desc: | ||||
| texture_cache[desc] = bpyima | texture_cache[desc] = bpyima | ||||
| # Update the USE-based cache | # Update the USE-based cache | ||||
| if tex_node.canHaveReferences(): | if tex_node.canHaveReferences(): | ||||
| tex_node.parsed = bpyima | tex_node.parsed = bpyima | ||||
| ▲ Show 20 Lines • Show All 339 Lines • ▼ Show 20 Lines | def importLamp_PointLight(node, ancestry): | ||||
| # ambientIntensity = node.getFieldAsFloat('ambientIntensity', 0.0, ancestry) # TODO | # ambientIntensity = node.getFieldAsFloat('ambientIntensity', 0.0, ancestry) # TODO | ||||
| # attenuation = node.getFieldAsFloatTuple('attenuation', (1.0, 0.0, 0.0), ancestry) # TODO | # attenuation = node.getFieldAsFloatTuple('attenuation', (1.0, 0.0, 0.0), ancestry) # TODO | ||||
| color = node.getFieldAsFloatTuple('color', (1.0, 1.0, 1.0), ancestry) | color = node.getFieldAsFloatTuple('color', (1.0, 1.0, 1.0), ancestry) | ||||
| intensity = node.getFieldAsFloat('intensity', 1.0, ancestry) # max is documented to be 1.0 but some files have higher. | intensity = node.getFieldAsFloat('intensity', 1.0, ancestry) # max is documented to be 1.0 but some files have higher. | ||||
| location = node.getFieldAsFloatTuple('location', (0.0, 0.0, 0.0), ancestry) | location = node.getFieldAsFloatTuple('location', (0.0, 0.0, 0.0), ancestry) | ||||
| # is_on = node.getFieldAsBool('on', True, ancestry) # TODO | # is_on = node.getFieldAsBool('on', True, ancestry) # TODO | ||||
| radius = node.getFieldAsFloat('radius', 100.0, ancestry) | radius = node.getFieldAsFloat('radius', 100.0, ancestry) | ||||
| bpylamp = bpy.data.lamps.new(vrmlname, 'POINT') | bpylamp = bpy.data.lights.new(vrmlname, 'POINT') | ||||
| bpylamp.energy = intensity | bpylamp.energy = intensity | ||||
| bpylamp.distance = radius | bpylamp.distance = radius | ||||
| bpylamp.color = color | bpylamp.color = color | ||||
| mtx = Matrix.Translation(Vector(location)) | mtx = Matrix.Translation(Vector(location)) | ||||
| return bpylamp, mtx | return bpylamp, mtx | ||||
| def importLamp_DirectionalLight(node, ancestry): | def importLamp_DirectionalLight(node, ancestry): | ||||
| vrmlname = node.getDefName() | vrmlname = node.getDefName() | ||||
| if not vrmlname: | if not vrmlname: | ||||
| vrmlname = 'DirectLight' | vrmlname = 'DirectLight' | ||||
| # ambientIntensity = node.getFieldAsFloat('ambientIntensity', 0.0) # TODO | # ambientIntensity = node.getFieldAsFloat('ambientIntensity', 0.0) # TODO | ||||
| color = node.getFieldAsFloatTuple('color', (1.0, 1.0, 1.0), ancestry) | color = node.getFieldAsFloatTuple('color', (1.0, 1.0, 1.0), ancestry) | ||||
| direction = node.getFieldAsFloatTuple('direction', (0.0, 0.0, -1.0), ancestry) | direction = node.getFieldAsFloatTuple('direction', (0.0, 0.0, -1.0), ancestry) | ||||
| intensity = node.getFieldAsFloat('intensity', 1.0, ancestry) # max is documented to be 1.0 but some files have higher. | intensity = node.getFieldAsFloat('intensity', 1.0, ancestry) # max is documented to be 1.0 but some files have higher. | ||||
| # is_on = node.getFieldAsBool('on', True, ancestry) # TODO | # is_on = node.getFieldAsBool('on', True, ancestry) # TODO | ||||
| bpylamp = bpy.data.lamps.new(vrmlname, 'SUN') | bpylamp = bpy.data.lights.new(vrmlname, 'SUN') | ||||
| bpylamp.energy = intensity | bpylamp.energy = intensity | ||||
| bpylamp.color = color | bpylamp.color = color | ||||
| # lamps have their direction as -z, yup | # lamps have their direction as -z, yup | ||||
| mtx = Vector(direction).to_track_quat('-Z', 'Y').to_matrix().to_4x4() | mtx = Vector(direction).to_track_quat('-Z', 'Y').to_matrix().to_4x4() | ||||
| return bpylamp, mtx | return bpylamp, mtx | ||||
| Show All 11 Lines | def importLamp_SpotLight(node, ancestry): | ||||
| color = node.getFieldAsFloatTuple('color', (1.0, 1.0, 1.0), ancestry) | color = node.getFieldAsFloatTuple('color', (1.0, 1.0, 1.0), ancestry) | ||||
| cutOffAngle = node.getFieldAsFloat('cutOffAngle', 0.785398, ancestry) * 2.0 # max is documented to be 1.0 but some files have higher. | cutOffAngle = node.getFieldAsFloat('cutOffAngle', 0.785398, ancestry) * 2.0 # max is documented to be 1.0 but some files have higher. | ||||
| direction = node.getFieldAsFloatTuple('direction', (0.0, 0.0, -1.0), ancestry) | direction = node.getFieldAsFloatTuple('direction', (0.0, 0.0, -1.0), ancestry) | ||||
| intensity = node.getFieldAsFloat('intensity', 1.0, ancestry) # max is documented to be 1.0 but some files have higher. | intensity = node.getFieldAsFloat('intensity', 1.0, ancestry) # max is documented to be 1.0 but some files have higher. | ||||
| location = node.getFieldAsFloatTuple('location', (0.0, 0.0, 0.0), ancestry) | location = node.getFieldAsFloatTuple('location', (0.0, 0.0, 0.0), ancestry) | ||||
| # is_on = node.getFieldAsBool('on', True, ancestry) # TODO | # is_on = node.getFieldAsBool('on', True, ancestry) # TODO | ||||
| radius = node.getFieldAsFloat('radius', 100.0, ancestry) | radius = node.getFieldAsFloat('radius', 100.0, ancestry) | ||||
| bpylamp = bpy.data.lamps.new(vrmlname, 'SPOT') | bpylamp = bpy.data.lights.new(vrmlname, 'SPOT') | ||||
| bpylamp.energy = intensity | bpylamp.energy = intensity | ||||
| bpylamp.distance = radius | bpylamp.distance = radius | ||||
| bpylamp.color = color | bpylamp.color = color | ||||
| bpylamp.spot_size = cutOffAngle | bpylamp.spot_size = cutOffAngle | ||||
| if beamWidth > cutOffAngle: | if beamWidth > cutOffAngle: | ||||
| bpylamp.spot_blend = 0.0 | bpylamp.spot_blend = 0.0 | ||||
| else: | else: | ||||
| if cutOffAngle == 0.0: # this should never happen! | if cutOffAngle == 0.0: # this should never happen! | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | if not name: | ||||
| name = 'Transform' | name = 'Transform' | ||||
| bpyob = node.blendData = node.blendObject = bpy.data.objects.new(name, None) | bpyob = node.blendData = node.blendObject = bpy.data.objects.new(name, None) | ||||
| bpyscene.objects.link(bpyob).select = True | bpyscene.objects.link(bpyob).select = True | ||||
| bpyob.matrix_world = getFinalMatrix(node, None, ancestry, global_matrix) | bpyob.matrix_world = getFinalMatrix(node, None, ancestry, global_matrix) | ||||
| # so they are not too annoying | # so they are not too annoying | ||||
| bpyob.empty_draw_type = 'PLAIN_AXES' | bpyob.empty_display_type = 'PLAIN_AXES' | ||||
| bpyob.empty_draw_size = 0.2 | bpyob.empty_display_size = 0.2 | ||||
| #def importTimeSensor(node): | #def importTimeSensor(node): | ||||
| def action_fcurve_ensure(action, data_path, array_index): | def action_fcurve_ensure(action, data_path, array_index): | ||||
| for fcu in action.fcurves: | for fcu in action.fcurves: | ||||
| if fcu.data_path == data_path and fcu.array_index == array_index: | if fcu.data_path == data_path and fcu.array_index == array_index: | ||||
| return fcu | return fcu | ||||
| ▲ Show 20 Lines • Show All 321 Lines • Show Last 20 Lines | |||||