private List <Sprite> GetParts(RobotParts robotPartType) { if (robotPartType == RobotParts.Antenna) { return(robotAntennas); } else if (robotPartType == RobotParts.Head) { return(robotHeads); } else if (robotPartType == RobotParts.Eyes) { return(robotEyes); } else if (robotPartType == RobotParts.Body) { return(robotBodies); } else if (robotPartType == RobotParts.ArmRight) { return(robotRightArms); } else if (robotPartType == RobotParts.ArmLeft) { return(robotLeftArms); } else if (robotPartType == RobotParts.Legs) { return(robotLegs); } else { return(robotBaseElements); } }
private void CreateRobotParts(RobotParts robotPartType) { //Clear the child elements before adding the new ones if (content.transform.childCount > 0) { for (int i = 0; i < content.transform.childCount; i++) { Destroy(content.transform.GetChild(i).gameObject); } } //Get the correct parts and display them List <Sprite> parts = GetParts(robotPartType); List <Button> buttons = new List <Button>(); float offset = 0.0f; for (int i = 0; i < parts.Count; i++) { GameObject uiSelectorRobotPart = Instantiate(robotPartPrefab); uiSelectorRobotPart.GetComponent <Image>().sprite = parts[i]; uiSelectorRobotPart.GetComponent <Button>().onClick.AddListener(delegate { SetBodyPart(uiSelectorRobotPart); }); uiSelectorRobotPart.transform.SetParent(content.transform); uiSelectorRobotPart.GetComponent <RectTransform>().anchoredPosition = Vector2.zero; uiSelectorRobotPart.GetComponent <RectTransform>().anchoredPosition += new Vector2(offset, 0.0f); offset += uiSelectorRobotPart.GetComponent <RectTransform>().rect.width; buttons.Add(uiSelectorRobotPart.GetComponent <Button>()); } scrollSnapper.SetButtons(buttons); }
public void DeliverRobotParts(FactoryRoom deliveryBay) { foreach (var robotPart in RobotParts) { deliveryBay.AddRobotPart(robotPart); } RobotParts.Clear(); }
private void AddRobotTransformations(RobotParts robotPart, Dictionary <string, Model3D> namedObjects) { try { Model3DGroup model3DGroup; if (robotPart == RobotParts.Main) { model3DGroup = namedObjects["Helper_Base"] as Model3DGroup; _baseRotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, 0, 1), BaseRotationSlider.Value); InsertTransformation(model3DGroup, new RotateTransform3D(_baseRotation)); model3DGroup = namedObjects["Helper_Arm1"] as Model3DGroup; _arm1Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(1, 0, 0), Arm1RotationSlider.Value); InsertTransformation(model3DGroup, new RotateTransform3D(_arm1Rotation)); model3DGroup = namedObjects["Helper_Arm2"] as Model3DGroup; _arm2Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(1, 0, 0), Arm2RotationSlider.Value); InsertTransformation(model3DGroup, new RotateTransform3D(_arm2Rotation)); model3DGroup = namedObjects["Helper_Arm3"] as Model3DGroup; _arm3Rotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(1, 0, 0), Arm3RotationSlider.Value); InsertTransformation(model3DGroup, new RotateTransform3D(_arm3Rotation)); // The robot tools are added to the "Helper_Extras" Model3DGroup. model3DGroup = namedObjects["Helper_Extras"] as Model3DGroup; // The original 3D model was created with coordinate system where Z axis is us (instead of Y up). // When the model was exported to fbx, the exported added a transformation to convert the model to Y up coordinate system. // If we now load another fbx file (robot tool) and add it to the last robot arm part, // the tool will have the same coordinate system change transformation, but because we would add that to // already transformed coordinate system, this would not work well. // Therefore we need to add a transformation that will allow negate the coordinate system change transformation in the added file: var matrixTransform3D = new MatrixTransform3D(new Matrix3D(1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1)); var transform3DGroup = new Transform3DGroup(); transform3DGroup.Children.Add(matrixTransform3D); _toolRotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, 0, 1), ToolRotationSlider.Value); transform3DGroup.Children.Add(new RotateTransform3D(_toolRotation)); InsertTransformation(model3DGroup, transform3DGroup); } else if (robotPart == RobotParts.Claw) { model3DGroup = namedObjects["Helper_Claw_Left"] as Model3DGroup; _clawLeftRotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, 1, 0), 0); InsertTransformation(model3DGroup, new RotateTransform3D(_clawLeftRotation)); model3DGroup = namedObjects["Helper_Claw_Right"] as Model3DGroup; _clawRightRotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(0, -1, 0), 0); InsertTransformation(model3DGroup, new RotateTransform3D(_clawRightRotation)); } else if (robotPart == RobotParts.Saw) { model3DGroup = namedObjects["Helper_SawBlade"] as Model3DGroup; _sawRotation = new AxisAngleRotation3D(new System.Windows.Media.Media3D.Vector3D(1, 0, 0), 0); InsertTransformation(model3DGroup, new RotateTransform3D(_sawRotation)); } else if (robotPart == RobotParts.Panel) { _shownPanelGeometryModel3D = namedObjects["Robot_Panel_Screen"] as GeometryModel3D; if (_shownPanelGeometryModel3D != null) { _shownPanelGeometryModel3D.Material = new DiffuseMaterial(Brushes.Black); } } } catch (Exception ex) { MessageBox.Show("Error setting robot transformations:\r\n" + ex.Message); } }
private void LoadRobotPart(RobotParts robotPart) { if (robotPart == RobotParts.None) { return; } string partName = robotPart.ToString(); string fileName = _rootFolder + string.Format(_robotModelFileName, partName); string texturesFolder = _rootFolder + string.Format(_texturesSubfolder, partName); Mouse.OverrideCursor = Cursors.Wait; try { if (robotPart == RobotParts.Main) { ModelPlaceholder.Content = null; ModelPlaceholder.Children.Clear(); InfoTextBlock.Text = ""; } Dictionary <string, Model3D> namedObjects; var readModel3D = LoadModel3D(fileName, texturesFolder, out namedObjects); if (readModel3D == null) { return; } // Add RotateTransform3D objects to robot parts AddRobotTransformations(robotPart, namedObjects); if (robotPart == RobotParts.Main) { // Show the model ModelPlaceholder.Content = readModel3D; // Setup camera Camera1.TargetPosition = readModel3D.Bounds.GetCenterPosition(); Camera1.Distance = 1.0 * readModel3D.Bounds.GetDiagonalLength(); // Manually call Refresh to update the scene (create DirectX resources) while we are still showing Wait cursor MainDXViewportView.Refresh(); _namedObjects = namedObjects; } else { Model3D toolConnectorModel3D; if (_namedObjects == null || !_namedObjects.TryGetValue("Helper_Extras", out toolConnectorModel3D)) { return; } var toolConnectorModel3DGroup = (Model3DGroup)toolConnectorModel3D; toolConnectorModel3DGroup.Children.Clear(); Ab3d.Utilities.ModelUtils.PositionModel3D(readModel3D, new Point3D(0, 0, 0), PositionTypes.Bottom); toolConnectorModel3DGroup.Children.Add(readModel3D); //var geometryModel3D = Ab3d.Models.Line3DFactory.CreateWireCross3D(new Point3D(0, 0, 0), 1000, 2, Colors.Orange, MainViewport); //toolConnectorModel3DGroup.Children.Add(geometryModel3D); } } catch (Exception ex) { MessageBox.Show(string.Format("Error loading robot part {0}:\r\n{1}", robotPart, ex.Message)); } finally { Mouse.OverrideCursor = null; } }
// Position parts based on the part object given as well as the scale, offset, and PartType public void GetPart(Part part, GameObject partObject, Vector3 scale, Vector3 offset, RobotParts piece) { int pieceNum = (int)piece; // get int value from given enum var go = Instantiate(partObject); // Instantiates arm gameobject as assigned prefab go.transform.SetParent(transform); // Set part as child to player gameobject go.transform.localScale = scale; // Set scale of this part go.transform.localPosition = offset; // Set Part position part.partPos = go.transform.localPosition; // Set part position to equal it's positition in relation to the parent Destroy(RobotPartObjectList[pieceNum]); // Destroy GameObject representation of given part RobotPartObjectList[pieceNum] = go; // Places game object in list and in the right order }
public void DeliverRobotParts(DeliveryBay deliveryBay) { deliveryBay.RobotParts = new List <RobotPart>(RobotParts); RobotParts.Clear(); }