Exemple #1
0
    public override bool RunComponent(RendererComponent.IOutputContext context)
    {
        // Calculate the perturbation ranges for position, location and field of view.
        float fov_min = -fov_radius_ / 2.0f;
        float fov_max = fov_radius_ / 2.0f;
        float pos_min = -position_radius_ / 2.0f;
        float pos_max = position_radius_ / 2.0f;
        float rot_min = -quat_radius_ / 2.0f;
        float rot_max = quat_radius_ / 2.0f;

        if (mode_ == Mode.Jitter || mode_ == Mode.Both)
        {
            // In 'Jitter' mode, apply random local perturbations on top of the
            // original cached state.
            foreach (CameraState camera_state in initial_camera_states_)
            {
                camera_state.camera.fieldOfView             = camera_state.fov + Random.Range(fov_min, fov_max);
                camera_state.camera.transform.localPosition = camera_state.pos + new Vector3(Random.Range(pos_min, pos_max), Random.Range(pos_min, pos_max), Random.Range(pos_min, pos_max));
                Vector3 axis = Random.rotationUniform * Vector3.up;
                camera_state.camera.transform.localRotation = camera_state.rot * Quaternion.AngleAxis(Random.Range(rot_min, rot_max) * Mathf.Rad2Deg, axis);
            }
        }

        if (mode_ == Mode.Orbit || mode_ == Mode.Both)
        {
            // In 'Orbit' mode rotate the camera around a line, going straight
            // up from the 'orbit_center' point.
            foreach (CameraState camera_state in initial_camera_states_)
            {
                camera_state.camera.transform.RotateAround(orbit_center_, Vector3.up, Random.Range(0.0f, 360.0f));
            }
        }

        return(true);
    }
Exemple #2
0
    public override bool RunComponent(RendererComponent.IOutputContext context)
    {
        JointController[] joint_controllers = GetComponentsInChildren <JointController>();
        foreach (JointController joint_controller in joint_controllers)
        {
            switch (joint_controller.joint_type_)
            {
            case JointController.JointType.Ball:
                // Assign a random quaternion sampled uniformly from a
                // sphere to a ball joint.
                joint_controller.UpdateJoint(Random.rotationUniform);
                break;

            case JointController.JointType.Hinge:
                // Assign a random value from the joint limit range to
                // a hinge joint.
                float range_min = joint_controller.range_[0];
                float range_max = joint_controller.range_[1];
                if (range_min > float.MinValue && range_max < float.MaxValue)
                {
                    joint_controller.UpdateJoint(Random.Range(joint_controller.range_[0], joint_controller.range_[1]));
                }
                break;

            case JointController.JointType.Slide:
                // Slide joints don't have ranges, ignore for now.
                break;
            }
            ;
        }
        return(true);
    }
Exemple #3
0
 public override bool RunComponent(RendererComponent.IOutputContext context)
 {
     if (camera_ == null)
     {
         return(false);
     }
     camera_.nearClipPlane = near_clip_;
     camera_.farClipPlane  = far_clip_;
     camera_.fieldOfView   = field_of_view_;
     return(true);
 }
    public override bool RunComponent(RendererComponent.IOutputContext context)
    {
        // Apply the local transformation to the cached original values.
        transform.localPosition = original_translate_ + translate_;
        transform.localRotation = original_rotate_ * rotate_;
        Vector3 new_scale = original_scale_;

        new_scale.Scale(scale_);
        transform.localScale = new_scale;
        return(true);
    }
Exemple #5
0
 public override bool RunComponent(RendererComponent.IOutputContext context)
 {
     foreach (LightHead light_head in light_heads_)
     {
         // Randomize orbit angle [0.0, 360.0) degrees, and use
         // randomization ranges to determine mounting distance
         // and mounting height.
         light_head.SetUp(target_, Random.Range(0.0f, 360.0f), Random.Range(min_light_height_, max_light_height_),
                          Random.Range(min_light_distance_, max_light_distance_));
     }
     return(true);
 }
Exemple #6
0
    public override bool RunComponent(RendererComponent.IOutputContext context)
    {
        foreach (HSVMaterial hsvm in initial_colors_)
        {
            // Calculate the clamped randomization ranges.
            float hue   = Mathf.Repeat(Random.Range(hsvm.h - hue_radius_, hsvm.h + hue_radius_), 1.0f);
            float min_s = Mathf.Max(min_saturation_, hsvm.s - saturation_radius_);
            float max_s = Mathf.Min(max_saturation_, hsvm.s + saturation_radius_);
            float min_v = Mathf.Max(min_value_, hsvm.v - value_radius_);
            float max_v = Mathf.Min(max_value_, hsvm.v + value_radius_);
            float min_e = Mathf.Max(min_emission_, hsvm.e - emission_radius_);
            float max_e = Mathf.Min(max_emission_, hsvm.e + emission_radius_);

            // We will keep the alpha exactly as original, do not randomize
            // transparency.
            float alpha = hsvm.m.color.a;

            // Randomize basic properties.
            if (hsvm.m.HasProperty("_Color"))
            {
                hsvm.m.color = Random.ColorHSV(hue, hue, min_s, max_s, min_v, max_v, alpha, alpha);
            }

            if (hsvm.m.HasProperty("_Metallic"))
            {
                hsvm.m.SetFloat("_Metallic", Random.Range(min_metallic_, max_metallic_));
            }

            if (hsvm.m.HasProperty("_Glossiness"))
            {
                hsvm.m.SetFloat("_Glossiness", Random.Range(min_glossiness_, max_glossiness_));
            }

            // If the material was originally emissive, randomize emission
            // with some probability (blinkenlights).
            if (hsvm.m.IsKeywordEnabled("_EMISSION") && hsvm.m.HasProperty("_EmissionColor"))
            {
                if (emission_probability_ > Random.Range(0.0f, 1.0f))
                {
                    hsvm.m.SetColor(
                        "_EmissionColor",
                        Random.ColorHSV(hue, hue, min_s, max_s, min_v, max_v, alpha, alpha) * Random.Range(min_e, max_e));
                }
                else
                {
                    hsvm.m.SetColor("_EmissionColor", Color.black);
                }
            }
        }
        return(true);
    }
Exemple #7
0
 public bool RunComponents(RendererComponent.IOutputContext context)
 {
     foreach (ComponentInstance component_instance in components_)
     {
         if (component_instance.enabled)
         {
             if (!component_instance.renderer_component.RunComponent(context))
             {
                 Logger.Warning("ComponentManager::RunComponents::Failed running: {0}.", component_instance.name);
             }
         }
     }
     return(true);
 }
Exemple #8
0
    public override bool RunComponent(RendererComponent.IOutputContext context)
    {
        MeshRenderer[] renderers = GetComponentsInChildren <MeshRenderer>();

        foreach (MeshRenderer mesh_renderer in renderers)
        {
            foreach (Material material in mesh_renderer.materials)
            {
                RandomizeMaterial(material);
            }
        }

        return(true);
    }
Exemple #9
0
    public override bool RunComponent(RendererComponent.IOutputContext context)
    {
        // Find all child light emitters.
        Light[] lights = GetComponentsInChildren <Light>();

        // Draw a total scene light intensity number.
        float scene_intensity      = Random.Range(min_scene_intensity_, max_scene_intensity_);
        float sum_intensity_denorm = 0.0f;

        // Go through all lights, and accumulate random weights.
        foreach (Light current_light in lights)
        {
            if (randomize_hue_)
            {
                current_light.color = Random.ColorHSV(0.0f, 1.0f, 0.0f, 0.3f, 0.9f, 1.0f);
            }
            else
            {
                current_light.color = Color.white;
            }

            // Randomize spot angle.
            current_light.spotAngle = Random.Range(min_spotlight_angle_, max_spotlight_angle_);

            // Draw a random light intensity weight, from the configured
            // range.
            current_light.intensity = Random.Range(min_light_intensity_, max_light_intensity_);
            sum_intensity_denorm   += current_light.intensity;
        }

        // Distribute total scene intensity between lights, use:
        //   weight / sum(weights) as factor.
        foreach (Light current_light in lights)
        {
            current_light.intensity = current_light.intensity * scene_intensity / sum_intensity_denorm;
        }

        return(true);
    }
Exemple #10
0
 // This component does nothing each frame. The actual hiding happens on initialization / update.
 public override bool RunComponent(RendererComponent.IOutputContext context)
 {
     return(true);
 }
Exemple #11
0
 public override bool RunComponent(RendererComponent.IOutputContext context)
 {
     transform.LookAt(target_offset_, Vector3.up);
     return(true);
 }