Пример #1
0
        private void ProcessShape(SceneReaderContext context)
        {
            Primitive prim = null;
            AreaLight area = null;

            if (!context.CurrentTransform.IsAnimated)
            {
                // Create primitive for static shape.

                var shape = Factories.MakeShape(ImplementationType,
                                                context.CurrentTransform[0], context.GraphicsState.ReverseOrientation,
                                                Parameters);
                var material = context.GraphicsState.CreateMaterial(
                    Parameters, context.CurrentTransform[0]);

                // Possibly create area light for shape.
                if (!string.IsNullOrEmpty(context.GraphicsState.AreaLight))
                {
                    area = Factories.MakeAreaLight(
                        context.GraphicsState.AreaLight,
                        context.CurrentTransform[0],
                        context.GraphicsState.AreaLightParams,
                        shape);
                }
                prim = new GeometricPrimitive(shape, material, area);
            }
            else
            {
                // Create primitive for animated shape.

                var shape = Factories.MakeShape(ImplementationType, new Transform(),
                                                context.GraphicsState.ReverseOrientation, Parameters);
                var material = context.GraphicsState.CreateMaterial(
                    Parameters, context.CurrentTransform[0]);

                // Get animatedWorldToObject transform for shape.
                var worldToObj0           = Transform.Invert(context.CurrentTransform[0]);
                var worldToObj1           = Transform.Invert(context.CurrentTransform[1]);
                var animatedWorldToObject = new AnimatedTransform(
                    worldToObj0, context.RenderOptions.TransformStartTime,
                    worldToObj1, context.RenderOptions.TransformEndTime);

                Primitive basePrim = new GeometricPrimitive(shape, material, null);
                if (!basePrim.CanIntersect)
                {
                    // Refine animated shape and create BVH if more than one shape created.
                    var refinedPrimitives = basePrim.FullyRefine();
                    if (refinedPrimitives.Count == 0)
                    {
                        return;
                    }
                    basePrim = (refinedPrimitives.Count > 1)
                        ? new BoundingVolumeHierarchyAccelerator(refinedPrimitives)
                        : refinedPrimitives[0];
                }
                prim = new TransformedPrimitive(basePrim, animatedWorldToObject);
            }

            // Add primitive to scene or current instance.
            if (context.RenderOptions.CurrentInstance != null)
            {
                context.RenderOptions.CurrentInstance.Add(prim);
            }
            else
            {
                context.RenderOptions.Primitives.Add(prim);
                if (area != null)
                {
                    context.RenderOptions.Lights.Add(area);
                }
            }
        }