public void AddLight(Light_ light, Vector3 translation) { modified = true; lights.Add(light); light.position += translation; HierarchyLight lgt = new HierarchyLight(light.name, lights.Count - 1); hierarchy.objects.Add(lgt); hierarchyChange = true; Console.WriteLine("dadajemy swiatlo " + lgt.name); }
public Light_(Light_ copy) { this.name = copy.name; this.type = copy.type; this.enabled = copy.enabled; colorR = copy.colorR; colorG = copy.colorG; colorB = copy.colorB; this.power = copy.power; position = new Vector3(copy.position.X, copy.position.Y, copy.position.Z); direction = new Vector3(copy.direction.X, copy.direction.Y, copy.direction.Z); innerAngle = copy.innerAngle; outerAngle = copy.outerAngle; goniometric = copy.goniometric; }
public Light_(Light_ copy) { this.name = copy.name; this.type = copy.type; this.enabled = copy.enabled; colorR = copy.colorR; colorG = copy.colorG; colorB = copy.colorB; this.power = copy.power; position = new Vector3(copy.position.X, copy.position.Y, copy.position.Z); direction = new Vector3(copy.direction.X, copy.direction.Y, copy.direction.Z); innerAngle = copy.innerAngle; outerAngle = copy.outerAngle; goniometric = copy.goniometric; }
public static Bitmap Render(Light_ lgt) { light = lgt; Vector3D direction = new Vector3D(); Color color; for (int i = 0; i < xResolution; i++) { for (int j = 0; j < yResolution; j++) { direction = vectorU * (i / (float)(xResolution - 1)) + vectorV * (j / (float)(yResolution - 1)); direction += topLeft; direction -= observer; direction.Normalize(); color = CalculateColor(observer, direction, 0); image.SetPixel(i, j, color); } } return image; }
public void SetLight(Light_ lgt) { light = lgt; goniometry.Goniometry = light.goniometric; colorRed_slider.Value = light.colorR; colorGreen_slider.Value = light.colorG; colorBlue_slider.Value = light.colorB; flux_slider.Value = light.power; innerAngle_slider.Value = light.innerAngle; outerAngle_slider.Value = light.outerAngle; name_box.Text = light.name; lgt.position.X = 0; lgt.position.Y = 0; lgt.position.Z = 0; UpdateElements(); RenderLight(); }
// Koniec sekcji //////////////////////////////////////////////////////////////////////////////////// private void objectToScene_Drop(object sender, System.Windows.DragEventArgs e) { if (e.Data.GetDataPresent("Object")) { object data = e.Data.GetData("Object"); Console.WriteLine(data.GetType()); ViewportInfo coords = GetViewCoords(); if (data is Shape_) { Shape_ shape = (Shape_)data; undo.Save(currScene); currScene.AddObject(shape.Triangulate((float)triang_Slider.Value), shape.GetType().ToString()); // przekształcenie współrzędnych float x = (float)e.GetPosition(this).X - xOffset; float y = (float)e.GetPosition(this).Y - yOffset; float xtrans = 0, ytrans = 0, ztrans = 0; float factor = (renderer.OrthoWidth[0] / coords.sizeX[1]); // Lewy górny if (x >= coords.posX[0] && x < coords.posX[0] + coords.sizeX[0] && y >= coords.posY[0] && y < coords.posY[0] + coords.sizeY[0]) { } // Prawy górny panel - gora (x, z) else if (x >= coords.posX[1] && x < coords.posX[1] + coords.sizeX[1] && y >= coords.posY[1] && y < coords.posY[1] + coords.sizeY[1]) { xtrans = (x - (coords.posX[1] + coords.sizeX[1] / 2)) / coords.sizeX[1] * renderer.OrthoWidth[0]; ytrans = renderer.OrthoLookAt[1].Y; ztrans = (y - (coords.posY[1] + coords.sizeY[1] / 2)) / coords.sizeY[1] * (coords.sizeY[1] * renderer.OrthoWidth[0] / coords.sizeX[1]); } // Lewy dolny panel - przod (x, y) else if (x >= coords.posX[2] && x < coords.posX[2] + coords.sizeX[2] && y >= coords.posY[2] && y < coords.posY[2] + coords.sizeY[2]) { xtrans = (x - (coords.posX[2] + coords.sizeX[2] / 2)) / coords.sizeX[1] * renderer.OrthoWidth[1]; ztrans = renderer.OrthoLookAt[0].Z; ytrans = - (y - (coords.posY[2] + coords.sizeY[2] / 2)) / coords.sizeY[2] * (coords.sizeY[2] * renderer.OrthoWidth[1] / coords.sizeX[2]); } // Prawy dolny panel - bok (z, y) else if (x >= coords.posX[3] && x < coords.posX[3] + coords.sizeX[3] && y >= coords.posY[3] && y < coords.posY[3] + coords.sizeY[3]) { ztrans = - (x - (coords.posX[3] + coords.sizeX[3] / 2)) / coords.sizeX[3] * renderer.OrthoWidth[2]; xtrans = renderer.OrthoLookAt[1].X; ytrans = - (y - (coords.posY[3] + coords.sizeY[3] / 2)) / coords.sizeY[3] * (coords.sizeY[3] * renderer.OrthoWidth[2] / coords.sizeX[3]); } Transformations.Transformations.TranslateAddedObject(currScene, xtrans, ytrans, ztrans); Console.WriteLine(currScene.points.Count() + " " + currScene.triangles.Count()); } else if (data is PreparedElement) { PreparedElement element = (PreparedElement)data; Console.WriteLine("Dodanie do sceny"); } else if (data is Surface) { Surface surface = (Surface)data; undo.Save(currScene); bool zazn = true; bool zastap = false; for (int i = 0; i < currScene.materials.Count; i++) if (currScene.materials[i].name == surface.Material.Name) { zastap = true; currScene.materials[i] = new Material_(surface.Material); } if (!zastap) currScene.materials.Add(new Material_(surface.Material)); if (currScene.selTriangles.Count == 0) { zazn = false; ViewportInfo views = GetViewCoords(); int x = (int)e.GetPosition(this).X - xOffset; int y = (int)e.GetPosition(this).Y - yOffset; int rect = -1; for (int i = 0; i < 4; ++i) { if (views.posX[i] <= x && x < views.posX[i] + views.sizeX[i] && views.posY[i] <= y && y < views.posY[i] + views.sizeY[i]) { rect = i; } } if (rect >= 0) { ViewportType viewportType = rect == 0 ? ViewportType.Perspective : ViewportType.Orto; int orthoRect = rect == 0 ? rect : rect - 1; SelectingElems.SelectElems(currScene, viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]), new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]), renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect]); } } for (int i = 0; i < currScene.parts.Count; i++) { foreach (HierarchyMesh obj in currScene.selTriangles) if (currScene.parts[i].triangles.Contains((int)obj.triangles[0])) currScene.materialAssign[i] = surface.Material.Name; } if (!zazn) currScene.selTriangles.Clear(); Console.WriteLine("Przypisanie atrybutów powierzchniowych"); } else if (data is Material_) { Material_ material = new Material_((Material_)data); material.colorR = material.colorR / 255; material.colorG = material.colorG / 255; material.colorB = material.colorB / 255; undo.Save(currScene); bool zazn = true; bool zastap = false; for (int i = 0; i < currScene.materials.Count; i++) if (currScene.materials[i].name == material.Name) { zastap = true; currScene.materials[i] = new Material_(material); } if (!zastap) currScene.materials.Add(new Material_(material)); if (currScene.selTriangles.Count == 0) { zazn = false; ViewportInfo views = GetViewCoords(); int x = (int)e.GetPosition(this).X - xOffset; int y = (int)e.GetPosition(this).Y - yOffset; int rect = -1; for (int i = 0; i < 4; ++i) { if (views.posX[i] <= x && x < views.posX[i] + views.sizeX[i] && views.posY[i] <= y && y < views.posY[i] + views.sizeY[i]) { rect = i; } } if (rect >= 0) { ViewportType viewportType = rect == 0 ? ViewportType.Perspective : ViewportType.Orto; int orthoRect = rect == 0 ? rect : rect - 1; SelectingElems.SelectElems(currScene, viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]), new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]), renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect]); } } for (int i = 0; i < currScene.parts.Count; i++) { foreach (HierarchyMesh obj in currScene.selTriangles) if (currScene.parts[i].triangles.Contains((int)obj.triangles[0])) currScene.materialAssign[i] = material.Name; } if (!zazn) currScene.selTriangles.Clear(); Console.WriteLine("Przypisanie atrybutów powierzchniowych"); } else if (data is LightObj) { LightObj light = (LightObj)data; undo.Save(currScene); Light_ sceneLight = new Light_(light.Light); currScene.lights.Add(sceneLight); currScene.selLights.Add(sceneLight); Console.WriteLine("Dodanie światła"); } else if (data is Light_) { Light_ light = (Light_)data; undo.Save(currScene); Light_ sceneLight = new Light_(light); currScene.lights.Add(sceneLight); currScene.selLights.Add(sceneLight); } } e.Handled = true; trNumTBG1.Text = currScene.triangles.Count().ToString(); trNumTBG2.Text = currScene.triangles.Count().ToString(); trNumTBG3.Text = currScene.triangles.Count().ToString(); trNumTBG4.Text = currScene.triangles.Count().ToString(); RenderViews(); }
public void AddLight(Light_ light, Vector3 translation) { modified = true; lights.Add(light); light.position += translation; HierarchyLight lgt = new HierarchyLight(light.name, lights.Count - 1); hierarchy.objects.Add(lgt); hierarchyChange = true; Console.WriteLine("dadajemy swiatlo "+lgt.name); }
private void swiatloGaleriaTab_Drop(object sender, System.Windows.DragEventArgs e) { if (e.Data.GetDataPresent("Object") || e.Data.GetDataPresent("Light")) { object data; if (e.Data.GetData("Object") is Light_) { data = e.Data.GetData("Object"); } else { data = e.Data.GetData("Light"); } //Console.WriteLine(data.GetType()); if (data is Light_) { Light_ light = new Light_((Light_)data); Graphics.LightRaytracer.Render(light); bool replace = false; if (String.Compare(light.name, "Default", true) == 0) { Modeler.DialogBoxes.NameDialog newName = new NameDialog(); bool res = (bool)newName.Show("Podaj nową nazwę światła", ""); if (!res) return; light.name = newName.Result; } while (_lightGallery.GetNames().Contains(light.name, StringComparer.OrdinalIgnoreCase) && !replace) { Modeler.DialogBoxes.NameDialog dialog = new NameDialog(); dialog.Owner = this; bool result = (bool)dialog.Show(lightMessage, light.name); string name = dialog.Result; if (!result) return; if (light.name == name) replace = true; light.name = name; dialog.Close(); } if (replace) { int idx = _lightGallery.GetNameIndex(light.name); _lightGallery.RemoveAt(idx); LightObj lgtObj = _lightGallery.SaveLightToGallery(light); _lightGallery.Insert(idx, lgtObj); } else { LightObj lgtObj = _lightGallery.SaveLightToGallery(light); _lightGallery.Add(lgtObj); } } } }
// Koniec sekcji //////////////////////////////////////////////////////////////////////////////////// private void objectToScene_Drop(object sender, System.Windows.DragEventArgs e) { // Wciąganie obiektów do sceny if (tabWidok.SelectedIndex == 0) { if (e.Data.GetDataPresent("Object")) { object data = e.Data.GetData("Object"); //Console.WriteLine(data.GetType()); //ViewportInfo coords = GetViewCoords(tabWidok.SelectedIndex); Vector3 translation; if (data is Shape_) { Shape_ shape = (Shape_)data; undo.Save(currScene); // przekształcenie współrzędnych float x = (float)e.GetPosition(this).X - xOffset; float y = (float)e.GetPosition(this).Y - yOffset; translation = CalculateTranslation(x, y); currScene.AddObject(shape.Triangulate((float)triang_Slider.Value), shape.Name, translation); currScene.hierarchyChange = false; initializeTreeView(); //sceneChange = true; } else if (data is PreparedElement) { undo.Save(currScene); PreparedElement element = (PreparedElement)data; // przekształcenie współrzędnych float x = (float)e.GetPosition(this).X - xOffset; float y = (float)e.GetPosition(this).Y - yOffset; translation = CalculateTranslation(x, y); //for (int i = 0; i < element.Scene.cams.Count; i++) //{ // cameraPan.comboBox1.Items.Add("Kamera " + (currScene.cams.Count() + 1 + i)); //} currScene.AddPreparedElement(element, translation); currScene.hierarchyChange = false; initializeTreeView(); //sceneChange = true; } else if (data is Surface) { Surface surface = (Surface)data; undo.Save(currScene); bool zazn = true; if (currScene.selTriangles.Count == 0) { zazn = false; ViewportInfo views = GetViewCoords(tabWidok.SelectedIndex); int x = (int)e.GetPosition(this).X - xOffset; int y = (int)e.GetPosition(this).Y - yOffset; ViewportOrientation viewport = GetViewportType(x, y); if (viewport != ViewportOrientation.None) { ViewportType viewportType = viewport == ViewportOrientation.Perspective ? ViewportType.Perspective : ViewportType.Orto; int rect = (int)viewport; int orthoRect = rect == 3 ? 0 : rect; SelectingElems.SelectElems(currScene, renderer.GetCamsPoints(), renderer.GetLightsPoints(), viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]), new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]), renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect], false); } } if (String.Compare(surface.Material.Name, "default", true) == 0) { Modeler.DialogBoxes.NameDialog newName = new NameDialog(); bool res = (bool)newName.Show("Podaj nową nazwę materiału", ""); if (!res) return; surface.Material.name = newName.Result; } bool replace = false; while (currScene.ContainsMaterialName(surface.Material.Name) && !replace) { Modeler.DialogBoxes.NameDialog dialog = new NameDialog(); dialog.Owner = this; bool result = (bool)dialog.Show(materialSceneMessage, surface.Material.Name); string name = dialog.Result; if (!result) return; if (surface.Material.Name == name) replace = true; surface.Material.name = name; dialog.Close(); } currScene.AddMaterial(surface.Material); currScene.hierarchyChange = false; if (!zazn) currScene.ClearSelectedTriangles(); //Console.WriteLine("Przypisanie atrybutów powierzchniowych"); //sceneChange = true; } else if (data is Material_) { Material_ material = new Material_((Material_)data); material.colorR = material.colorR / 255; material.colorG = material.colorG / 255; material.colorB = material.colorB / 255; undo.Save(currScene); bool zazn = true; if (currScene.selTriangles.Count == 0) { zazn = false; ViewportInfo views = GetViewCoords(tabWidok.SelectedIndex); int x = (int)e.GetPosition(this).X - xOffset; int y = (int)e.GetPosition(this).Y - yOffset; ViewportOrientation viewport = GetViewportType(x, y); if (viewport != ViewportOrientation.None) { ViewportType viewportType = viewport == ViewportOrientation.Perspective ? ViewportType.Perspective : ViewportType.Orto; int rect = (int)viewport; int orthoRect = rect == 3 ? 0 : rect; SelectingElems.SelectElems(currScene, renderer.GetCamsPoints(), renderer.GetLightsPoints(), viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]), new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]), renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect], false); } } if (String.Compare(material.Name, "default", true) == 0) { Modeler.DialogBoxes.NameDialog newName = new NameDialog(); bool res = (bool)newName.Show("Podaj nową nazwę materiału", ""); if (!res) return; material.name = newName.Result; } bool replace = false; while (currScene.ContainsMaterialName(material.Name) && !replace) { Modeler.DialogBoxes.NameDialog dialog = new NameDialog(); dialog.Owner = this; bool result = (bool)dialog.Show(materialSceneMessage, material.Name); string name = dialog.Result; if (!result) return; if (material.Name == name) replace = true; material.name = name; dialog.Close(); } currScene.AddMaterial(material); if (!zazn) currScene.ClearSelectedTriangles(); //Console.WriteLine("Przypisanie atrybutów powierzchniowych"); //sceneChange = true; } else if (data is LightObj) { if (currScene.selLights.Count > 0) //objętnie ile ich jest zaznaczonych zmienia tylko 1 sprawdzająć nazwe { undo.Save(currScene); Light_ sceneLight = currScene.lights[currScene.selLights[0]]; Light_ dataLight = ((LightObj)data).Light; sceneLight.colorR = dataLight.colorR; sceneLight.colorG = dataLight.colorG; sceneLight.colorB = dataLight.colorB; sceneLight.enabled = dataLight.enabled; sceneLight.goniometric = dataLight.goniometric; sceneLight.innerAngle = dataLight.innerAngle; sceneLight.name = dataLight.name; sceneLight.outerAngle = dataLight.outerAngle; sceneLight.power = dataLight.power; sceneLight.type = dataLight.type; //sceneChange = true; } else { LightObj light = (LightObj)data; undo.Save(currScene); Light_ sceneLight = new Light_(light.Light); // przekształcenie współrzędnych float x = (float)e.GetPosition(this).X - xOffset; float y = (float)e.GetPosition(this).Y - yOffset; translation = CalculateTranslation(x, y); currScene.AddLight(sceneLight, translation); currScene.hierarchyChange = false; initializeTreeView(); //sceneChange = true; } } else if (data is Light_) { if (currScene.selLights.Count > 0) { undo.Save(currScene); Light_ sceneLight = currScene.lights[currScene.selLights[0]]; Light_ dataLight = (Light_)data; sceneLight.colorR = dataLight.colorR; sceneLight.colorG = dataLight.colorG; sceneLight.colorB = dataLight.colorB; sceneLight.enabled = dataLight.enabled; sceneLight.goniometric = dataLight.goniometric; sceneLight.innerAngle = dataLight.innerAngle; sceneLight.name = dataLight.name; sceneLight.outerAngle = dataLight.outerAngle; sceneLight.power = dataLight.power; sceneLight.type = dataLight.type; //currScene.hierarchyChange = true; currScene.hierarchyChange = false; initializeTreeView(); //sceneChange = true; } else { Light_ light = (Light_)data; undo.Save(currScene); Light_ sceneLight = new Light_(light); // przekształcenie współrzędnych float x = (float)e.GetPosition(this).X - xOffset; float y = (float)e.GetPosition(this).Y - yOffset; translation = CalculateTranslation(x, y); currScene.AddLight(sceneLight, translation); //TO DO sprawdzenie czy nazwa jest unikatowa //currScene.hierarchyChange = true; currScene.hierarchyChange = false; initializeTreeView(); //sceneChange = true; } } else if (data is Camera) { Camera cam = (Camera)data; undo.Save(currScene); float x = (float)e.GetPosition(this).X - xOffset; float y = (float)e.GetPosition(this).Y - yOffset; translation = CalculateTranslation(x, y); currScene.AddCamera(cam, translation); cameraPan.comboBox1.Items.Add("Kamera " + (currScene.cams.Count())); cameraPan.comboBox1.SelectedIndex = currScene.activeCamera; //sceneChange = true; } } } // Wciąganie obiektów do edytora powierzchni beziera. else if (tabWidok.SelectedIndex == 1) { if (e.Data.GetDataPresent("Object")) { object data = e.Data.GetData("Object"); if (data is BezierSurface) { bezierSurface = new BezierSurface((BezierSurface)data); bezierSurface.Triangulate((float)triang_Slider.Value); RenderBezier(); } } } e.Handled = true; trNumTBG1.Text = currScene.triangles.Count().ToString(); trNumTBG2.Text = currScene.triangles.Count().ToString(); trNumTBG3.Text = currScene.triangles.Count().ToString(); trNumTBG4.Text = currScene.triangles.Count().ToString(); Renderer.RecalculateData(currScene); RenderViews(); currScene.selectedHierObj = null; }
public LightObj(Light_ lgt, string imgUri) { Light = lgt; ImageUri = imgUri; }
public Scene SceneFromSelection(out Vector3D center) { Scene retScene = new Scene(); HashSet <uint> selectedTriangIdx = new HashSet <uint>(); HashSet <uint> selectedPointsIdx = new HashSet <uint>(); List <Triangle> newTriangles = new List <Triangle>(); List <Vector3D> newPoints = new List <Vector3D>(); List <uint> newTriangleIdx = new List <uint>(); List <int> newLightIdx = new List <int>(); uint idx = 0; for (int i = 0; i < triangles.Count; ++i) { newTriangleIdx.Add(0); } //List<HierarchyMesh> selectedMeshes = new List<HierarchyMesh>(); bool[] selectedPoints = new bool[points.Count]; bool[] selectedTriangs = new bool[triangles.Count]; for (int i = 0; i < selectedPoints.Length; i++) { selectedPoints[i] = false; } for (int i = 0; i < selectedTriangs.Length; i++) { selectedTriangs[i] = false; } foreach (HierarchyMesh mesh in selTriangles) //for (int i = 0; i < selTriangles.Count; i++) { //selectedMeshes.Add(Hierarchy.GetSelectedMesh(hierarchy.objects, (int)mesh.triangles[0])); for (int j = 0; j < mesh.triangles.Count; j++) { int oldIdx = (int)mesh.triangles[j]; newTriangleIdx[oldIdx] = idx++; selectedTriangIdx.Add(mesh.triangles[j]); int triang = (int)mesh.triangles[j]; selectedTriangs[mesh.triangles[j]] = true; newTriangles.Add(new Triangle(triangles[triang].p1, triangles[triang].p2, triangles[triang].p3)); selectedPointsIdx.Add(triangles[(int)mesh.triangles[j]].p1); selectedPointsIdx.Add(triangles[(int)mesh.triangles[j]].p2); selectedPointsIdx.Add(triangles[(int)mesh.triangles[j]].p3); selectedPoints[triangles[(int)mesh.triangles[j]].p1] = true; selectedPoints[triangles[(int)mesh.triangles[j]].p2] = true; selectedPoints[triangles[(int)mesh.triangles[j]].p3] = true; } } idx = 0; for (int i = 0; i < lights.Count; i++) { newLightIdx.Add(-1); } for (int i = 0; i < selLights.Count; i++) { newLightIdx[selLights[i]] = (int)idx++; } for (int i = 0; i < points.Count; i++) { if (selectedPoints[i]) { newPoints.Add(new Vector3D(points[i])); } } // Lista zawiera indeksy poczatka i konca usuwanych punktow (beda // one wystepowaly sekcjami) List <int> pointStartEnd = new List <int>(); bool flag = true; for (int i = 0; i < selectedPoints.Length; i++) { if (!selectedPoints[i] && flag) { pointStartEnd.Add(i); flag = false; } if (selectedPoints[i] && !flag) { pointStartEnd.Add(i - 1); flag = true; } } if (!flag) { pointStartEnd.Add(selectedPoints.Length - 1); } // Lista zawiera indeksy poczatka i konca usuwanych trojkatow List <int> triangStartEnd = new List <int>(); flag = true; for (int i = 0; i < selectedTriangs.Length; i++) { if (!selectedTriangs[i] && flag) { triangStartEnd.Add(i); flag = false; } if (selectedTriangs[i] && !flag) { triangStartEnd.Add(i - 1); flag = true; } } if (!flag) { triangStartEnd.Add(selectedTriangs.Length - 1); } int offset = 0; for (int i = 0; i < pointStartEnd.Count; i += 2) { int diffP = pointStartEnd[i + 1] - pointStartEnd[i] + 1; foreach (Triangle triangle in newTriangles) { if (triangle.p1 > pointStartEnd[i + 1] - offset) { triangle.p1 -= (uint)diffP; } if (triangle.p2 > pointStartEnd[i + 1] - offset) { triangle.p2 -= (uint)diffP; } if (triangle.p3 > pointStartEnd[i + 1] - offset) { triangle.p3 -= (uint)diffP; } } offset += diffP; } List <HierarchyObject> newHierarchy = new List <HierarchyObject>(); if (selectedHierObj != null) { HierarchyNode newNode = new HierarchyNode(selectedHierObj); newHierarchy.Add(newNode); RebuildHierarchy(newHierarchy, newTriangleIdx, newLightIdx); } else { foreach (HierarchyMesh mesh in selTriangles) { HierarchyMesh newMesh = (new HierarchyMesh(mesh.name)); for (int i = 0; i < mesh.triangles.Count; i++) { newMesh.triangles.Add(newTriangleIdx[(int)mesh.triangles[i]]); } newHierarchy.Add(newMesh); } } List <Part> newParts = new List <Part>(); List <String> newMaterialAssign = new List <string>(); for (int i = 0; i < parts.Count; i++) { Part newPart = (new Part(new List <int>())); bool used = false; for (int j = 0; j < parts[i].triangles.Count; j++) { newPart.triangles.Add((int)newTriangleIdx[parts[i].triangles[j]]); if ((int)newTriangleIdx[parts[i].triangles[j]] > 0) { used = true; } } if (used) { newParts.Add(newPart); newMaterialAssign.Add(materialAssign[i]); } } foreach (Material_ material in materials) { retScene.materials.Add(new Material_(material)); } center = new Data.Scene.Vector3D(0, 0, 0); int count = newPoints.Count + selCams.Count + selLights.Count; foreach (Data.Scene.Vector3D v in newPoints) { center.x = center.x + v.x / count; center.y = center.y + v.y / count; center.z = center.z + v.z / count; } //foreach (int c in selCams) //{ // Camera cam = cams[c]; // center.x = center.x + cam.position.X / count; // center.y = center.y + cam.position.Y / count; // center.z = center.z + cam.position.Z / count; //} foreach (int l in selLights) { Light_ light = lights[l]; center.x = center.x + light.position.X / count; center.y = center.y + light.position.Y / count; center.z = center.z + light.position.Z / count; } foreach (Data.Scene.Vector3D v in newPoints) { v.x -= center.x; v.y -= center.y; v.z -= center.z; } List <Light_> newwLights1 = new List <Light_>(); foreach (int lightIndex in selLights) { Light_ light = new Light_(lights[lightIndex]); newwLights1.Add(light); newwLights1[newwLights1.Count - 1].position -= center; int tmp = newwLights1.Count - 1; //dodawanie światel do hierarchii if (selectedHierObj == null) { HierarchyLight newLight = new HierarchyLight(light.name.ToString(), tmp); newHierarchy.Add(newLight); } //newLight.name = light.name; Console.WriteLine("dodawanie do hierarchiii"); } //List<Camera> newCams = new List<Camera>(); //foreach (int camIndex in selCams) //{ // newCams.Add(new Camera(cams[camIndex])); // newCams[newCams.Count - 1].position -= center; //} retScene.points = newPoints; retScene.triangles = newTriangles; retScene.hierarchy.objects = newHierarchy; retScene.parts = newParts; retScene.materialAssign = newMaterialAssign; retScene.lights = newwLights1; //retScene.cams = newCams; hierarchyChange = true; return(retScene); }
private void lightPreview_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("Object") || e.Data.GetDataPresent("Light")) { if (e.Data.GetData("Light") is Light_) { Light_ lightData = (Light_)e.Data.GetData("Light"); Light_ lightPrevious = (Light_)e.Data.GetData("LightPrevious"); e.Data.SetData("Object", e.Data.GetData("Light")); lightData.position = lightPrevious.position; lightData.direction = lightPrevious.direction; } object data = e.Data.GetData("Object"); Console.WriteLine(data.GetType()); if (data is Modeler.Data.Light.LightObj) { light = new Light_(((Modeler.Data.Light.LightObj)data).Light); //material.colorR = material.colorR * 255; //material.colorG = material.colorG * 255; //material.colorB = material.colorB * 255; SetLight(light); //SetSliders(); //name_box.Text = material.name; } else if (data is Light_) { light = new Light_(((Light_)data)); SetLight(light); //SetSliders(); //name_box.Text = material.name; } } }
private void swiatloGaleriaTab_Drop(object sender, System.Windows.DragEventArgs e) { if (e.Data.GetDataPresent("Object")) { object data = e.Data.GetData("Object"); Console.WriteLine(data.GetType()); if (data is Light_) { Light_ light = new Light_((Light_)data); if (light.type==Light_Type.Goniometric) _lightGallery.Add(new LightObj(light, "Ikony/Swiatla/lgt - goni.png")); if (light.type == Light_Type.Point) _lightGallery.Add(new LightObj(light, "Ikony/Swiatla/lgt - point.png")); if (light.type == Light_Type.Spot) _lightGallery.Add(new LightObj(light, "Ikony/Swiatla/lgt - spot.png")); } } }
public HierarchyLight(Light_ light) : base(light.name) { this.light = light; }
public void SetLight(Light_ lgt) { light = lgt; goniometry.SetGoniometry(light.goniometric); colorRed_slider.Value = light.colorR; colorGreen_slider.Value = light.colorG; colorBlue_slider.Value = light.colorB; flux_slider.Value = light.power; innerAngle_slider.Value = light.innerAngle; outerAngle_slider.Value = light.outerAngle; UpdateElements(); RenderLight(); }
public Scene SceneFromSelection(out Vector3D center) { Scene retScene = new Scene(); HashSet<uint> selectedTriangIdx = new HashSet<uint>(); HashSet<uint> selectedPointsIdx = new HashSet<uint>(); List<Triangle> newTriangles = new List<Triangle>(); List<Vector3D> newPoints = new List<Vector3D>(); List<uint> newTriangleIdx = new List<uint>(); List<int> newLightIdx = new List<int>(); uint idx = 0; for (int i = 0; i < triangles.Count; ++i) newTriangleIdx.Add(0); //List<HierarchyMesh> selectedMeshes = new List<HierarchyMesh>(); bool[] selectedPoints = new bool[points.Count]; bool[] selectedTriangs = new bool[triangles.Count]; for (int i = 0; i < selectedPoints.Length; i++) { selectedPoints[i] = false; } for (int i = 0; i < selectedTriangs.Length; i++) { selectedTriangs[i] = false; } foreach (HierarchyMesh mesh in selTriangles) //for (int i = 0; i < selTriangles.Count; i++) { //selectedMeshes.Add(Hierarchy.GetSelectedMesh(hierarchy.objects, (int)mesh.triangles[0])); for (int j = 0; j < mesh.triangles.Count; j++) { int oldIdx = (int)mesh.triangles[j]; newTriangleIdx[oldIdx] = idx++; selectedTriangIdx.Add(mesh.triangles[j]); int triang = (int)mesh.triangles[j]; selectedTriangs[mesh.triangles[j]] = true; newTriangles.Add(new Triangle(triangles[triang].p1, triangles[triang].p2, triangles[triang].p3)); selectedPointsIdx.Add(triangles[(int)mesh.triangles[j]].p1); selectedPointsIdx.Add(triangles[(int)mesh.triangles[j]].p2); selectedPointsIdx.Add(triangles[(int)mesh.triangles[j]].p3); selectedPoints[triangles[(int)mesh.triangles[j]].p1] = true; selectedPoints[triangles[(int)mesh.triangles[j]].p2] = true; selectedPoints[triangles[(int)mesh.triangles[j]].p3] = true; } } idx = 0; for (int i = 0; i < lights.Count; i++) { newLightIdx.Add(-1); } for (int i = 0; i < selLights.Count; i++) { newLightIdx[selLights[i]] = (int)idx++; } for (int i=0; i<points.Count; i++) { if (selectedPoints[i]) { newPoints.Add(new Vector3D(points[i])); } } // Lista zawiera indeksy poczatka i konca usuwanych punktow (beda // one wystepowaly sekcjami) List<int> pointStartEnd = new List<int>(); bool flag = true; for (int i = 0; i < selectedPoints.Length; i++) { if (!selectedPoints[i] && flag) { pointStartEnd.Add(i); flag = false; } if (selectedPoints[i] && !flag) { pointStartEnd.Add(i - 1); flag = true; } } if (!flag) pointStartEnd.Add(selectedPoints.Length - 1); // Lista zawiera indeksy poczatka i konca usuwanych trojkatow List<int> triangStartEnd = new List<int>(); flag = true; for (int i = 0; i < selectedTriangs.Length; i++) { if (!selectedTriangs[i] && flag) { triangStartEnd.Add(i); flag = false; } if (selectedTriangs[i] && !flag) { triangStartEnd.Add(i - 1); flag = true; } } if (!flag) triangStartEnd.Add(selectedTriangs.Length - 1); int offset = 0; for (int i = 0; i < pointStartEnd.Count; i += 2) { int diffP = pointStartEnd[i + 1] - pointStartEnd[i] + 1; foreach (Triangle triangle in newTriangles) { if (triangle.p1 > pointStartEnd[i + 1] - offset) triangle.p1 -= (uint)diffP; if (triangle.p2 > pointStartEnd[i + 1] - offset) triangle.p2 -= (uint)diffP; if (triangle.p3 > pointStartEnd[i + 1] - offset) triangle.p3 -= (uint)diffP; } offset += diffP; } List<HierarchyObject> newHierarchy = new List<HierarchyObject>(); if (selectedHierObj != null) { HierarchyNode newNode = new HierarchyNode(selectedHierObj); newHierarchy.Add(newNode); RebuildHierarchy(newHierarchy, newTriangleIdx, newLightIdx); } else { foreach (HierarchyMesh mesh in selTriangles) { HierarchyMesh newMesh = (new HierarchyMesh(mesh.name)); for (int i = 0; i < mesh.triangles.Count; i++) { newMesh.triangles.Add(newTriangleIdx[(int) mesh.triangles[i]]); } newHierarchy.Add(newMesh); } } List<Part> newParts = new List<Part>(); List<String> newMaterialAssign = new List<string>(); for (int i = 0; i < parts.Count; i++) { Part newPart = (new Part(new List<int>())); bool used = false; for (int j = 0; j < parts[i].triangles.Count; j++) { newPart.triangles.Add((int)newTriangleIdx[parts[i].triangles[j]]); if ((int)newTriangleIdx[parts[i].triangles[j]] > 0) used = true; } if (used) { newParts.Add(newPart); newMaterialAssign.Add(materialAssign[i]); } } foreach (Material_ material in materials) retScene.materials.Add(new Material_(material)); center = new Data.Scene.Vector3D(0, 0, 0); int count = newPoints.Count + selCams.Count + selLights.Count; foreach (Data.Scene.Vector3D v in newPoints) { center.x = center.x + v.x / count; center.y = center.y + v.y / count; center.z = center.z + v.z / count; } //foreach (int c in selCams) //{ // Camera cam = cams[c]; // center.x = center.x + cam.position.X / count; // center.y = center.y + cam.position.Y / count; // center.z = center.z + cam.position.Z / count; //} foreach (int l in selLights) { Light_ light = lights[l]; center.x = center.x + light.position.X / count; center.y = center.y + light.position.Y / count; center.z = center.z + light.position.Z / count; } foreach (Data.Scene.Vector3D v in newPoints) { v.x -= center.x; v.y -= center.y; v.z -= center.z; } List<Light_> newwLights1 = new List<Light_>(); foreach (int lightIndex in selLights) { Light_ light = new Light_(lights[lightIndex]); newwLights1.Add(light); newwLights1[newwLights1.Count - 1].position -= center; int tmp = newwLights1.Count - 1; //dodawanie światel do hierarchii if (selectedHierObj == null) { HierarchyLight newLight = new HierarchyLight(light.name.ToString(), tmp); newHierarchy.Add(newLight); } //newLight.name = light.name; Console.WriteLine( "dodawanie do hierarchiii"); } //List<Camera> newCams = new List<Camera>(); //foreach (int camIndex in selCams) //{ // newCams.Add(new Camera(cams[camIndex])); // newCams[newCams.Count - 1].position -= center; //} retScene.points = newPoints; retScene.triangles = newTriangles; retScene.hierarchy.objects = newHierarchy; retScene.parts = newParts; retScene.materialAssign = newMaterialAssign; retScene.lights = newwLights1; //retScene.cams = newCams; hierarchyChange = true; return retScene; }