replace_objects (CWrp::File8WVR)

    # File ../lib/roller/CWRP.rb, line 628
      def replace_objects(replacements)
        replaced = 0

        reset_progress 'Replacing objects', @objects.size / OBJECTS_PER_PROGRESS

        @objects.each_with_index do |object, index|
          # If replacement has been defined, replace it.
          replacement = replacements[object.name]
          unless replacement.nil?
            new_object = replacement[rand(replacement.size)]

            object.name = new_object[:name]

            # Offset the object. The X/Y offset must be rotated based on the
            # object's orientation, but Z is added directly.
            model_offset = new_object[:offset]
            world_offset = rotate(model_offset[0], model_offset[1], object.dir)
            object.position.x += world_offset[0]
            object.position.y += world_offset[1]
            object.position.z += model_offset[2]

            replaced += 1
          end

          increment_progress if index.modulo(OBJECTS_PER_PROGRESS) == 0
        end

        replaced
      end