65.9K
CodeProject 正在变化。 阅读更多。
Home

ConnectCode 软件盒子封面制作器

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.64/5 (6投票s)

2009 年 3 月 26 日

BSD

2分钟阅读

viewsIcon

37438

downloadIcon

622

一个开源的 3D 软件盒子封面创建器

Click to enlarge image

引言

什么是盒装图?

盒装图是软件盒子的三维图像。盒装图可以帮助您的软件更好地销售。它们展现出专业的形象,并给您的客户留下高质量产品的印象。盒装图是一个很棒的营销工具。它鼓励访问您网站的访客更详细地检查您的产品。在您的网站上拥有一个盒装图,可以让您在竞争对手中脱颖而出。原因很简单。包装更好的软件会比同类产品更引人注目。

ConnectCode 软件盒子封面制作器

ConnectCode 软件盒装图制作器能够从现有的徽标和宣传材料创建逼真的三维软件盒子图像。用户只需提供两到三个图像,调整盒子方向并将其结果保存为图像文件。

支持的功能

  • 基于滑块的用户界面,易于使用
  • 软件盒子的旋转
  • 调整相机距离、相机高度以及相机相对于软件盒子的偏移
  • 正面、顶部和侧面的纹理
  • 支持阴影
  • 盒子尺寸

Using the Code

该项目使用 .NET 3.0 编写,并利用了 WPF 3D 的优势。软件的结构非常简单。场景由一个相机、一个具有六个面的矩形盒子和几个点光源组成。矩形软件盒子的每个面都用用户指定的**正面**、**侧面**和**顶部**图像进行绘制。矩形盒子的**底部**面被放大(按 4 的比例缩放),并用作绘制阴影的地面平面。

矩形盒子的五个可见面(不包括底部面)被分组到一个名为 softwareBox 的单个对象中。这个 softwareBox 附带了缩放和旋转 Transform,以便可以调整盒子尺寸和盒子旋转。

以下顺序调用四个方法 ResetScene()CreateGeometries()PrepareMaterials()CreateScene() 来创建实际图像。

private void NewProject()
{
    ResetScene();
    CreateGeometries();
    PrepareMaterials();
    CreateScene();
}
public partial class Window1 : System.Windows.Window
{
        Viewport3D mainViewport = null;
        ModelVisual3D mainMV = null;

        Transform3DGroup boxTr = null;
        Transform3DGroup bottomTr = null;
        Model3DGroup scene = null;
        Model3DGroup softwareBox = null;
        PerspectiveCamera sceneCamera = null;
        PointLight ptLight1 = null;
        PointLight ptLight2 = null;
        PointLight ptLight3 = null;
        PointLight ptLight4 = null;

        GeometryModel3D SecondSideFace = null;
        GeometryModel3D SideFace = null;
        GeometryModel3D BottomFace = null;
        GeometryModel3D FrontFace = null;
        GeometryModel3D TopFace = null;
        GeometryModel3D SecondFrontFace = null;

        public ImageSource imgFrontSrc = null;
        public ImageSource imgSideSrc = null;
        public ImageSource imgTopSrc = null;
        public ImageSource imgBottomSrc = null;
        ImageBrush imgFrontBrush = null;
        ImageBrush imgSideBrush = null;
        ImageBrush imgTopBrush = null;
        ImageBrush imgBottomBrush = null;

        String startfolder = "";
        Window3 PropDlg = null;

        //Main Parameters
        public Double angleOfRotation;
        public Double viewDistance;
        public Double viewHorizontalShift;
        public Double viewHeight;

        public Double scaleX;
        public Double scaleY;
        public Double scaleZ;

        public String imgFront;
        public String imgSide;
        public String imgTop;
        public String imgBottom;

        public Double ptLight1PosX;
        public Double ptLight1PosY;
        public Double ptLight1PosZ;

        public Double ptLight2PosX;
        public Double ptLight2PosY;
        public Double ptLight2PosZ;

        public Double ptLight3PosX;
        public Double ptLight3PosY;
        public Double ptLight3PosZ;

        public Double ptLight4PosX;
        public Double ptLight4PosY;
        public Double ptLight4PosZ;

        public Double ptLight1Att;
        public Double ptLight2Att;
        public Double ptLight3Att;
        public Double ptLight4Att;

        public Boolean includeShadows;

        public int ImgWidth = 400;
        public int ImgHeight = 400;

        public void ResetScene()
        {
            angleOfRotation = 19;
            viewDistance = 6;
            viewHorizontalShift = 1;
            viewHeight = 0.2;

            scaleX = 0.5;
            scaleY = 1.5;
            scaleZ = 1.2;

            imgFront = "";
            imgSide = "";
            imgTop = "";
            imgBottom = "";

            ptLight1PosX = 3;
            ptLight1PosY = 0.7;
            ptLight1PosZ = -1;
            ptLight1Att = 0.02;

            ptLight2PosX = 3;
            ptLight2PosY = 0.7;
            ptLight2PosZ = 3;
            ptLight2Att = 0.01;

            ptLight3PosX = 0;
            ptLight3PosY = 7;
            ptLight3PosZ = 0;
            ptLight3Att = 0.02;

            ptLight4PosX = 0;
            ptLight4PosY = 2;
            ptLight4PosZ = 0;
            ptLight4Att = 0.000002;

            includeShadows = true;
        }

        private void CreateGeometries()
        {
            SecondSideFace = new GeometryModel3D();
            SideFace = new GeometryModel3D();
            BottomFace = new GeometryModel3D();
            FrontFace = new GeometryModel3D();
            TopFace = new GeometryModel3D();
            SecondFrontFace = new GeometryModel3D();

            SideFace.Geometry = 
		(MeshGeometry3D)Application.Current.Resources["SideFace"];
            SecondFrontFace.Geometry = 
		(MeshGeometry3D)Application.Current.Resources["SecondFrontFace"];
            SecondSideFace.Geometry = 
		(MeshGeometry3D)Application.Current.Resources["SecondSideFace"];
            BottomFace.Geometry = 
		(MeshGeometry3D)Application.Current.Resources["BottomFace"];
            FrontFace.Geometry = 
		(MeshGeometry3D)Application.Current.Resources["FrontFace"];
            TopFace.Geometry = (MeshGeometry3D)Application.Current.Resources["TopFace"];

            softwareBox = new Model3DGroup();
            softwareBox.Children.Add(SecondSideFace);
            softwareBox.Children.Add(SideFace);
            //softwareBox.Children.Add(BottomFace);
            softwareBox.Children.Add(FrontFace);
            softwareBox.Children.Add(TopFace);
            softwareBox.Children.Add(SecondFrontFace);
        }

        public void PrepareMaterials()
        {
            UpdateImageSource();

            imgFrontBrush = new ImageBrush();
            imgSideBrush = new ImageBrush();
            imgTopBrush = new ImageBrush();
            imgBottomBrush = new ImageBrush();

            imgFrontBrush.ImageSource = imgFrontSrc;
            imgSideBrush.ImageSource = imgSideSrc;
            imgTopBrush.ImageSource = imgTopSrc;
            imgBottomBrush.ImageSource = imgBottomSrc;

            DiffuseMaterial FrontFaceMaterial = 
			new DiffuseMaterial((Brush)imgFrontBrush); //front
            DiffuseMaterial SecondFrontFaceMaterial = 
			new DiffuseMaterial((Brush)imgFrontBrush); //front2
            DiffuseMaterial TopFaceMaterial = 
			new DiffuseMaterial((Brush)imgTopBrush); //top
            DiffuseMaterial BottomFaceMaterial = 
			new DiffuseMaterial((Brush)imgBottomBrush); //bottom
            DiffuseMaterial SecondSideFaceMaterial = 
			new DiffuseMaterial((Brush)imgSideBrush); //side2
            DiffuseMaterial SideFaceMaterial = 
			new DiffuseMaterial((Brush)imgSideBrush); //side
            //SpecularMaterial BottomFaceMaterial = 
			new SpecularMaterial((Brush)imgBottomBrush, 0.3);
            //EmissiveMaterial BottomFaceEmmisiveMaterial = 
			new EmissiveMaterial((Brush)imgBottomBrush); //bottom

            FrontFace.Material = FrontFaceMaterial;
            SecondFrontFace.Material = SecondFrontFaceMaterial;
            SideFace.Material = SideFaceMaterial;
            SecondSideFace.Material = SecondSideFaceMaterial;
            TopFace.Material = TopFaceMaterial;
            BottomFace.Material = BottomFaceMaterial;
            //BottomFace.Material = BottomFaceEmmisiveMaterial;
        }

        public void UpdateImageSource()
        {
            //Get Textures
            if (imgFront == "")
                imgFront = startfolder + "\\front.jpg";

            if (imgSide == "")
                imgSide = startfolder + "\\side.jpg";

            if (imgTop == "")
                imgTop = startfolder + "\\top.jpg";

            if (imgBottom == "")
                imgBottom = startfolder + "\\shadow.jpg";

            imgFrontSrc = RetreiveImageSource(imgFront);
            imgSideSrc = RetreiveImageSource(imgSide);
            imgTopSrc = RetreiveImageSource(imgTop);
            imgBottomSrc = RetreiveImageSource(imgBottom);
        }

        private void CreateScene()
        {
            mainViewport = new Viewport3D();

            RotateTransform3D rTr = new RotateTransform3D
		(new AxisAngleRotation3D(new Vector3D(0, 1, 0), angleOfRotation));
            ScaleTransform3D sTr = new ScaleTransform3D(scaleX, scaleY, scaleZ);
            ScaleTransform3D bsTr = new ScaleTransform3D(4, scaleY, 4);

            sceneCamera = new PerspectiveCamera();
            sceneCamera.FieldOfView = 45;
            sceneCamera.Position = 
		new Point3D(viewDistance, viewHeight, viewHorizontalShift);
            sceneCamera.UpDirection = new Vector3D(0, 1, 0);
            sceneCamera.LookDirection = 
		new Vector3D(-viewDistance, -viewHeight, -viewHorizontalShift);
            mainViewport.Camera = sceneCamera;

            boxTr = new Transform3DGroup();
            bottomTr = new Transform3DGroup();
            bottomTr.Children.Add(bsTr);
            bottomTr.Children.Add(rTr);

            boxTr.Children.Add(sTr);
            boxTr.Children.Add(rTr);

            softwareBox.Transform = boxTr;
            BottomFace.Transform = bottomTr;

            ptLight1 = new PointLight();
            ptLight2 = new PointLight();
            ptLight3 = new PointLight();
            ptLight4 = new PointLight();
            ptLight1.Position = 
		new Point3D(viewDistance-3, viewHeight+0.5, viewHorizontalShift-2);
            ptLight2.Position = 
		new Point3D(viewDistance-3, viewHeight+0.5, viewHorizontalShift+2);
            ptLight1.Position = new Point3D(ptLight1PosX, ptLight1PosY, ptLight1PosZ);
            ptLight2.Position = new Point3D(ptLight2PosX, ptLight2PosY, ptLight2PosZ);
            ptLight3.Position = new Point3D(ptLight3PosX, ptLight3PosY, ptLight3PosZ);
            ptLight4.Position = new Point3D(ptLight4PosX, ptLight4PosY, ptLight4PosZ);
            ptLight1.Color = Colors.White;
            ptLight2.Color = Colors.White;
            ptLight3.Color = Colors.White;
            ptLight4.Color = Colors.White;
            ptLight1.QuadraticAttenuation = ptLight1Att;
            ptLight2.QuadraticAttenuation = ptLight2Att;
            ptLight3.QuadraticAttenuation = ptLight3Att;
            ptLight4.QuadraticAttenuation = ptLight4Att;

            scene = new Model3DGroup();
            scene.Children.Add(softwareBox);
            scene.Children.Add(ptLight1);
            scene.Children.Add(ptLight2);
            scene.Children.Add(ptLight3);
            scene.Children.Add(ptLight4);

            if (includeShadows)
            {
                scene.Children.Add(BottomFace);
            }

            mainMV = new ModelVisual3D();
            mainMV.Content = scene;
            mainViewport.Children.Add(mainMV);

            workPanel.Children.Add(mainViewport);
        }
}

这个工具为任何对编写或扩展盒装图制作软件感兴趣的人提供了一个机会,可以使用更高级的算法创建他们自己的自定义盒装图软件。例如,用户可以编辑自己的阴影图像以生成更好看的阴影。或者,他们可以使用其他 Material,例如 EmmisiveMaterialSpecularMaterial,使盒子更逼真。

原始网站

有关 ConnectCode 软件盒装图制作器的更新和更多信息,请访问该项目的原始网站:Box Shot

历史

  • 2009 年 3 月 26 日:初始版本
© . All rights reserved.